Skip to content

Commit

Permalink
Merge pull request #45 from enowars/gnb-hidden
Browse files Browse the repository at this point in the history
Move gnb to hidden folder
  • Loading branch information
theodorsm committed Jul 14, 2023
2 parents f148c29 + ee904b9 commit 3133d59
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 22 deletions.
Binary file added service/gnb
Binary file not shown.
5 changes: 0 additions & 5 deletions service/setup.sh

This file was deleted.

8 changes: 1 addition & 7 deletions service/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@ go 1.20

require (
github.com/gofrs/uuid v4.4.0+incompatible
github.com/stretchr/testify v1.8.2
golang.org/x/crypto v0.9.0
golang.org/x/net v0.10.0
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.30.0
)

require (
github.com/stretchr/testify v1.8.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/zap v1.24.0
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 3 additions & 9 deletions service/src/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -9,12 +9,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -27,6 +22,7 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
Expand All @@ -49,8 +45,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions service_hidden/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use https://gitignore.io/ to create a suitable .gitignore file for your project.
data/
./gnb
4 changes: 4 additions & 0 deletions service_hidden/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cd src
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../../service/gnb cmd/gnb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,31 @@ func handleUeConnection(ueConn net.Conn) {
return
}

initUeMsg := ngap.InitUEMessageMsg{NasPdu: gmm, RanUeNgapId: 1}
var reg nas.NASRegRequestMsg
err = parser.DecodeMsg(gmm.Message, &reg)
if err != nil {
fmt.Printf("Error decoding: %#v\n", err)
return
}

//fmt.Printf("FROM UE: (NASRegRequest)\n %s\n", reg)

newreg := nas.NASRegRequestMsg{SecHeader: reg.SecHeader, MobileId: reg.MobileId}
newreg.SecCap.EaCap = reg.SecCap.EaCap
newreg.SecCap.IaCap = reg.SecCap.IaCap

msg, err := parser.EncodeMsg(&newreg)
if err != nil {
fmt.Printf("Error encoding NASRegRequest: %#v\n", err)
return
}

newgmm := nas.GmmHeader{}
newgmm.MessageType = gmm.MessageType
newgmm.Mac = gmm.Mac
newgmm.Message = msg

initUeMsg := ngap.InitUEMessageMsg{NasPdu: newgmm, RanUeNgapId: 1}
buf, _ := parser.EncodeMsg(&initUeMsg)
fmt.Println("=============================")
fmt.Printf("TO CORE: (InitUEMessage + NASRegRequest)\n %s\n", buf)
Expand Down
5 changes: 5 additions & 0 deletions service_hidden/src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module phreaking

go 1.20

require github.com/gofrs/uuid v4.4.0+incompatible
2 changes: 2 additions & 0 deletions service_hidden/src/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
69 changes: 69 additions & 0 deletions service_hidden/src/internal/io/io.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io

import (
"errors"
"io"
"net"
"phreaking/pkg/nas"
"phreaking/pkg/ngap"
"phreaking/pkg/parser"
)

var EOF error = io.EOF

func Send(conn net.Conn, msg []byte) (err error) {
msgLen := uint16(len(msg))
buf := make([]byte, 2)
buf[0] = uint8(msgLen >> 8)
buf[1] = uint8(msgLen & 0xff)
_, err = conn.Write(buf)
if err != nil {
return err
}
_, err = conn.Write(msg)
if err != nil {
return err
}
return nil
}

func SendGmm(conn net.Conn, gmm nas.GmmHeader) (err error) {
pkt, err := parser.EncodeMsg(&gmm)
if err != nil {
return err
}

return Send(conn, pkt)
}

func SendNgapMsg[T any](conn net.Conn, ngapType ngap.NgapMsgType, msgPtr *T) (err error) {
ngapPdu, err := parser.EncodeMsg(&msgPtr)
if err != nil {
return err
}
ngapHeader := ngap.NgapHeader{MessageType: ngapType, NgapPdu: ngapPdu}
pkt, err := parser.EncodeMsg(&ngapHeader)
if err != nil {
return err
}

return Send(conn, pkt)
}

func Recv(conn net.Conn) ([]byte, error) {
buf := make([]byte, 2)

_, err := conn.Read(buf)
if err != nil {
return nil, err
}

msgLen := uint16(buf[1]) | uint16(buf[0])<<8
if msgLen < 1 {
return nil, errors.New("msg length of buffer is zero or negative")
}
buf = make([]byte, msgLen)
_, err = conn.Read(buf)
return buf, err

}
171 changes: 171 additions & 0 deletions service_hidden/src/pkg/nas/msgTypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package nas

import "github.com/gofrs/uuid"

type NasMsgType int
type AmfUeNgapIdType uuid.UUID

const (
NASRegRequest NasMsgType = iota
NASIdRequest
NASIdResponse
NASAuthRequest
NASAuthResponse
NASSecurityModeCommand
NASSecurityModeComplete
InitialContextSetupRequestRegAccept
UECapInfoIndication
InitialContextSetupResponse
RegisterComplete
PDUSessionEstRequest
PDUSessionEstAccept
PDUReq
PDURes
PDUSessionResourceReleaseCommand
// Location
LocationUpdate
LocationReportRequest
LocationReportResponse
)

type EaMask uint8

const (
EA0 EaMask = 1 << iota
EA1
EA2
EA3
EA4
EA5
EA6
EA7
)

var EaMaskMap = []EaMask{
EA0,
EA1,
EA2,
EA3,
EA4,
EA5,
EA6,
EA7,
}

type IaMask uint8

const (
IA0 IaMask = 1 << iota
IA1
IA2
IA3
IA4
IA5
IA6
IA7
)

var IaMaskMap = []IaMask{
IA0,
IA1,
IA2,
IA3,
IA4,
IA5,
IA6,
IA7,
}

type SecCapType struct {
// 1 | 2 | .. | 8
// EA0 | EA1 | .. | EA7
EaCap EaMask
// 1 | 2 | .. | 8
// IA0 | IA1 | .. | IA7
IaCap IaMask
}

type GmmHeader struct {
// MobileId MobileIdType
Security bool
Mac [8]byte
MessageType NasMsgType
Message []byte
}

type MobileIdType struct {
// SupiFormat uint8
// IdType
Mcc uint8
Mnc uint8
// Routing indicator
ProtecScheme uint8
HomeNetPki uint8
Msin uint
}

type NASRegRequestMsg struct {
// Extended protocol discriminator
SecHeader uint8
// 5GS registration type
// ngKsi
MobileId MobileIdType
SecCap SecCapType
}

type NASAuthRequestMsg struct {
SecHeader uint8
Rand []byte
AuthRand []byte
Auth []byte
}

type NASAuthResponseMsg struct {
SecHeader uint8
Res []byte
}

type NASSecurityModeCommandMsg struct {
SecHeader uint8
EaAlg uint8
IaAlg uint8
ReplaySecCap SecCapType
}

type PDUSessionEstRequestMsg struct {
PduSesId uint8
PduSesType uint8
// add integrity protetion maximum data rate
}

type PDUSessionEstAcceptMsg struct {
PduSesId uint8
// PduAddress []byte
// SSC
// QoS
// AMBR
}

type LocationUpdateMsg struct {
Location string
}

type LocationReportRequestMsg struct {
AmfUeNgapId AmfUeNgapIdType
RanUeNgapId uint32
}

type LocationReportResponseMsg struct {
AmfUeNgapId AmfUeNgapIdType
RanUeNgapId uint32
Locations []string
}

type PDUReqMsg struct {
PduSesId uint8
Request []byte
}
type PDUResMsg struct {
PduSesId uint8
Response []byte
}
Loading

0 comments on commit 3133d59

Please sign in to comment.