Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setup script and improve output of gnb #39

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Use https://gitignore.io/ to create a suitable .gitignore file for your project.
data/
./gnb
Binary file removed service/gnb
Binary file not shown.
5 changes: 5 additions & 0 deletions service/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd src
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../gnb cmd/gnb/main.go
rm -rf cmd/gnb
38 changes: 27 additions & 11 deletions service/src/cmd/gnb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func handleUeConnection(ueConn net.Conn) {
return
}

fmt.Printf("\nSuccessfully connected to UE\n\n")

fmt.Println("=============================")
fmt.Printf("FROM UE: (NASRegRequest)\n %s\n", reply)

Expand All @@ -35,7 +37,9 @@ func handleUeConnection(ueConn net.Conn) {
}

initUeMsg := ngap.InitUEMessageMsg{NasPdu: gmm, RanUeNgapId: 1}
fmt.Printf("TO CORE: (InitUEMessage + NASRegRequest)\n %s\n", initUeMsg)
buf, _ := parser.EncodeMsg(&initUeMsg)
fmt.Println("=============================")
fmt.Printf("TO CORE: (InitUEMessage + NASRegRequest)\n %s\n", buf)
err = io.SendNgapMsg(coreConn, ngap.InitUEMessage, &initUeMsg)
if err != nil {
fmt.Printf("Error sending: %#v\n", err)
Expand Down Expand Up @@ -65,8 +69,9 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&down.NasPdu)
fmt.Println("=============================")
fmt.Printf("TO UE: (NASAuthRequest)\n %s\n", down.NasPdu)
fmt.Printf("TO UE: (NASAuthRequest)\n %s\n", buf)
err = io.SendGmm(ueConn, down.NasPdu)
if err != nil {
fmt.Printf("Error sending: %#v\n", err)
Expand All @@ -81,7 +86,6 @@ func handleUeConnection(ueConn net.Conn) {

fmt.Println("=============================")
fmt.Printf("FROM UE: (NASAuthRes)\n %s\n", reply)

amfUeNgapId := down.AmfUeNgapId

// AuthRes
Expand All @@ -100,8 +104,9 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&up)
fmt.Println("=============================")
fmt.Printf("TO CORE: (UpNASTrans + NASAuthRes)\n %s\n", up)
fmt.Printf("TO CORE: (UpNASTrans + NASAuthRes)\n %s\n", buf)

// SecModeCmd
reply, err = io.Recv(coreConn)
Expand All @@ -128,8 +133,9 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&down.NasPdu)
fmt.Println("=============================")
fmt.Printf("TO UE: (NASSecurityModeCommand)\n %s\n", down.NasPdu)
fmt.Printf("TO UE: (NASSecurityModeCommand)\n %s\n", buf)
err = io.SendGmm(ueConn, down.NasPdu)
if err != nil {
fmt.Printf("Error sending: %#v\n", err)
Expand Down Expand Up @@ -159,8 +165,9 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&up)
fmt.Println("=============================")
fmt.Printf("TO CORE: (UpNASTrans + LocationUpdate)\n %s\n", up)
fmt.Printf("TO CORE: (UpNASTrans + LocationUpdate)\n %s\n", buf)

// PDUSessionReq
reply, err = io.Recv(ueConn)
Expand All @@ -185,7 +192,8 @@ func handleUeConnection(ueConn net.Conn) {
return
}
fmt.Println("=============================")
fmt.Printf("TO CORE: (UpNASTrans + PDUSessionEstRequest)\n %s\n", up)
buf, _ = parser.EncodeMsg(&up)
fmt.Printf("TO CORE: (UpNASTrans + PDUSessionEstRequest)\n %s\n", buf)

// PDUSessionAccept

Expand Down Expand Up @@ -219,8 +227,9 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&down.NasPdu)
fmt.Println("=============================")
fmt.Printf("TO UE: (PDUSessionEstResponse)\n %s\n", down.NasPdu)
fmt.Printf("TO UE: (PDUSessionEstResponse)\n %s\n", buf)

// PDUReq

Expand All @@ -247,8 +256,9 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&up)
fmt.Println("=============================")
fmt.Printf("TO CORE: (UpNASTrans + PDUReq)\n %s\n", up)
fmt.Printf("TO CORE: (UpNASTrans + PDUReq)\n %s\n", buf)

// PDURes

Expand Down Expand Up @@ -282,16 +292,20 @@ func handleUeConnection(ueConn net.Conn) {
return
}

buf, _ = parser.EncodeMsg(&down.NasPdu)
fmt.Println("=============================")
fmt.Printf("TO UE: (PDURes)\n %s\n", down.NasPdu)
fmt.Printf("TO UE: (PDURes)\n %s\n", buf)

return
}

}

func main() {
fmt.Println("5Go gNB tool - your friendly fake basestation")
fmt.Printf("\n===== 5Go gNB jammer =====\n\n")
fmt.Println("Bip bop... overpowering nearest basestations....")
fmt.Println("CORE <-X-> gNB <-X-> UE")
fmt.Printf("Creating fake basetation...\n\n")
fmt.Println("Enter 5Go CORE address: <IP:PORT>")
reader := bufio.NewReader(os.Stdin)
addr, err := reader.ReadString('\n')
Expand Down Expand Up @@ -334,6 +348,8 @@ func main() {
fmt.Println("=============================")
fmt.Printf("FROM CORE: (NGSetupResponse)\n %s\n", buf)

fmt.Println("=============================")
fmt.Printf("\nSuccessfully connected to CORE\n\n")
fmt.Println("Enter 5Go UE address: <IP:PORT>")
reader = bufio.NewReader(os.Stdin)
addr, err = reader.ReadString('\n')
Expand Down