Skip to content

Commit

Permalink
pwnshopped sqli-pin
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Dec 18, 2024
1 parent d4039e0 commit 3bcc31b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions web-security/pwnshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ challenges:
- id: cmdi-ls-filter
challenge: CommandInjectionLSFilter
binary_name: server
- id: sqli-pin
challenge: SQLInjectionPin
binary_name: server
14 changes: 11 additions & 3 deletions web-security/sqli-pin/server
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import os

app = flask.Flask(__name__)


class TemporaryDB:
def __init__(self):
self.db_file = tempfile.NamedTemporaryFile("x", suffix=".db")
Expand All @@ -20,12 +21,14 @@ class TemporaryDB:
connection.commit()
return result


db = TemporaryDB()
# https://www.sqlite.org/lang_createtable.html
db.execute("""CREATE TABLE users AS SELECT "admin" AS username, ? as pin""", [random.randrange(2**32, 2**63)])
# https://www.sqlite.org/lang_insert.html
db.execute("""INSERT INTO users SELECT "guest" as username, 1337 as pin""")


@app.route("/", methods=["POST"])
def challenge_post():
username = flask.request.form.get("username")
Expand All @@ -34,7 +37,7 @@ def challenge_post():
flask.abort(400, "Missing `username` form parameter")
if not pin:
flask.abort(400, "Missing `pin` form parameter")

if pin[0] not in "0123456789":
flask.abort(400, "Invalid pin")

Expand All @@ -52,6 +55,7 @@ def challenge_post():
flask.session["user"] = username
return flask.redirect(flask.request.path)


@app.route("/", methods=["GET"])
def challenge_get():
if not (username := flask.session.get("user", None)):
Expand All @@ -61,14 +65,18 @@ def challenge_get():
if username == "admin":
page += "<br>Here is your flag: " + open("/flag").read()

return page + """
return (
page
+ """
<hr>
<form method=post>
User:<input type=text name=username>PIN:<input type=text name=pin><input type=submit value=Submit>
</form>
</body></html>
"""
)


app.secret_key = os.urandom(8)
app.config['SERVER_NAME'] = f"challenge.localhost:80"
app.config["SERVER_NAME"] = f"challenge.localhost:80"
app.run("challenge.localhost", 80)

0 comments on commit 3bcc31b

Please sign in to comment.