diff --git a/README.md b/README.md index 41731eb..19155ce 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ Parameters and examples of use. ### Parameters ``` --d --domain [target_domain] (required) --o --output [output_file] (optional) +-d --domain [target_domain] (required) +-o --output [output_file] (optional) +-v --validonly (optional) ``` ### Examples @@ -42,6 +43,10 @@ $ python3 ctfr.py -d starbucks.com ```bash $ python3 ctfr.py -d facebook.com -o /home/shei/subdomains_fb.txt ``` +```bash +$ python3 ctfr.py -d starbucks.com -v +``` + ### With Docker I think it's a little bit crazy to use Docker for running such a little python script, but if you want to do it anyway, you can download [this lightweight (97.8MB) Docker image](https://hub.docker.com/r/johnpaulada/ctfr/) made by John Paulada. diff --git a/ctfr.py b/ctfr.py index 36a2ea1..9a217a8 100644 --- a/ctfr.py +++ b/ctfr.py @@ -9,6 +9,8 @@ ## # LIBRARIES # ## import re import requests +import datetime +from dateutil.parser import parse ## # CONTEXT VARIABLES # ## version = 1.2 @@ -19,6 +21,7 @@ def parse_args(): import argparse parser = argparse.ArgumentParser() parser.add_argument('-d', '--domain', type=str, required=True, help="Target domain.") + parser.add_argument('-v', '--validonly', action='store_true', help="Only include valid certs.") parser.add_argument('-o', '--output', type=str, help="Output file.") return parser.parse_args() @@ -50,6 +53,7 @@ def main(): subdomains = [] target = clear_url(args.domain) + validonly = args.validonly output = args.output req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target)) @@ -59,7 +63,14 @@ def main(): exit(1) for (key,value) in enumerate(req.json()): - subdomains.append(value['name_value']) + not_before = parse(value['not_before']) + not_after = parse(value['not_after']) + now = datetime.datetime.now() + if validonly: + if (not_before < now < not_after): + subdomains.append(value['name_value']) + else: + subdomains.append(value['name_value']) print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target))