LFI

Function

Read Content

Execute

Remote URL

PHP

include()/include_once()

require()/require_once()

file_get_contents()

fopen()/file()

NodeJS

fs.readFile()

fs.sendFile()

res.render()

Java

include

import

.NET

@Html.Partial()

@Html.RemotePartial()

Response.WriteFile()

include


Local File Inclusion

Basic LFI

Path Traversal

Filename Prefix

Note: This may not always work, as in this example a directory named lang_/ may not exist, so our relative path may not be correct.

Appended Extensions

Path Truncation

4096 chars

Null bytes

/etc/passwd%00

Second order Attacks

/profile/$username/avatar.png -> ../../../etc/passwd


Basic Bypasses

Non-recursive Path Traversal Filters

....// or ..././ or ..../ or ....////

Encoding

%2e%2e%2f

Approved Paths

./languages/../../../../etc/passwd


Automated Scanning

Fuzzing GET parameters

Using Wordlist

Fuzzing Server Files

Server Web Root

Server Logs/Configs

LFI Tools


Prevention

File Inclusion Prevention

case-match (whitelisting)

Preventing Directory Traversal

Web Server Configuration

allow_url_fopen and allow_url_include to Off.

use Docker or open_basedir = /var/www in php.ini

Disable PHP Expectarrow-up-right and mod_userdirarrow-up-right

WAF

Last updated