Skip to content

Commit

Permalink
pwnshopize xss-stored-alert
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Dec 24, 2024
1 parent af56848 commit 982bbd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions web-security/pwnshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ challenges:
challenge: SQLInjectionBlind
- id: xss-stored-html
challenge: XSSStoredHTML
- id: xss-stored-alert
challenge: XSSStoredAlert
16 changes: 12 additions & 4 deletions web-security/xss-stored-alert/server
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/opt/pwn.college/python

import tempfile
import sqlite3
import flask
import os

app = flask.Flask(__name__)


import sqlite3
import tempfile


class TemporaryDB:
def __init__(self):
self.db_file = tempfile.NamedTemporaryFile("x", suffix=".db")
Expand All @@ -19,26 +22,31 @@ class TemporaryDB:
connection.commit()
return result


db = TemporaryDB()

# https://www.sqlite.org/lang_createtable.html
db.execute("""CREATE TABLE posts AS SELECT "First Post!" AS content""")


@app.route("/", methods=["POST"])
def challenge_post():
content = flask.request.form.get("content", "")
db.execute("INSERT INTO posts VALUES (?)", [content])
return flask.redirect(flask.request.path)


@app.route("/", methods=["GET"])
def challenge_get():
page = "<html><body>\nWelcome to pwnpost, the anonymous posting service. Post away!\n"
page += "<form method=post>Post:<input type=text name=content></form>\n"
page += "<form method=post>Post:<input type=text name=content><input type=submit value=Submit></form>\n"

for post in db.execute("SELECT content FROM posts").fetchall():
page += "<hr>" + post["content"] + "\n"

return page + "</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)
6 changes: 3 additions & 3 deletions web-security/xss-stored-alert/victim
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ service = FirefoxService(log_path="/dev/null")
browser = webdriver.Firefox(service=service, options=options)
atexit.register(browser.quit)

open_ports = { s.laddr.port for s in psutil.net_connections(kind="inet") if s.status == 'LISTEN' }
open_ports = {s.laddr.port for s in psutil.net_connections(kind="inet") if s.status == "LISTEN"}
if 80 not in open_ports:
print("Service doesn't seem to be running?")
sys.exit(1)

challenge_url = "http://challenge.localhost:80/"
flag = open("/flag").read().strip()

print(f"Visiting {challenge_url}")
browser.get(challenge_url)
Expand All @@ -41,4 +41,4 @@ except TimeoutException:
sys.exit(3)
else:
print("Alert triggered! Your reward:")
print(flag)
print(open("/flag").read().strip())

0 comments on commit 982bbd9

Please sign in to comment.