1
1
# A script to extract domain names from related SSL/TLS certificates using Censys
2
- # Requires Censys API ID and API Secret to be able to extract SSL/TLS certificates
3
- # Requires censys module. Run " pip install censys" to install .
2
+ # You'll need Censys API ID and API Secret to be able to extract SSL/TLS certificates
3
+ # Needs censys module to run. pip install censys.
4
4
5
5
from __future__ import print_function
6
6
7
- __author__ = "Bharath(github.com/yamakira)"
8
- __version__ = "0.1"
9
- __purpose__ = "Extract subdomains for a domain from censys certificate dataset"
10
-
11
- import re
12
- import sys
13
7
import logging
14
8
15
9
logging .basicConfig (
16
10
level = logging .INFO ,
17
11
format = "%(message)s"
18
12
)
19
13
14
+ __author__ = "Bharath(github.com/yamakira)"
15
+ __version__ = "0.1"
16
+ __purpose__ = "Extract subdomains for a domain from censys certificate dataset"
17
+
18
+ CENSYS_API_ID = ""
19
+ CENSYS_API_SECRET = ""
20
+
21
+ import argparse
22
+ import re
23
+ import sys
24
+
20
25
try :
21
26
import censys .certificates
22
27
except ImportError :
23
28
logging .info ("\033 [1;31m[!] Failed to import censys module. Run 'pip install censys'\033 [1;m" )
24
29
sys .exit ()
25
30
26
- CENSYS_API_ID = "" # Provide your Censys API ID
27
- CENSYS_API_SECRET = "" # Provide your Censys API Secret
28
-
29
31
def get_certificates (domain ):
30
32
if not CENSYS_API_ID or not CENSYS_API_SECRET :
31
33
logging .info ("\033 [1;31m[!] API KEY or Secret for Censys not provided.\033 [1;m" \
@@ -40,12 +42,12 @@ def get_certificates(domain):
40
42
sys .exit ()
41
43
return certificates
42
44
43
- def get_subdomains (certificates ):
45
+ def get_subdomains (domain , certificates ):
44
46
logging .info ("[+] Extracting sub-domains for {} from certificates" .format (domain ))
45
47
subdomains = []
46
48
for certificate in certificates :
47
- parsed_result = re .findall (r'(?<=CN=).*?(?=,) ' , certificate [u'parsed.subject_dn' ])
48
- if len (parsed_result ) > 0 : subdomains .append (parsed_result [0 ])
49
+ parsed_result = re .findall (r'(?<=CN=).*' , certificate [u'parsed.subject_dn' ])
50
+ if len (parsed_result ) > 0 and domain in parsed_result [ 0 ] : subdomains .append (parsed_result [0 ])
49
51
return subdomains
50
52
51
53
def print_subdomains (subdomains ):
@@ -66,5 +68,5 @@ def get_domain():
66
68
if __name__ == '__main__' :
67
69
domain = get_domain ()
68
70
certificates = get_certificates (domain )
69
- subdomains = get_subdomains (certificates )
71
+ subdomains = get_subdomains (domain , certificates )
70
72
print_subdomains (subdomains )
0 commit comments