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

Diff for: ethical-hacking/bruteforce-ssh/bruteforce_ssh.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ def is_ssh_open(hostname, username, password):
2222
except socket.timeout:
2323
# this is when host is unreachable
2424
print(f"{RED}[!] Host: {hostname} is unreachable, timed out.{RESET}")
25-
return False
25+
returning = False
2626
except paramiko.AuthenticationException:
2727
print(f"[!] Invalid credentials for {username}:{password}")
28-
return False
28+
returning = False
2929
except paramiko.SSHException:
3030
print(f"{BLUE}[*] Quota exceeded, retrying with delay...{RESET}")
3131
# sleep for a minute
3232
time.sleep(60)
33-
return is_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-
return True
40+
return returning
3941

4042

4143
if __name__ == "__main__":

0 commit comments

Comments
 (0)