Challenge Info
Spoiler
Saturn corp just launched their new proxy service. According to them, they have made sure their proxy service contains no security issues as they have implemented decent security measures with up to date components.
Artifacts Provided
- Application source — Flask app (
app.py, templates,requirements.txt),Dockerfileandsupervisord.conf - Live web instance —
http://VICTIM-IP:PORT
Analysis
Reconnaissance
The site is a proxy: we submit a URL and the page behind it is shown in an iframe. app.py has two routes:
| |
/secret from itself. Two things stand out:- The URL is checked by
SafeURLand then fetched a second time by plainrequests.get(url), which validates nothing. - The pinned versions are current, so there is no known-CVE route:
| |
supervisord.conf runs python3 /app/app.py, so gunicorn is not used and Flask listens directly on the app.run port, 1337:
| |
gunicorn in requirements.txt suggests the app might be served on port 80, which would make a DNS rebinding service viable. supervisord.conf rules that out here: the app runs with app.run on 1337, and a URL without an explicit port can only reach 80.SafeURL Behaviour
Reading the library source (safeurl.py, version 1.3) shows three things that decide the approach.
1. setFollowLocationLimit(0) does not disable redirects. In execute(), a limit of 0 means unlimited, and every redirect target goes through validateUrl again:
| |
A server that redirects to 127.0.0.1 is therefore caught by SafeURL itself. A static redirect (a URL shortener or a redirect service) cannot work.
2. Ports. The default whitelist is ["80", "443", "8080"] (strings), and validatePort checks the integer parsed from the URL against it. A local test against SafeURL 1.3 rejected an explicit :8080 with InvalidPortException. The submitted URL must carry no port, and SafeURL’s redirect hops cannot target :1337 either.
3. Two independent fetches. SafeURL fetches the URL with pycurl, and requests.get(url) then fetches it again. The second fetch follows redirects without any validation. Their User-Agents differ, so a server can tell them apart.
Location redirect (SafeURL follows and validates every hop), DNS rebinding (the instance listens on 1337, and an explicit port is rejected), and the usual SSRF payload lists (the blacklist covers 127.0.0.0/8, 10/8, 172.16/12, 192.168/16, 169.254/16 and others).Exploitation
The plan: a server of ours answers SafeURL’s request with a plain 200 and answers the requests fetch with a redirect to the internal endpoint. The redirect has to include the port, http://127.0.0.1:1337/secret. That hop is not validated, because only requests follows it, and the request to /secret comes from the server itself, so remote_addr is 127.0.0.1.
We branch on the User-Agent header (pycurl sends PycURL/..., requests sends python-requests/...):
| |
Tested first against SafeURL 1.3 locally: the server received one PycURL/... request answered with 200 and one python-requests/... request answered with 302, and the redirect reached the internal service.
The target has to reach our server, so we expose it with a tunnel. The tunnel URL has no explicit port, so it passes SafeURL’s port check:
| |
Submitting the https://<id>.ngrok-free.app URL in the form returns the /secret page with the flag.
python -m http.server 80 behind it. curl http://panathinaikos.duckdns.org/ returned curl: (52) Empty reply from server, and http.server logged nothing, so the request never reached our server. Exposing a home connection needs a port forward on the router, and a tunnel is simpler.200, every later one redirected) instead of the User-Agent, which breaks if the instance retries or hits the server twice. And its redirect target is http://127.0.0.1/secret, because its app.py listens on port 80. Our instance’s app.py listens on 1337, so the redirect needed :1337.Spoiler

| |
Full Chain
- The app is a proxy.
app.pyshows/secretis only served to127.0.0.1, and the submitted URL is checked by SafeURL-Python 1.3 before a second, uncheckedrequests.get(url). - In SafeURL,
setFollowLocationLimit(0)means unlimited redirects and each hop is re-validated, so a static redirect to127.0.0.1is blocked. An explicit port in the URL is rejected too. - The two fetches are independent and have different User-Agents (
PycURL/...andpython-requests/...). - A Flask server of ours returns
200to the pycurl request and a302tohttp://127.0.0.1:1337/secretto thepython-requestsone, exposed through an ngrok tunnel (no explicit port). - Submitting the tunnel URL: SafeURL sees a harmless page, then
requestsfollows the redirect,/secretsees127.0.0.1, and the flag comes back in the iframe.
