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 option to filter expired certificates #36

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Parameters and examples of use.
```
-d --domain [target_domain] (required)
-o --output [output_file] (optional)
-a --active (optional) List only unexpired certificates.
```

### Examples
Expand Down
85 changes: 46 additions & 39 deletions ctfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,78 @@

## # LIBRARIES # ##
import re

import requests

## # CONTEXT VARIABLES # ##
version = 1.2
version = 1.3


## # MAIN FUNCTIONS # ##

def parse_args():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--domain', type=str, required=True, help="Target domain.")
parser.add_argument('-o', '--output', type=str, help="Output file.")
return parser.parse_args()
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--domain', type=str, required=True, help="Target domain.")
parser.add_argument('-o', '--output', type=str, help="Output file.")
parser.add_argument('-a', '--active', action="store_true", default=False, help="Exclude expired certs")
return parser.parse_args()


def banner():
global version
b = '''
global version
b = '''
____ _____ _____ ____
/ ___|_ _| ___| _ \
| | | | | |_ | |_) |
| |___ | | | _| | _ <
\____| |_| |_| |_| \_\\
Version {v} - Hey don't miss AXFR!
Made by Sheila A. Berta (UnaPibaGeek)
'''.format(v=version)
print(b)

def clear_url(target):
return re.sub('.*www\.','',target,1).split('/')[0].strip()
'''.format(v=version)
print(b)

def save_subdomains(subdomain,output_file):
with open(output_file,"a") as f:
f.write(subdomain + '\n')
f.close()

def main():
banner()
args = parse_args()
def clear_url(target):
return re.sub(".*www\.", '', target, 1).split('/')[0].strip()

subdomains = []
target = clear_url(args.domain)
output = args.output

req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target))
def save_subdomains(subdomain, output_file):
subdomain = subdomain.replace("\\n", " | ")
with open(output_file, "a") as f:
f.write(subdomain + '\n')
f.close()

if req.status_code != 200:
print("[X] Information not available!")
exit(1)

for (key,value) in enumerate(req.json()):
subdomains.append(value['name_value'])
def main():
banner()
args = parse_args()
subdomains = []
targeted = target = clear_url(args.domain)
output = args.output
if args.active:
targeted = target + '&exclude=expired'

req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=targeted))


print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target))
if req.status_code != 200:
print("[X] Information not available!")
exit(1)
for (key, value) in enumerate(req.json()):
subdomains.append(value['name_value'].replace("\n", " | "))

subdomains = sorted(set(subdomains))
subdomains = sorted(set(subdomains))
qty = len(subdomains)
print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target))
print("\n[!] ---- {d} certs found ---- [!] \n".format(d=qty))

for subdomain in subdomains:
print("[-] {s}".format(s=subdomain))
if output is not None:
save_subdomains(subdomain,output)
for subdomain in subdomains:
print("[-] {s}".format(s=subdomain))
if output is not None:
save_subdomains(subdomain, output)

print("\n\n[!] Done. Have a nice day! ;).")
print("\n\n[!] Done. Have a nice day! ;).")


main()