Skip to content

Commit 960805d

Browse files
author
bharath
committed
Uploaded crtsh postgres script & Fixed censys script
1 parent 9f863d9 commit 960805d

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

crt_psql.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
# Script by Hanno Bock - https://github.com/hannob/tlshelpers/blob/master/getsubdomain
3+
4+
query="SELECT ci.NAME_VALUE NAME_VALUE FROM certificate_identity ci WHERE ci.NAME_TYPE = 'dNSName' AND lower(ci.NAME_VALUE) LIKE lower('%.$1');"
5+
6+
echo $query | \
7+
psql -t -h crt.sh -p 5432 -U guest certwatch | \
8+
sed -e 's:^ *::g' -e 's:^*\.::g' -e '/^$/d' | \
9+
sort -u | sed -e 's:*.::g'

subdomain_enum_censys.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
# 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.
44

55
from __future__ import print_function
66

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
137
import logging
148

159
logging.basicConfig(
1610
level=logging.INFO,
1711
format="%(message)s"
1812
)
1913

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+
2025
try:
2126
import censys.certificates
2227
except ImportError:
2328
logging.info("\033[1;31m[!] Failed to import censys module. Run 'pip install censys'\033[1;m")
2429
sys.exit()
2530

26-
CENSYS_API_ID = "" # Provide your Censys API ID
27-
CENSYS_API_SECRET = "" # Provide your Censys API Secret
28-
2931
def get_certificates(domain):
3032
if not CENSYS_API_ID or not CENSYS_API_SECRET:
3133
logging.info("\033[1;31m[!] API KEY or Secret for Censys not provided.\033[1;m" \
@@ -40,12 +42,12 @@ def get_certificates(domain):
4042
sys.exit()
4143
return certificates
4244

43-
def get_subdomains(certificates):
45+
def get_subdomains(domain, certificates):
4446
logging.info("[+] Extracting sub-domains for {} from certificates".format(domain))
4547
subdomains = []
4648
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])
4951
return subdomains
5052

5153
def print_subdomains(subdomains):
@@ -66,5 +68,5 @@ def get_domain():
6668
if __name__ == '__main__':
6769
domain = get_domain()
6870
certificates = get_certificates(domain)
69-
subdomains = get_subdomains(certificates)
71+
subdomains = get_subdomains(domain, certificates)
7072
print_subdomains(subdomains)

0 commit comments

Comments
 (0)