Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions challenges/web-security/.gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
**/tests_private/** filter=git-crypt-web-security diff=git-crypt-web-security
common/xss-advanced.py.j2 filter=git-crypt-web-security diff=git-crypt-web-security
common/xss-browser.py.j2 filter=git-crypt-web-security diff=git-crypt-web-security
postmessage-origin-validation/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-csp-gadget/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-css-exfil/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-dangling-markup/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-dom-clobbering/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-httponly/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-mutation/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
xss-prototype-pollution/challenge/** filter=git-crypt-web-security diff=git-crypt-web-security
12 changes: 9 additions & 3 deletions challenges/web-security/common/dockerfile.selenium.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
{% block additional_packages %}{% endblock %}
{% block before_copy %}
RUN <<END
apt-get install -y python3-pip wget python3-selenium python3-psutil curl software-properties-common
set -e
apt-get update
apt-get install -y software-properties-common
add-apt-repository -y ppa:mozillateam/ppa
echo 'Package: firefox*' > /etc/apt/preferences.d/mozilla-firefox
echo 'Pin: release o=LP-PPA-mozillateam' >> /etc/apt/preferences.d/mozilla-firefox
echo 'Pin-Priority: 1001' >> /etc/apt/preferences.d/mozilla-firefox
apt-get update
apt-get install -y firefox
apt-get install -y curl firefox python3-pip python3-psutil python3-selenium wget
END
RUN curl -L https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz | tar xz -C /usr/local/bin
RUN curl --fail --show-error --location --retry 3 \
--output /tmp/geckodriver.tar.gz \
https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
RUN tar xzf /tmp/geckodriver.tar.gz -C /usr/local/bin
RUN rm /tmp/geckodriver.tar.gz
{% endblock %}
2 changes: 1 addition & 1 deletion challenges/web-security/common/init.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

[ -x /challenge/server ] && chmod u+s /challenge/server
[ -x /challenge/victim ] && chmod u+s /challenge/victim
echo "127.0.0.1 hacker.localhost challenge.localhost" >> /etc/hosts
echo "127.0.0.1 hacker.localhost challenge.localhost{% block additional_hosts %}{% endblock %}" >> /etc/hosts
Binary file added challenges/web-security/common/xss-advanced.py.j2
Binary file not shown.
Binary file added challenges/web-security/common/xss-browser.py.j2
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Frames and windows from different origins cannot directly read each other's pages, so applications often use `postMessage()` to communicate across that boundary.
The receiving page must authenticate both the sender's exact origin and the window that sent the message before returning sensitive data.
A hostname-suffix check can mistake an attacker-controlled subdomain for the intended peer, and a permissive reply sends the result back across the boundary.
Build a page at `http://hacker.challenge.localhost:1337/` that talks to the administrator's dashboard, recover its token, and redeem it for the flag.
Run `/challenge/server`, start your web server, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

response = requests.get(
"http://challenge.localhost/redeem", params={"token": "wrong"}
)
assert response.status_code == 403

response = requests.get("http://challenge.localhost:8080/")
response.raise_for_status()
assert '<iframe id=dashboard src="http://challenge.localhost/">' in response.text

response = requests.get("http://challenge.localhost:8080/missing")
assert response.status_code == 404
finally:
server.terminate()
server.wait()
5 changes: 5 additions & 0 deletions challenges/web-security/xss-csp-gadget/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A nonce-based Content Security Policy authorizes trusted scripts while rejecting injected script elements and event handlers.
With `'strict-dynamic'`, that trust also follows scripts which an authorized script loads at runtime.
This is safe only when every trusted loader keeps attacker-controlled values away from its script source.
Find the loader gadget in the administrator's review page, make trusted code load your script, and exfiltrate the protected data.
Run `/challenge/server`, save your markup, start your web server, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3

import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

payload = '<div data-module="http://example.invalid/module.js"></div>'
requests.post(
"http://challenge.localhost/payload", data={"payload": payload}
).raise_for_status()
response = requests.get("http://challenge.localhost/")
response.raise_for_status()
assert payload not in response.text
assert requests.get("http://challenge.localhost/admin/secret").status_code == 403
finally:
server.terminate()
server.wait()
5 changes: 5 additions & 0 deletions challenges/web-security/xss-css-exfil/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Blocking JavaScript does not make attacker-controlled CSS inert.
CSS attribute selectors can test secrets already present in the DOM, while a matching rule can trigger an outbound request through `url()`.
Repeated guesses turn those conditional requests into an oracle that reveals the secret one piece at a time.
Recover the administrator's token without JavaScript, redeem it, and get the flag.
Run `/challenge/server`, save your CSS, start your listener, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions challenges/web-security/xss-css-exfil/tests_public/test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

css = "#account { color: rgb(1, 2, 3); }"
requests.post(
"http://challenge.localhost/payload",
data={"payload": css},
).raise_for_status()

response = requests.get("http://challenge.localhost/")
response.raise_for_status()
assert css in response.text
assert "data-token=" not in response.text
policy = response.headers["Content-Security-Policy"]
assert "default-src 'none'" in policy
assert "style-src 'unsafe-inline'" in policy
assert "img-src http://hacker.localhost:1337" in policy

response = requests.get("http://challenge.localhost/redeem", params={"token": "wrong"})
assert response.status_code == 403
finally:
server.terminate()
server.wait()
5 changes: 5 additions & 0 deletions challenges/web-security/xss-dangling-markup/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
An HTML injection can alter how the browser parses markup that follows it even when Content Security Policy blocks JavaScript.
Leaving an attribute value unfinished can make later page content part of a resource URL, causing the browser to send that content to another origin.
This technique is called dangling-markup injection.
Use the administrator's review page to capture its token without JavaScript, then redeem the token for the flag.
Run `/challenge/server`, save your markup, start your listener, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

payload = "<strong>review me</strong>"
requests.post(
"http://challenge.localhost/payload", data={"payload": payload}
).raise_for_status()
response = requests.get("http://challenge.localhost/")
response.raise_for_status()
assert payload not in response.text
assert "default-src 'none'" in response.headers["Content-Security-Policy"]
assert "data-token" not in response.text
assert (
requests.get(
"http://challenge.localhost/redeem", params={"token": "wrong"}
).status_code
== 403
)
finally:
server.terminate()
server.wait()
5 changes: 5 additions & 0 deletions challenges/web-security/xss-dom-clobbering/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTML elements with certain `id` and `name` values become named properties on the page's global object.
Legacy compatibility makes that behavior useful to ordinary pages, but it also means injected markup can replace values that trusted JavaScript expects to be plain configuration objects.
When that script uses the resulting property in a security-sensitive operation, markup alone can redirect its behavior without injecting a new script.
Use that behavior to steer the administrator page's trusted code, recover its token, and redeem it for the flag.
Run `/challenge/server`, save your markup, start your listener, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

payload = "<strong>review me</strong>"
requests.post(
"http://challenge.localhost/payload", data={"payload": payload}
).raise_for_status()
response = requests.get("http://challenge.localhost/")
response.raise_for_status()
assert payload not in response.text

response = requests.post(
"http://challenge.localhost/login",
data={"username": "admin", "password": "incorrect"},
)
assert response.status_code == 403
finally:
server.terminate()
server.wait()
4 changes: 4 additions & 0 deletions challenges/web-security/xss-httponly/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
An `HttpOnly` session cookie cannot be read through `document.cookie`.
The browser still attaches that cookie to same-origin requests made by injected JavaScript, and the script can read the responses to those requests.
Use the administrator's browser to retrieve protected data and exfiltrate it to a server you control.
Run `/challenge/server`, save your payload, start your listener, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions challenges/web-security/xss-httponly/tests_public/test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

response = requests.get("http://challenge.localhost/admin/secret")
assert response.status_code == 403

payload = "<strong>administrator review</strong>"
response = requests.post("http://challenge.localhost/payload", data={"payload": payload})
response.raise_for_status()

response = requests.post(
"http://challenge.localhost/login",
data={"username": "admin", "password": "incorrect"},
allow_redirects=False,
)
assert response.status_code == 403
assert "Set-Cookie" not in response.headers
finally:
server.terminate()
server.wait()
5 changes: 5 additions & 0 deletions challenges/web-security/xss-mutation/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTML sanitization is tied to the parse tree and context that the sanitizer inspected.
If an application later concatenates that output into a raw-text wrapper and parses it again, text that was harmless inside an attribute can acquire structural meaning.
This parse-sanitize-reparse gap is called mutation XSS.
Make the review system's markup-source preview mutate sanitized input into executable markup and exfiltrate the administrator's protected data.
Run `/challenge/server`, save your markup, start your listener, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions challenges/web-security/xss-mutation/tests_public/test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python3

import subprocess
import time

import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.service import Service as FirefoxService


server = subprocess.Popen(["/challenge/server"])
browser = None
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

payload = "<strong>formatted review</strong>"
requests.post(
"http://challenge.localhost/payload", data={"payload": payload}
).raise_for_status()
response = requests.get("http://challenge.localhost/")
response.raise_for_status()
assert payload not in response.text

options = FirefoxOptions()
options.add_argument("--headless")
service = FirefoxService(
executable_path="/usr/local/bin/geckodriver", log_path="/dev/null"
)
browser = webdriver.Firefox(service=service, options=options)
browser.get("http://challenge.localhost/preview")

preview = browser.find_element(By.ID, "preview")
assert preview.get_attribute("textContent") == payload
assert not preview.find_elements(By.TAG_NAME, "strong")
finally:
if browser is not None:
browser.quit()
server.terminate()
server.wait()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Every ordinary JavaScript object inherits properties from `Object.prototype` unless the application deliberately chooses otherwise.
An unsafe recursive merge can follow special keys into that shared prototype, making an attacker-controlled value appear on unrelated objects later in the page.
When one of those inherited values reaches an HTML sink, prototype pollution becomes DOM XSS.
Turn the unsafe merge into code execution in the administrator's origin and exfiltrate the protected data.
Run `/challenge/server`, save your JSON, start your listener, and run `/challenge/victim`.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import json
import subprocess
import time

import requests


server = subprocess.Popen(["/challenge/server"])
try:
for _ in range(100):
try:
requests.get("http://challenge.localhost/", timeout=1).raise_for_status()
break
except requests.RequestException:
time.sleep(0.1)
else:
raise AssertionError("server did not become ready in time")

preferences = {"theme": {"color": "blue"}}
requests.post(
"http://challenge.localhost/payload",
data={"payload": json.dumps(preferences)},
).raise_for_status()
response = requests.get("http://challenge.localhost/preferences")
response.raise_for_status()
assert response.json() == preferences
assert requests.get("http://challenge.localhost/admin/secret").status_code == 403
finally:
server.terminate()
server.wait()
Loading