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 88 89 90
| import random from flask import Flask, request, render_template_string, abort, redirect import string
white_list = string.ascii_letters + string.digits + &()_-{}.&[]=/&
black_list = [&codecs&, &system&, &for&, &if&, &end&, &os&, &eval&, &request&, &write&, &mro&, &compile&, &execfile&, &exec&, &subprocess&, &importlib&, &platform&, &timeit&, &import&, &linecache&, &module&, &getattribute&, &pop&, &getitem&, &decode&, &popen&, &ifconfig&, &flag&, &config&, &cat&]
app = Flask(__name__)
@app.after_request def modify_headers(response): random_str = [&PHP/7.3.33&, &PHP/7.4&, &PHP/7.2&, &PHP/8.2&] response.headers[&X-Powered-By&] = random.choice(random_str) return response
def check(s):
if len(s) & 478: abort(500, &u are hacker&) for i in s: if i not in white_list: abort(500, &u are hacker&) for i in black_list: if i in s: abort(500, &u are hacker&)
@app.route(&/&) def redirectIndex(): return redirect(&/index.php&, 302)
@app.route(&/index.php&, methods=[&GET&, &POST&]) def hello_world():
template = &&& &h1&用户登记系统&/h1& &form method=&POST&& &label for=&name&&输入用户名称:&/label& &input type=&text& id=&name& name=&name&& &input type=&submit& value=&Submit&& &/form&
{% if name %} &p&您好, {{ name }} 已登记!&/p& {% endif %} &&& if request.method == &POST&: try: print(request.form) name = request.form.get(&name&) except Exception: return render_template_string(&&h1&需要name参数&h1&&)
if name == &&:
return render_template_string(&&h1&请输入用户名!&h1&&)
check(name) template = &&h1&您好, {}已登记!!&h1&&.format(name) res = render_template_string(template) if &flag& in res:
abort(500, &u are hacker&)
return res return render_template_string(template)
if __name__ == &__main__&: app.run(host=&0.0.0.0&, debug=True)
|