-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsubs_cert.py
59 lines (52 loc) · 1.33 KB
/
subs_cert.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
import sys,time
from socket import socket
import ssl,masscan
import M2Crypto
import OpenSSL,xml,threading
vers = sys.version[0]
if vers == "2":
import Queue as queue
else:
import queue as queue
q = queue.Queue()
final_res = []
try:
ip_range = sys.argv[1]
except:
print('Usage: python subs_cert.py <IPRANGE>')
subs_ssl = []
try:
mas = masscan.PortScanner()
mas.scan(ip_range,ports='443')
for host in mas.all_hosts:
subs_ssl.append(host)
except (xml.etree.ElementTree.ParseError,masscan.masscan.NetworkConnectionError) as e:
print('Probably iprange\'s is not valid/down')
pass
def process_cert_subs(i):
try:
cert = ssl.get_server_certificate((str(i), 443))
x509 = M2Crypto.X509.load_cert_string(cert)
cert_val = x509.get_subject().as_text()
cnames = cert_val.split('CN=')[1]
if len(cnames) > 0:
print(cnames)
except SSLEOFError as e:
pass
def process_queue():
while not q.empty():
current_ip = q.get()
process_cert_subs(current_ip)
q.task_done()
if len(subs_ssl) > 0:
for i in subs_ssl:
i = str(i)
i = i.strip('\n')
i = i.strip('\r')
q.put(i)
else:
print('Empty ips.. Exiting..')
sys.exit(1)
for i in range(100):
t = threading.Thread(target=process_queue)
t.start()