diff --git a/challenges/web-security/.gitattributes b/challenges/web-security/.gitattributes index f4f1e9a76..6a7eea061 100644 --- a/challenges/web-security/.gitattributes +++ b/challenges/web-security/.gitattributes @@ -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 diff --git a/challenges/web-security/common/dockerfile.selenium.j2 b/challenges/web-security/common/dockerfile.selenium.j2 index 7fbdfc4f8..6296dee67 100644 --- a/challenges/web-security/common/dockerfile.selenium.j2 +++ b/challenges/web-security/common/dockerfile.selenium.j2 @@ -2,13 +2,19 @@ {% block additional_packages %}{% endblock %} {% block before_copy %} RUN < /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 %} diff --git a/challenges/web-security/common/init.j2 b/challenges/web-security/common/init.j2 index 5fac6234c..56ebc0c63 100644 --- a/challenges/web-security/common/init.j2 +++ b/challenges/web-security/common/init.j2 @@ -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 diff --git a/challenges/web-security/common/xss-advanced.py.j2 b/challenges/web-security/common/xss-advanced.py.j2 new file mode 100644 index 000000000..392be9eb1 Binary files /dev/null and b/challenges/web-security/common/xss-advanced.py.j2 differ diff --git a/challenges/web-security/common/xss-browser.py.j2 b/challenges/web-security/common/xss-browser.py.j2 new file mode 100644 index 000000000..885cc9c20 Binary files /dev/null and b/challenges/web-security/common/xss-browser.py.j2 differ diff --git a/challenges/web-security/postmessage-origin-validation/DESCRIPTION.md b/challenges/web-security/postmessage-origin-validation/DESCRIPTION.md new file mode 100644 index 000000000..88e4f9887 --- /dev/null +++ b/challenges/web-security/postmessage-origin-validation/DESCRIPTION.md @@ -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`. diff --git a/challenges/web-security/postmessage-origin-validation/challenge/.init.j2 b/challenges/web-security/postmessage-origin-validation/challenge/.init.j2 new file mode 100755 index 000000000..eec9ae7b5 Binary files /dev/null and b/challenges/web-security/postmessage-origin-validation/challenge/.init.j2 differ diff --git a/challenges/web-security/postmessage-origin-validation/challenge/Dockerfile.j2 b/challenges/web-security/postmessage-origin-validation/challenge/Dockerfile.j2 new file mode 100644 index 000000000..cdfb5ec62 Binary files /dev/null and b/challenges/web-security/postmessage-origin-validation/challenge/Dockerfile.j2 differ diff --git a/challenges/web-security/postmessage-origin-validation/challenge/server.j2 b/challenges/web-security/postmessage-origin-validation/challenge/server.j2 new file mode 100755 index 000000000..ff76dabba Binary files /dev/null and b/challenges/web-security/postmessage-origin-validation/challenge/server.j2 differ diff --git a/challenges/web-security/postmessage-origin-validation/challenge/victim.j2 b/challenges/web-security/postmessage-origin-validation/challenge/victim.j2 new file mode 100755 index 000000000..dd6481c26 Binary files /dev/null and b/challenges/web-security/postmessage-origin-validation/challenge/victim.j2 differ diff --git a/challenges/web-security/postmessage-origin-validation/tests_private/test_solve.py b/challenges/web-security/postmessage-origin-validation/tests_private/test_solve.py new file mode 100755 index 000000000..1333bda1f Binary files /dev/null and b/challenges/web-security/postmessage-origin-validation/tests_private/test_solve.py differ diff --git a/challenges/web-security/postmessage-origin-validation/tests_public/test_service.py b/challenges/web-security/postmessage-origin-validation/tests_public/test_service.py new file mode 100755 index 000000000..7a7638057 --- /dev/null +++ b/challenges/web-security/postmessage-origin-validation/tests_public/test_service.py @@ -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 '