Add ability to recover clients from config file

This commit is contained in:
raul 2024-06-07 12:03:30 +02:00
parent b42f31d4be
commit ebde90cce2
1 changed files with 24 additions and 8 deletions

View File

@ -13,10 +13,12 @@ import (
) )
var ( var (
C2Port string = "1302" C2Port string = "1302"
clientList []Client clientList []Client
clientIDs int = 0 clientIDs int = 0
clientJSONPath string = "/home/raul/.config/tiamat/clients.json"
isUsingJSONParameter bool
clientJSONPath string = "/.config/tiamat/clients.json"
) )
func (c Client) Instruct(i Instructions) error { func (c Client) Instruct(i Instructions) error {
@ -29,11 +31,26 @@ func (c Client) Instruct(i Instructions) error {
} }
func recoverClients() error { func recoverClients() error {
var fileToOpen string
home, err := os.UserHomeDir()
if err != nil {
return err
}
if isUsingJSONParameter == false {
fileToOpen = home + clientJSONPath
configPath := viper.GetString("Server.ClientPath")
if configPath != "" {
fileToOpen = configPath
}
} else {
fileToOpen = clientJSONPath
}
clients := ClientJSON{} clients := ClientJSON{}
file, err := os.Open(clientJSONPath) file, err := os.Open(fileToOpen)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
fmt.Println("CLIENTJSON DOES NOT EXIST") log.Printf("Missing file at %v\n", fileToOpen)
return nil return nil
} }
return err return err
@ -54,6 +71,7 @@ func recoverClients() error {
} }
func Server() { func Server() {
log.SetPrefix("[TIAMAT] ")
p := viper.GetString("Server.Port") p := viper.GetString("Server.Port")
if p != "" { if p != "" {
C2Port = p C2Port = p
@ -64,8 +82,6 @@ func Server() {
log.Fatalf("Error happened recovering clients: %v\n", err) log.Fatalf("Error happened recovering clients: %v\n", err)
} }
log.SetPrefix("[TIAMAT] ")
ln, err := net.Listen("tcp", ":"+C2Port) ln, err := net.Listen("tcp", ":"+C2Port)
if err != nil { if err != nil {
log.Fatalf("Error happened listening on C2 port: %v\n", err) log.Fatalf("Error happened listening on C2 port: %v\n", err)