This repository has been archived by the owner on May 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evil_client.py
executable file
·64 lines (51 loc) · 1.7 KB
/
evil_client.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import requests
ENV_VAR = "ENIGMA2_HTTP_API_HOST"
ENV_VAL_FALLBACK = "127.0.0.1"
PAYLOAD_FALLBACK = """
import platform
print platform.system()
"""
def evil_client(base_url, payload=None):
endpoint = "{base_url}/api/evil".format(base_url=base_url)
if payload is None:
payload = PAYLOAD_FALLBACK
req = requests.post(endpoint, data={"uma": payload})
print("Request to {!r} yielded HTTP status code {:d}".format(
endpoint, req.status_code))
data = req.json()
if data.get("uma") is True:
print data['stdout']
else:
print data.get("exception")
def dump_disclaimer():
print("In order for this test to work the environment variable")
print(">>> {var: ^70} <<<".format(var=ENV_VAR))
print("needs to be set to the hostname/network location of an "
"enigma2 device reachable by this script!")
print("If this is not the case, the fallback value")
print(">>> {val: ^70} <<<".format(val=ENV_VAL_FALLBACK))
print("will be used!")
print("")
print("We will be using the network location {val!r}:".format(
val=os.environ.get(ENV_VAR, ENV_VAL_FALLBACK)))
print("")
print("")
if __name__ == '__main__':
dump_disclaimer()
base_url = "http://{:s}".format(os.environ.get(ENV_VAR, ENV_VAL_FALLBACK))
payload = None
for key in ('http_proxy', 'https_proxy'):
try:
del os.environ[key]
except KeyError:
pass
if len(sys.argv) > 1:
source = sys.argv[1]
print("Payload: {!r}".format(source))
with open(source, "rb") as src:
payload = src.read()
evil_client(base_url, payload)