Skip to content

Commit

Permalink
feat: adds dotenv file support
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmeese7 committed Feb 9, 2023
1 parent 74502c9 commit 297733c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CENSYS_API_ID=
CENSYS_API_SECRET=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
.env
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,33 @@ $ python censys-subdomain-finder.py github.com
1) Register an account (free) on https://censys.io/register
2) Browse to https://censys.io/account, and set two environment variables with your API ID and API secret:

```shell
export CENSYS_API_ID=...
export CENSYS_API_SECRET=...
```
```shell
export CENSYS_API_ID=...
export CENSYS_API_SECRET=...
```

Alternatively, you can use a `.env` file to store these values for persistence across uses:

```shell
cp .env.template .env
```

Then edit the `.env` file and set the values for `CENSYS_API_ID` and `CENSYS_API_SECRET`.

3) Clone the repository:

```shell
git clone https://github.com/christophetd/censys-subdomain-finder.git
```
```shell
git clone https://github.com/christophetd/censys-subdomain-finder.git
```

4) Install the dependencies in a virtualenv:

```shell
cd censys-subdomain-finder
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
```shell
cd censys-subdomain-finder
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

## Usage

Expand Down
9 changes: 6 additions & 3 deletions censys-subdomain-finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from censys.search import CensysCertificates
import censys
from dotenv import load_dotenv
import sys
import cli
import os
import time

load_dotenv()

NON_COMMERCIAL_API_LIMIT = 1000

# Finds subdomains of a domain using Censys API
Expand All @@ -23,7 +26,7 @@ def find_subdomains(domain, api_id, api_secret, limit_results):
subdomains = []
for search_result in certificates_search_results:
subdomains.extend(search_result['parsed.names'])

return set(subdomains)
except censys.common.exceptions.CensysUnauthorizedException:
sys.stderr.write('[-] Your Censys credentials look invalid.\n')
Expand All @@ -49,7 +52,7 @@ def print_subdomains(domain, subdomains, time_ellapsed):
print('[*] Found %d unique subdomain%s of %s in ~%s seconds\n' % (len(subdomains), 's' if len(subdomains) > 1 else '', domain, str(time_ellapsed)))
for subdomain in subdomains:
print(' - ' + subdomain)

print('')

# Saves the list of found subdomains to an output file
Expand Down Expand Up @@ -97,5 +100,5 @@ def main(domain, output_file, censys_api_id, censys_api_secret, limit_results):
if None in [ censys_api_id, censys_api_secret ]:
sys.stderr.write('[!] Please set your Censys API ID and secret from your environment (CENSYS_API_ID and CENSYS_API_SECRET) or from the command line.\n')
exit(1)

main(args.domain, args.output_file, censys_api_id, censys_api_secret, limit_results)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
censys==2.1.2
python-dotenv

0 comments on commit 297733c

Please sign in to comment.