python字典破解

import urllib.request    #python3中已经没有了urllib2这个库 
import threading
import queue
import urllib

threads =50
target_url ="http://testphp.vulnweb.com"
wordlist_file="/tmp/all.txt"  #从SVNDigger读取txt文件
user_agent="Mozilla/5.0(xll;linux x86_64; rv:19.0) Gecko/20100101-Firefox/19.0"


def build_wordlist(wordlist_file):
    #读入字典文件
    fd=open(wordlist_file,"rb")
    raw_words=fd.readlines()
    fd.close()


    found_resume=False
    words   =  queue.Queue()


    for word in raw_words:



        word=word.rstrip()


        if resume is not None:


            if found_resume:
                words.put(word)
            else:
                if word==resume:
                    found_resume=True
                    print("Resuming wordlist from: %s" % resume)
        else:
            words.put(word)


    return words
def dir_bruter(word_queue,extensions=None):


    while not word_queue.empty():
        attempt =word_queue.get()



        attempt_list=[]


        #检查是否有文件扩展名,如果没有
        #就是我们要暴力破解的路径

        if "." not in attempt:
            attempt_list.append("/%s/" % attempt)
        else:
            attempt_list.append("/%s" %attempt)


        # 如果我们想更多扩展
        if extensions:
            for extension in extensions:
                attempt_list.appen("/%s%s" % (attempt,extension))


        #迭代我们要尝试的文件列表

        for brute in attempt_list:

            url="%s%s" %(target_url,urllib.quote(brute))


            try:
                headers={}
                headers["User-Agent"]=user_agent
                r=urllib.Request(url,headers=headers)



                response=urllib.urlopen(r)


                if len(response.read()):
                    print("[%d]=>%s" % (response.code,url))
            except urllib.error.URLError as e:


                if hasattr(e,'code') and e.code!=404:
                    print("!!! %d=> %s" %(e.code,url))


                pass
            word_queue=build_wordlist(wordlist_file)
            extensions=[".php",".bak",".org",".inc"]



            for i in range(threads):
                t=threading.Thread(target=dir_bruter,args=(word_queue,extensions,))
                t.start()




  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值