githubEdit

LFI

If you locate an LFI, first try to get RCE.

Log Poisoning

1) Locate a writable log file

Apache Server

/var/log/apache2/access.log

Nginx Server

/var/log/nginx/access.log

(Check the location of the access.log file in nginx)

/etc/nginx/nginx.conf 

2) Inject a payload

Inject a simple web shell payload into a request header (e.g., User-Agent or Referer) that the web server will log.

nc -nv IP 80

Payload:

GET /<?php system($_GET['cmd']); ?>

Curl one-liner

curl -A "<?= shell_exec('id'); ?>" http://example.com/vulnerable.php

3) Execute via LFI

Alternate poisoning method: SSH Log Poisoning

1) Locate the log file

2) Poison the auth.log file

Connect to SSH port via netcat

Inject payload

3) Run commands via your webshell now

RCE via Email

Using LFI, after enumerating users (e.g., /etc/passwd), you can attempt to execute PHP code through a mail server by embedding PHP in email data.

1. Connect to the mail server

2. Inject PHP payload into the email service

3. Perform user enumeration if unsure about the users

Path Traversal manual payloads

Simple traversal: start with

Try variants like :

or

Dot+slash permutations:

or

Try Double-encoding:

URL-encode twice if the app decodes input more than once (example: %252e%252e%252f = %2e%2e%2f).

LFI to RCE by calling your uploaded reverse shell

If you have write access on an FTP server, you can upload your reverse shell, then call it with LFI to catch it.

1) Upload your reverse shell in a writable FTP share

2) Using LFI, find the FTP configuration file to detect the share that your shell is uploaded.

Enumerate with ffuf

Read FTP configuration file

You might detect something like

3) Enjoy your shell

LFI an a WordPress application

If we detect a Wordpress application that has LFI vulnerability, we can extract the application's wp-config.php for credentials.

LFI for port knocking configuration file

Depending on the content of the file, use the knockd tool in Kali

Test if the sequence worked

Bonus: Wordlists

Normal fuzzing

Fuzz GET Parameters

Fuzz PHP Files

Fuzz Server Logs and Configs

Fuzz Webroot

fuzz for index.php use wordlist for Linux or wordlist for windows, or this general wordlist alternative; consider that depending on our LFI situation, we may need to add a few back directories (e.g. ../../../../), and then add our index.php afterwords.

Example:

LFI Wrappers

1) Base64 encode a file

Decode

2) ROT13 encoding

3) php://data

Encode PHP payload in base64

Reverse Shell via LFI

Inject a shell using /proc/self/environ. If the environment variables are writable, inject PHP code into the environment.

1. Send PHP payload

2. Access the file via LFI to trigger the reverse shell

Last updated