-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Authentication bypasses are not always so trivial. | ||
Sometimes, the logic of the application might look correct, but again, the gap between what the developer expects to be true and what will actually be true rears its ugly head. | ||
Give this level a try, and remember: _you_ control the requests, including all the HTTP headers sent! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/opt/pwn.college/python | ||
|
||
import tempfile | ||
import sqlite3 | ||
import flask | ||
import os | ||
|
||
app = flask.Flask(__name__) | ||
|
||
class TemporaryDB: | ||
def __init__(self): | ||
self.db_file = tempfile.NamedTemporaryFile("x", suffix=".db") | ||
|
||
def execute(self, sql, parameters=()): | ||
connection = sqlite3.connect(self.db_file.name) | ||
connection.row_factory = sqlite3.Row | ||
cursor = connection.cursor() | ||
result = cursor.execute(sql, parameters) | ||
connection.commit() | ||
return result | ||
|
||
db = TemporaryDB() | ||
# https://www.sqlite.org/lang_createtable.html | ||
db.execute("""CREATE TABLE IF NOT EXISTS users AS SELECT "admin" AS username, ? as password""", [os.urandom(8).decode('latin1')]) | ||
# https://www.sqlite.org/lang_insert.html | ||
db.execute("""INSERT INTO users SELECT "guest" as username, "password" as password""") | ||
|
||
@app.route("/", methods=["POST"]) | ||
def challenge_post(): | ||
username = flask.request.form.get("username") | ||
password = flask.request.form.get("password") | ||
if not username: | ||
flask.abort(400, "Missing `username` form parameter") | ||
if not password: | ||
flask.abort(400, "Missing `password` form parameter") | ||
|
||
user = db.execute("SELECT rowid, * FROM users WHERE username = ? AND password = ?", (username, password)).fetchone() | ||
if not user: | ||
flask.abort(403, "Invalid username or password") | ||
|
||
response = flask.redirect(flask.request.path) | ||
response.set_cookie('session_user', username) | ||
return response | ||
|
||
@app.route("/", methods=["GET"]) | ||
def challenge_get(): | ||
page = "<html><body>" | ||
if "session_user" not in flask.request.cookies: | ||
page += "Welcome to the login service! Please log in as admin to get the flag." | ||
else: | ||
username = flask.request.cookies["session_user"] | ||
page = f"<html><body>Hello, {username}!" | ||
if username == "admin": | ||
page += "<br>Here is your flag: " + open("/flag").read() | ||
|
||
return page + """ | ||
<hr> | ||
<form method=post> | ||
User:<input type=text name=username>Pass:<input type=text name=password><input type=submit value=Submit> | ||
</form> | ||
</body></html> | ||
""" | ||
|
||
os.setuid(os.geteuid()) | ||
app.secret_key = os.urandom(8) | ||
app.run("challenge.localhost", int(os.environ.get("HTTP_PORT", 80))) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters