-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathsshCheck.py
55 lines (51 loc) · 2.12 KB
/
sshCheck.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
import paramiko
import sys
def sshcheck(hostname, port, username, password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(hostname, port, username, password, timeout=10)
print("[+] Valid: %s %s"%(username,password))
ssh.close();
except paramiko.AuthenticationException:
print("[!] Authentication failed")
except Exception:
print("[!] Connection Failed")
except paramiko.SSHException:
print("[!] Unable to establish SSH connection: %s"%(sshException))
def sshcheckfile(hostname, port, username, keyfile):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
key=paramiko.RSAKey.from_private_key_file(keyfile)
try:
ssh.connect(hostname, port, username, pkey=key, timeout=2)
print("[+] Valid: %s %s"%(username,keyfile))
ssh.close();
except paramiko.AuthenticationException:
print("[!] Authentication failed")
except Exception:
print("[!] Connection Failed")
except paramiko.SSHException:
print("[!] Unable to establish SSH connection: %s"%(sshException))
if __name__ == "__main__":
if len(sys.argv)!=6:
print('[!]Wrong parameter')
print('sshCheck')
print('Use to check the valid credential of SSH(Support password and privatekeyfile)')
print('Author:3gstudent')
print('Usage:')
print('%s <host> <port> <mode><user> <password>'%(sys.argv[0]))
print('<mode>:')
print('- plaintext')
print('- keyfile')
print('Eg.')
print('%s 192.168.1.1 22 plaintext root toor'%(sys.argv[0]))
print('%s 192.168.1.1 22 keyfile root id_rsa'%(sys.argv[0]))
sys.exit(0)
else:
if sys.argv[3] == 'plaintext':
sshcheck(sys.argv[1], int(sys.argv[2]), sys.argv[4], sys.argv[5])
elif sys.argv[3] == 'keyfile':
sshcheckfile(sys.argv[1], int(sys.argv[2]), sys.argv[4], sys.argv[5])
else:
print('[!]Wrong parameter')