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
| import base64, pickle, jwt, os
from sanic import Sanic
from sanic.response import text, html
from difflib import SequenceMatcher
app = Sanic(__name__)
APP_SECRET = os.urandom(32).hex()
jrl = [jwt.encode({"admin": True, "uid": '5201314'}, APP_SECRET, algorithm="HS256")]
def similar(a, b):
return SequenceMatcher(None, a, b).ratio() > 0.88
def check_waf(payload):
dangerous_keywords = [b'exception', b'listener', b'get', b'post', b'add_route']
return not any(k in payload.lower() for k in dangerous_keywords)
def verify_admin(request):
token = request.cookies.get('session', None).strip().replace('=', '')
if token in jrl:
return False
try:
payload = jwt.decode(token, APP_SECRET, algorithms=["HS256"])
return payload.get('admin') == True
except:
return False
@app.route('/', methods=['GET', 'POST'])
async def index(request):
return text('gogogo')
@app.route("/login")
async def login(request):
user = request.cookies.get("user")
if user and similar(user.lower(), 'admin'):
token = jwt.encode({"admin": False, "user": user}, APP_SECRET, algorithm="HS256")
resp = text("login success")
resp.cookies["session"] = token
return resp
return text("login fail")
@app.route("/src")
async def src(request):
return text(open('app.py').read())
@app.route("/admin", methods=['GET', 'POST'])
async def admin(request):
if not verify_admin(request):
return text("forbidden")
cmd = request.form.get('cmd')
if cmd:
try:
decoded_cmd = base64.b64decode(cmd)
if not check_waf(decoded_cmd):
return text("WAF: Dangerous keywords detected!")
pickle.loads(decoded_cmd)
except Exception as e:
return text(f"Error: {str(e)}")
return text("gogogo")
@app.route('/jrl', methods=['GET'])
async def jrl_endpoint(request):
return text(str(jrl))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
|