Skip to content

Commit

Permalink
add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Oct 26, 2024
1 parent 2abac25 commit 2bcfb7c
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 102 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/firefart/stunner

go 1.22
go 1.23

require (
github.com/firefart/gosocks v0.4.2
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers_stun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestPadding(t *testing.T) {
t.Parallel()

var tests = []struct {
tests := []struct {
testName string
inputLen int
expectedLen int
Expand Down
4 changes: 2 additions & 2 deletions internal/helpers_turn.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func ParseMappedAdress(input []byte) (*netip.Addr, uint16, error) {
return nil, 0, fmt.Errorf("invalid buffer length %d, need to be > 4", len(input))
}
family := input[0:2] // 0x0001 = ipv4, 0x0002 = ipv6
if !bytes.Equal(family, []byte{00, 01}) && !bytes.Equal(family, []byte{00, 02}) {
if !bytes.Equal(family, []byte{0o0, 0o1}) && !bytes.Equal(family, []byte{0o0, 0o2}) {
return nil, 0, fmt.Errorf("invalid family %02x", family)
}
portRaw := input[2:4]
Expand All @@ -96,7 +96,7 @@ func ConvertXORAddr(input []byte, transactionID string) (string, uint16, error)
return "", 0, fmt.Errorf("invalid buffer length %d, need to be > 4", len(input))
}
family := input[0:2] // 0x0001 = ipv4, 0x0002 = ipv6
if !bytes.Equal(family, []byte{00, 01}) && !bytes.Equal(family, []byte{00, 02}) {
if !bytes.Equal(family, []byte{0o0, 0o1}) && !bytes.Equal(family, []byte{0o0, 0o2}) {
return "", 0, fmt.Errorf("invalid family %02x", family)
}
portRaw := input[2:4]
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers_turn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestXorAddr(t *testing.T) {
func TestConvertXORAddr(t *testing.T) {
t.Parallel()

var tests = []struct {
tests := []struct {
input string
transactionID string
expectedHost string
Expand Down
4 changes: 2 additions & 2 deletions internal/parsers_stun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestFromBytes(t *testing.T) {
t.Parallel()

var tests = []struct {
tests := []struct {
testName string
input string
}{
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestFromBytes(t *testing.T) {
func TestFromBytesFail(t *testing.T) {
t.Parallel()

var tests = []struct {
tests := []struct {
testName string
input string
}{
Expand Down
123 changes: 64 additions & 59 deletions internal/requests_turn.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ func AllocateRequestAuth(username, password, nonce, realm string, targetProtocol
Method: MsgTypeMethodAllocate,
}

s.Attributes = []Attribute{{
Type: AttrRequestedTransport,
Value: transport,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
s.Attributes = []Attribute{
{
Type: AttrRequestedTransport,
Value: transport,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
}

if allocateProtcol != AllocateProtocolIgnore {
Expand Down Expand Up @@ -88,13 +89,14 @@ func SendRequest(target netip.Addr, port uint16) (*Stun, error) {
Method: MsgTypeMethodSend,
}

s.Attributes = []Attribute{{
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrData,
Value: []byte("pwned by firefart\n"),
},
s.Attributes = []Attribute{
{
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrData,
Value: []byte("pwned by firefart\n"),
},
}

return s, nil
Expand All @@ -115,19 +117,20 @@ func CreatePermissionRequest(username, password, nonce, realm string, target net
Method: MsgTypeMethodCreatePermission,
}

s.Attributes = []Attribute{{
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
s.Attributes = []Attribute{
{
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
}

return s, nil
Expand All @@ -152,22 +155,23 @@ func ChannelBindRequest(username, password, nonce, realm string, target netip.Ad
Method: MsgTypeMethodChannelbind,
}

s.Attributes = []Attribute{{
Type: AttrChannelNumber,
Value: append(channelNumber, []byte{0x00, 0x00}...),
}, {
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
s.Attributes = []Attribute{
{
Type: AttrChannelNumber,
Value: append(channelNumber, []byte{0x00, 0x00}...),
}, {
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
}

return s, nil
Expand All @@ -183,16 +187,17 @@ func RefreshRequest(username, password, nonce, realm string) *Stun {
Method: MsgTypeMethodRefresh,
}

s.Attributes = []Attribute{{
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
s.Attributes = []Attribute{
{
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
}

return s
Expand Down
63 changes: 33 additions & 30 deletions internal/requests_turntcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func ConnectRequest(target netip.Addr, port uint16) (*Stun, error) {
Method: MsgTypeMethodConnect,
}

s.Attributes = []Attribute{{
Type: AttrXorPeerAddress,
Value: targetXOR,
},
s.Attributes = []Attribute{
{
Type: AttrXorPeerAddress,
Value: targetXOR,
},
}

return s, nil
Expand All @@ -40,19 +41,20 @@ func ConnectRequestAuth(username, password, nonce, realm string, target netip.Ad
Method: MsgTypeMethodConnect,
}

s.Attributes = []Attribute{{
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
s.Attributes = []Attribute{
{
Type: AttrXorPeerAddress,
Value: targetXOR,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
}

return s, nil
Expand All @@ -68,19 +70,20 @@ func ConnectionBindRequest(connectionID []byte, username, password, nonce, realm
Method: MsgTypeMethodConnectionBind,
}

s.Attributes = []Attribute{{
Type: AttrConnectionID,
Value: connectionID,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
s.Attributes = []Attribute{
{
Type: AttrConnectionID,
Value: connectionID,
}, {
Type: AttrUsername,
Value: []byte(username),
}, {
Type: AttrRealm,
Value: []byte(realm),
}, {
Type: AttrNonce,
Value: []byte(nonce),
},
}

return s
Expand Down
12 changes: 6 additions & 6 deletions internal/types_stun.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"github.com/firefart/stunner/internal/helper"
)

const headerSize = 20
const messageIntegritySize = 20
const (
headerSize = 20
messageIntegritySize = 20
)

// nolint:deadcode,varcheck,unused
const fingerPrintSize = 4

var (
// MagicCookie is the fixed value according to the rfc
MagicCookie = []byte{'\x21', '\x12', '\xa4', '\x42'}
)
// MagicCookie is the fixed value according to the rfc
var MagicCookie = []byte{'\x21', '\x12', '\xa4', '\x42'}

// Stun is the main object
type Stun struct {
Expand Down
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"net"
"net/netip"
"os"
"runtime/debug"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -397,6 +398,20 @@ func main() {
})
},
},
{
Name: "version",
Usage: "prints the current version and build infos",
Description: "prints the current version and build infos",
Action: func(ctx *cli.Context) error {
info, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Errorf("could not get buildinfo")
}
fmt.Printf("Build info:\n")
fmt.Printf("%s", info)
return nil
},
},
},
}

Expand Down

0 comments on commit 2bcfb7c

Please sign in to comment.