Remote Code Execution (RCE)
https://gitlab.com/jobertabma/vulnerable-code/-/tree/master/rce?ref_type=heads
Step 1: Understand the Vulnerability
The provided code in
index.phpcontains a Remote Code Execution (RCE) vulnerability due to the use of theeval()function. Theeval()function executes a string of PHP code, which can be manipulated by an attacker if not properly sanitized.index.phpBreakdown

Step 2: Create and Run the Bash Script
1.Create the Bash Script: Create a file named rce.sh and add the provided Bash script to it.
- Explanation of the Script:
echo $1 > _tmp/strip: This line writes the first argument passed to the script into a file namedstripin the_tmpdirectory.php -S 127.0.0.1:8080 -t rce &starts a PHP built-in server at127.0.0.1:8080, serving thercedirectory in the background.open 'http://127.0.0.1:8080/?variable=empty; phpinfo()'opens the URLhttp://127.0.0.1:8080/?variable=empty; phpinfo().This URL exploits the vulnerability by setting
$_GET['variable']toempty; phpinfo().The
evalstatement inindex.phpwill then executeecho $empty; phpinfo();, resulting in the execution ofphpinfo()wait: This line waits for the background process (the PHP server) to finish
2.Make the Script Executable: Change the script's permissions to make it executable.
3. Run the script:

Expected Outcomes:
When you run the provided automation script, the expected outcome is that the PHP
phpinfo()function will be executed, and its output will be displayed in the web browser. Here is the step-by-step expected outcome

Last updated