-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.cgi
executable file
·87 lines (70 loc) · 2.36 KB
/
proxy.cgi
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
#!/bin/python3
import codecs
import os
import sys
import requests
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
def printCorsHeaders():
print("Access-Control-Allow-Headers:Content-Type,X-Cookie,Clientdate,Android-Id,Device-Info,Target-Path,Target-Host,Dt,H,W,Hmac")
print("Access-Control-Expose-Headers:X-Set-Cookie,Set-Cookie")
print("Access-Control-Allow-Methods:GET,HEAD,PUT,PATCH,POST,DELETE")
print("Access-Control-Allow-Origin:http://localhost:8080")
if os.environ.get('REQUEST_METHOD') == "OPTIONS":
printCorsHeaders()
print("Status: 204 No Content\n")
sys.exit()
# Check if http header is for valid host
host = os.environ.get('HTTP_TARGET_HOST', None)
if host == 'qkgermany.feoquizserver.com':
method = os.environ.get('REQUEST_METHOD')
path = os.environ.get('HTTP_TARGET_PATH', '')
content_type = os.environ.get('CONTENT_TYPE', None)
cookie = os.environ.get('HTTP_X_COOKIE', None)
device_type = os.environ.get('HTTP_DT', None)
device_info = os.environ.get('HTTP_DEVICE_INFO', None)
android_id = os.environ.get('HTTP_ANDROID_ID', None)
clientdate = os.environ.get('HTTP_CLIENTDATE', None)
hmac = os.environ.get('HTTP_HMAC', None)
height = os.environ.get('HTTP_H', None)
width = os.environ.get('HTTP_W', None)
session = requests.Session()
headers = {
"Content-Type": content_type,
"Cookie": cookie,
"Clientdate": clientdate,
"Dt": device_type,
"Device-Info": device_info,
"Android-Id": android_id,
"Hmac": hmac,
"H": height,
"W": width,
}
printCorsHeaders()
print("Cache-Control: no-cache")
url = "https://%s/%s" % (host, path)
input_data = sys.stdin.buffer.read()
try:
if method == 'GET':
r = session.get(url, headers=headers, data=input_data)
elif method == 'POST':
r = session.post(url, headers=headers, data=input_data)
except:
print("Content-Type: text/json")
print("Status: 500 Internal Server Error\n")
print('{"message":"Failed to contact remote server"}')
sys.exit()
for key, value in r.headers.items():
if key == 'Content-Encoding' or key == 'Transfer-Encoding':
continue
if key == 'Set-Cookie':
print("X-Set-Cookie: %s" % value)
continue
print("%s: %s" % (key, value))
print("Status: %d %s\n" % (r.status_code, r.reason))
# Forward response body
r.encoding='utf-8'
print(r.text)
sys.exit()
print("Status: 403 Forbidden\n")
print("Forbidden")
sys.exit()