-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_user.py
41 lines (39 loc) · 1.55 KB
/
find_user.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
import paramiko, base64
import time
import socket
import gssapi, pyasn1
import sys
import getpass
from socket import timeout, gaierror
from paramiko.ssh_exception import (
SSHException, BadHostKeyException, NoValidConnectionsError
)
target = ""
username = ""
password = ""
if len(sys.argv) == 3:
username = sys.argv[1]
target = sys.argv[2]
password = getpass.getpass('Password:')
elif len(sys.argv) > 3:
print("Too many arguments\n")
exit()
elif len(sys.argv) < 3:
print("Include a Sunet ID to search for")
exit()
for i in range(1, 33):
try:
key = paramiko.RSAKey(data=base64.decodestring('AAAAB3NzaC1yc2EAAAABIwAAAQEAzBGOI2HrympIZLVT1oETmeeVu5T9ZvyqOdIlIRqxKQp4wWo8vvCmNHCWTtzQiHic4ypoaduW0hayPPJcCE2a8k9Yt0iqm5UqePhebyRaIVH3wSKdESk4KX0BJX8f43xWk4KkUT/lOK0EGD3/tlEM/70T8vLbRyNprrGBedhHLpbMocv+2XbWCb2wQzTW7oy4x0fiBXDPK2iUDIAG0WMbG6LDCjljsJZPna8chW6voxzXMujhLS2fJY1puZ7ELbHM18NfXxAmNpVWR6smEc+VaSEOMdod63NJh6qYTZFamnjhGXGRWRzoaMT3V99Rl1/o9eMrCZdGWUBIBu6ImcL5Tw=='))
client = paramiko.SSHClient()
client.get_host_keys().add('myth%d.stanford.edu' % i, 'ssh-rsa', key)
client.connect('myth%d.stanford.edu' % i, timeout=.5, username=username, password=password)
except (NoValidConnectionsError, timeout, gaierror, SSHException):
continue
# print("Searching myth machine %d for %s" % (i, target))
stdin, stdout, stderr = client.exec_command('who')
for line in stdout:
if line.strip('\n').find("%s" % target) >= 0:
print("*Found %s on myth machine %d*" % (target, i))
# exit()
print '... ' + line.strip('\n') #prints all the users
client.close()