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

Adds output flag #1

Open
wants to merge 3 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
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# crtsh.py
A Python utility to fetch or would say scrap subdomains from https://crt.sh

### Requirements
```
argparse
requests
json
```
A Python utility to scrape subdomains from https://crt.sh.

### Installation
```
```shell
git clone https://github.com/YashGoti/crtsh.py.git
cd crtsh.py
python3 crtsh.py -h
```
* if you want to use crtsh from anywhere try below installation guide
```

If you want to use crtsh from anywhere:

```shell
git clone https://github.com/YashGoti/crtsh.py.git
cd crtsh.py
mv crtsh.py crtsh
Expand All @@ -26,15 +21,17 @@ cp crtsh /usr/bin/
### Options
|Flags||Description|
|-|-|-|
|-h|--help|show this help message and exit|
|-d DOMAIN|--domain DOMAIN|Specify Target Domain to get subdomains from crt.sh|
|-h|--help|Show this help message and exit|
|-d DOMAIN|--domain DOMAIN|Specify target domain to get subdomains from crt.sh|
|-o FILENAME|--output FILENAME|Specify file to direct output to|
|-r|--recursive|Do recursive search for subdomains|
|-w|--wildcard|Include wildcard in output|

### Usage
```
```shell
python3 crtsh.py -d example.com
python3 crtsh.py -d example.com -w
python3 crtsh.py -d example.com -r
python3 crtsh.py -d example.com -r -w
python3 crtsh.py -d example.com -r -w -o output.txt
```
39 changes: 26 additions & 13 deletions crtsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ def parser_error(errmsg):
print("Error: " + errmsg)
sys.exit()

def parse_args():
parser = argparse.ArgumentParser(epilog='\tExample: \r\npython3 ' + sys.argv[0] + " -d google.com")
def parse_args():
parser = argparse.ArgumentParser(epilog="\tExample: \r\npython3 " + sys.argv[0] + " -d google.com")
parser.error = parser_error
parser._optionals.title = "OPTIONS"
parser.add_argument('-d', '--domain', help='Specify Target Domain to get subdomains from crt.sh', required=True)
parser.add_argument('-r', '--recursive', help='Do recursive search for subdomains', action='store_true', required=False)
parser.add_argument('-w', '--wildcard', help='Include wildcard in output', action='store_true', required=False)
parser.add_argument("-d", "--domain", help="Specify Target Domain to get subdomains from crt.sh", required=True)
parser.add_argument("-o", "--output", help="Direct output to a file instead of stdout", required=False)
parser.add_argument("-r", "--recursive", help="Do recursive search for subdomains", action="store_true", required=False)
parser.add_argument("-w", "--wildcard", help="Include wildcard in output", action="store_true", required=False)
return parser.parse_args()

def crtsh(domain):
try:
response = requests.get(BASE_URL.format(domain), timeout=25)
if response.ok:
content = response.content.decode('UTF-8')
content = response.content.decode("UTF-8")
jsondata = json.loads(content)
for i in range(len(jsondata)):
name_value = jsondata[i]['name_value']
if name_value.find('\n'):
subname_value = name_value.split('\n')
name_value = jsondata[i]["name_value"]
if name_value.find("\n"):
subname_value = name_value.split("\n")
for subname_value in subname_value:
if subname_value.find('*'):
if subname_value.find("*"):
if subname_value not in subdomains:
subdomains.add(subname_value)
else:
Expand All @@ -42,15 +43,27 @@ def crtsh(domain):
if __name__ == "__main__":
args = parse_args()
crtsh(args.domain)

# Direct the output to a file or stdout
def output(subdomain):
if args.output:
# Create the output file if specified
file = open(args.output, "w")
file.close()
with open(args.output, "a") as f:
f.write(subdomain + "\n")
else:
print(subdomain)

if args.domain:
for subdomain in subdomains:
print(subdomain)
output(subdomain)

if args.recursive:
for wildcardsubdomain in wildcardsubdomains.copy():
wildcardsubdomain = wildcardsubdomain.replace('*.', '%25.')
wildcardsubdomain = wildcardsubdomain.replace("*.", "%25.")
crtsh(wildcardsubdomain)

if args.wildcard:
for wildcardsubdomain in wildcardsubdomains:
print(wildcardsubdomain)
output(wildcardsubdomain)
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
argparse
requests
json