Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add switch to only output hosts that have a valid cert #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion ctfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
## # LIBRARIES # ##
import re
import requests
import datetime
from dateutil.parser import parse

## # CONTEXT VARIABLES # ##
version = 1.2
Expand All @@ -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()

Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down