Skip to content

Commit

Permalink
sshprank.py: fix high memory usage by removing futures dequeue, which we
Browse files Browse the repository at this point in the history
really don't need atm. fix for #9
  • Loading branch information
noptrix committed Jan 18, 2021
1 parent 079aa4e commit a538131
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions sshprank.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


__author__ = 'noptrix'
__version__ = '1.2.3'
__version__ = '1.3.0'
__copyright = 'santa clause'
__license__ = 'MIT'

Expand Down Expand Up @@ -445,16 +445,13 @@ def crack_login(host, port, username, password):

def run_threads(host, ports, val='single'):
global excluded
futures = deque()

excluded[host] = set()

with ThreadPoolExecutor(opts['sthreads']) as e:
for port in ports:
if port not in excluded[host]:
futures.append(e.submit(crack_login, host, port, opts['user'],
opts['pass']))
wait(futures, None, ALL_COMPLETED)
e.submit(crack_login, host, port, opts['user'], opts['pass'])

with ThreadPoolExecutor(opts['lthreads']) as exe:
if 'userlist' in opts:
Expand All @@ -466,34 +463,30 @@ def run_threads(host, ports, val='single'):

if 'userlist' in opts and 'passlist' in opts:
for u in uf:
pf = open(opts['passlist'], 'r', encoding='latin-1')
for p in pf:
futures.append(exe.submit(crack_login, host, port, u.rstrip(),
p.rstrip()))
exe.submit(crack_login, host, port, u.rstrip(), p.rstrip())

if 'userlist' in opts and 'passlist' not in opts:
for u in uf:
futures.append(exe.submit(crack_login, host, port, u.rstrip(),
opts['pass']))
exe.submit(crack_login, host, port, u.rstrip(), opts['pass'])

if 'passlist' in opts and 'userlist' not in opts:
for p in pf:
futures.append(exe.submit(crack_login, host, port, opts['user'],
p.rstrip()))
exe.submit(crack_login, host, port, opts['user'], p.rstrip())

if 'combolist' in opts:
for line in cf:
try:
l = line.split(':')
futures.append(exe.submit(crack_login, host, port, l[0].rstrip(),
l[1].rstrip()))
exe.submit(crack_login, host, port, l[0].rstrip(), l[1].rstrip())
except IndexError:
log('combo list format: <user>:<pass>', 'error')

if opts['exit']:
for x in as_completed(futures):
if x.result() == SUCCESS:
os._exit(SUCCESS)
# TODO
#if opts['exit']:
# for x in as_completed(futures):
# if x.result() == SUCCESS:
# os._exit(SUCCESS)

return

Expand Down

0 comments on commit a538131

Please sign in to comment.