Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Aug 31, 2024
1 parent d09b7de commit 3a8ad6a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions web-security/level-1/server
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ app = flask.Flask(__name__)
@app.route("/<path:path>", methods=["GET", "POST"])
def challenge(path="index.html"):
requested_path = app.root_path + "/files/" + path
real_path = os.path.realpath(requested_path)

try:
return open(requested_path).read()
except PermissionError:
flask.abort(403, real_path)
flask.abort(403, requested_path)
except FileNotFoundError:
flask.abort(404, real_path)
flask.abort(404, f"No {requested_path} from directory {os.getcwd()}")
except Exception as e:
flask.abort(500, real_path + ":" + str(e))
flask.abort(500, requested_path + ":" + str(e))

app.secret_key = open("/flag").read().strip()
app.run("challenge.localhost", int(os.environ.get("HTTP_PORT", 80)))
1 change: 0 additions & 1 deletion web-security/level-2/run

This file was deleted.

7 changes: 3 additions & 4 deletions web-security/path-traversal-2/server
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ app = flask.Flask(__name__)
@app.route("/<path:path>", methods=["GET", "POST"])
def challenge(path="index.html"):
requested_path = app.root_path + "/files/" + path.strip("/.")
real_path = os.path.realpath(requested_path)

try:
return open(requested_path).read()
except PermissionError:
flask.abort(403, real_path)
flask.abort(403, requested_path)
except FileNotFoundError:
flask.abort(404, real_path)
flask.abort(404, f"No {requested_path} from directory {os.getcwd()}")
except Exception as e:
flask.abort(500, real_path + ":" + str(e))
flask.abort(500, requested_path + ":" + str(e))

app.secret_key = open("/flag").read().strip()
app.run("challenge.localhost", int(os.environ.get("HTTP_PORT", 80)))

0 comments on commit 3a8ad6a

Please sign in to comment.