What's a Local File transfer sion?
A local file transfer Sion (usually called "LFI") is a webhacking technique that allow simply to include files from a local location. that means that we can include a file that is outside of the web directory (if we got rights), and execute PHP code.
<? Php include ($ _ GET ['page']);?>
This code will search for the variable GET "Page", include and execute the page specified by that GET variable. if you wan't an example, you 've surely already seen an website with something like "index. php? Page = news. php "that's it, that's in a lot of case, an include. to start include file locally, we'll use ".. /"that allow us to go to an directory upper than the actual one. we'll try to include the file/etc/passwd, well, it's not always readable but it's a good start. we'll use "... /"to go to the root, then load/etc/passwd.
A http://www.bkjia.com/index. php? Page =.../../passwd
I personally prefer using "./" before the page name to verify if there's an exploitable local file transfer Sion (example: index. php? Page = news. php> index. php? Page =./news. php if it works, mostly there's an LFI) but it won't always work. Note that/etc/password will only works on Linux system.
The null byte technique.
In most cases, the webmaster will not do an include like that, he'll prefer add himself ". php "at the end of the transition. (Well, we can say that index. php? P = news is prettier than index. php? P = news. php) He'll use a code like that:
<? Php include ($ _ GET ['page']. ". php");?>
So, this time, the php will include again a page with the GET variable page, but it'll add. php at the end. To bypass this restriction, we'll useNull byte.The principe of the null byte is that it is an line terminator char. it means that everything after the null byte will be deleted. to use it, you'll have to got a website with magic quotes off. the character urlencoded is "% 00" (the browser will automatically translate it) so, for example, this time we'll gotta use that:
Http://sitelambda.com/index.php? Page =.../../etc/passwd % 00
It'll include/etc/passwd perfectly. The. php will be deleted by the null byte.
And now that I got a LFI, what should I do?
I actually know only 4 LFI exploitation technique, there they are:
The access. log
The principe is simple, we'll include the log file that logs all the web connections to the server. in our case, it'll be the access. log, but it can also be access_log, or any name in fact. (You'll gotta see the apache/httpd configuration to know what's the logfile name ).
Http://www.bkjia.com/<? Phpinfo ();?>
By the way, I think that the useragent is not urlencoded, so you can modify it and try with that.
The/proc/self/environ
You'll gotta do something like that, then the server will log it inside the access_log, and when you'll include it, the code will be executed. note that your browser automatically urlencode your special chars, so you'll have to go to that url with a script that won't auto-urlencode. if you go with your browser, it'll be something like: "% 3C? Phpinfo ();? % 3E ".
It's my favorite one. try to include/proc/self/environ, you will see a list of actual processus variable. (Well, if you got rights to include that file, that's not often the case) you'll see something like that if you're on Mozilla:
HTTP_USER_AGENT = Mozilla/5.0
Why it is interessant? Because you'll be able to change your useragent to suit the php code you want. How? Go to "about: config" (type it in your Firefox Browser), create a new line, string, with these datas: "general. useragent. override "for the name, and" <? Phpinfo () ;?>" For the value. (Note that there's some tool that do it automatically, like useragent switcher). Reload the page, and you'll see an phpinfo instead of "Mozilla/5.0 ″
The PHP Sessions Exploitation.
Another exploitation is the sessions exploitation. if your site got php sessions (phpsessid, etc ..) you'll be able to include them and if you can modify the datas, it'll be easy to execute code. you'll gotta include sess _ [your phpsessid value]. most of time, it is in/tmp, but you'll be able to find it sometimes in/var/lib/php5/also, etc .. the data stored in phpsessid shoshould be everything (like a name at a register, an option you choose ).
Index. php? P =.../tmp/sess_tnrdo9ub2tsdurntv0pdir1no7% 00
I suggest you to surf a little before trying to include the phpsessid, touch at everything, modify options, etc ..
The upload
We don't often heard of it, but it's the easiest technique. just upload a file that contain php code, include it. example: There's an forum on the site you're actually trying LFIs, upload an avatar with modified code that contain php (hexedit it, and modify only at the center of the datas, so the forum will still recognize it as an image ). found the right path, and include your avatar, tadaa, your code is executed.
Read a file with LFI
There's a technique that will allow us to "read" a file with a LFI. (Interessant file to check shocould be config. php file, that normally, will only be executed, not shown ). we'll use PHP Filters to help us do it:
Index. php? Page = php: // filter/read = convert. base64-encode/resource = config
This code will base64 the resource "config" (like if it was index. php? Page = config, but with base64'd) with that, your code won't be executed, and you'll can base64_decode () it after to take the original config. php file. this method won't need magic quotes but you'll need to have a PHP Version higher or egal to PHP5.
Special cases
Sometimes, even if you can read the/etc/passwd, it is not an include. for example, when they'll use readfile () in php, it'll load the file, but php code won't be executed. it's a problem to execute php code, but well, it'll give you an advantage on one point, you'll be able to read configs file.
Index. php? Page =./forum/config
Then show the source of the page (CTRL + U) to have the code.
The "Does a folder exist" trick.
If you got a LFI, a good technique to know if a folder exist is simply to enter, then go out of it. Example:
Index. php? Page = .. /.. /.. /.. /.. /.. /var/www/dossierexistant /.. /.. /.. /.. /.. /etc/passwd % 00
How to protect from LFIs?
Well, first, activate magic quotes, it's not the "perfect solution", but it'll help. then you shoshould also activate open_basedir to only read into your web folder and/tmp, you shoshould also do a function that parse the "/", ". "and" % 00 "char.
But well, the best option is the non dynamic include.
If ($ _ GET ['page'] = "news") {include ("news. php");} else {include ("accueil. php ");}
From http://hi.baidu.com/evilrapper/blog/item/3395b4f4c47827f17709d749.html