|
4 | 4 | import re
|
5 | 5 | import paramiko, socket
|
6 | 6 | import optparse
|
| 7 | +from threading import Thread |
7 | 8 |
|
8 | 9 | desc = "Quick automated tool developed to find your Linux machine using your credentials. For finding machines on the same subnet, just run sherlock without any arguments. For finding machines on another subnet of the same network, use the '-e' for options."
|
9 | 10 |
|
| 11 | +found = None |
| 12 | + |
10 | 13 | def parseCmd():
|
11 | 14 | p = optparse.OptionParser(description=desc)
|
12 | 15 | p.add_option('-e', '--ext', dest='ext', default='', help='take external subnet ip if required')
|
@@ -49,30 +52,33 @@ def getInput(opts):
|
49 | 52 | ip = patt.findall(f)
|
50 | 53 | return [ip, username, password]
|
51 | 54 |
|
| 55 | +def worker(host, username, password): |
| 56 | + global found |
| 57 | + try: |
| 58 | + ssh = paramiko.SSHClient() |
| 59 | + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
| 60 | + print "Trying for " + host + " ...." |
| 61 | + ssh.connect(host, username = username, password = password) |
| 62 | + print "Connected for " + host |
| 63 | + found = host |
| 64 | + return True |
| 65 | + except (paramiko.ssh_exception.BadHostKeyException, paramiko.ssh_exception.AuthenticationException, |
| 66 | + paramiko.ssh_exception.SSHException, socket.error) as e: |
| 67 | + print e |
| 68 | + return False |
| 69 | + |
52 | 70 | def findMc(ip, username, password):
|
53 |
| - i = 1 |
54 |
| - while i < len(ip): |
55 |
| - ip_addr = ip[i] |
56 |
| - try: |
57 |
| - ssh = paramiko.SSHClient() |
58 |
| - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
59 |
| - print "Trying for " + ip_addr + '....' |
60 |
| - ssh.connect(ip_addr, username=username, password=password) |
61 |
| - print "Connected." |
62 |
| - break |
63 |
| - except (paramiko.ssh_exception.BadHostKeyException, paramiko.ssh_exception.AuthenticationException, |
64 |
| - paramiko.ssh_exception.SSHException, socket.error) as e: |
65 |
| - print e |
66 |
| - i+=1 |
67 |
| - continue |
68 |
| - print ip_addr + " done" |
69 |
| - if i >= len(ip): |
70 |
| - print "Desired machine is not found" |
71 |
| - return "" |
72 |
| - else: |
73 |
| - print "Your desired IP is " + ip[i] |
74 |
| - return ip[i] |
| 71 | + threads = [] |
| 72 | + for host in ip: |
| 73 | + t = Thread(target=worker, args = (host, username, password)) |
| 74 | + t.start() |
| 75 | + threads.append(t) |
| 76 | + |
| 77 | + for t in threads: |
| 78 | + t.join() |
75 | 79 |
|
| 80 | + if found is not None: |
| 81 | + print "The correct destination is " + found |
76 | 82 |
|
77 | 83 | if __name__ == '__main__':
|
78 | 84 | opts = parseCmd()
|
|
0 commit comments