Command-Injection
https://gitlab.com/jobertabma/vulnerable-code/-/tree/master/command-injection?ref_type=heads
Step 1: Understand the Vulnerability
The PHP script takes user input from the
hostGET parameter.It directly passes this input into the
shell_execfunction to execute a ping command without any input sanitization.

Step 2: Create and Run the Bash Script
Create the Bash Script: Create a file named
runcomand.shand add the provided Bash script to it.
Explanation of the Script:
echo $1 > _tmp/strip: This line is just an example of writing some input to a file, it doesn't affect the exploitation.php -S 127.0.0.1:8080 -t command-injection &: This starts a PHP built-in web server on127.0.0.1:8080, serving files from thecommand-injectiondirectory.open 'http://127.0.0.1:8080/?host=127.0.0.1; cat /etc/passwd': This opens the URL in a web browser, with thehostparameter set to127.0.0.1; cat /etc/passwd. This injects thecat /etc/passwdcommand after thepingcommand, exploiting the command injection vulnerability.wait: This waits for the background processes to finish.
2 . Make the Script Executable: Change the script's permissions to make it executable.
3. Run the script:

Manually Testing the Exploit:
You can also test the exploit manually by starting the PHP server and accessing the URL in your web browser.
run the PHP server:
Open your browser and go to:
By doing this, the cat /etc/passwd command will be executed, and the contents of the /etc/passwd file will be displayed on the webpage, demonstrating the command injection vulnerability.
Expected Outcomes:
The expected outcome of exploiting the command injection vulnerability in the provided PHP code is that the contents of the /etc/passwd file will be displayed in the web browser. The /etc/passwd file on Unix-like operating systems contains user account information.

The cat /etc/passwd command is executed on the server, and its output is sent back to the web browser. This confirms that the server is vulnerable to command injection and demonstrates the potential risk of allowing unsanitized user input to be passed directly to system commands.
Last updated