JohnLyu的blog

橙汁事务所艾欧泽亚分部

0%

wechat id for you

  • hint: python format

wechat id for you is here

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
import html
import secrets

from flask import Flask, Response, request

from flag import FLAG, GIFT

app = Flask(__name__)


def read(filename, encoding='utf-8'):
with open(filename, 'r', encoding=encoding) as fin:
return fin.read()


@app.route('/', methods=['GET'])
def index():
guess = request.args.get('guess')

if not guess:
return Response(read(__file__), mimetype='text/plain')

if guess == secrets.token_hex(16):
return 'Nice guess! Your flag is {}'.format(FLAG)
elif guess == "giveup":
return 'Give up is OK, sweet gift for you: {}'.format(GIFT)

fs = ('Better luck next time!<br/>'
'Your IP: {r.remote_addr}<br/>'
'Your User Agent: {r.user_agent}<br/>'
'Your Guess: ' + html.escape(guess))
return fs.format(r=request)


if __name__ == '__main__':
app.run(host='0.0.0.0', port=15000)