Skip to content

Commit b4c0f40

Browse files
committed
Add SD-WAN Harvester files
1 parent defa827 commit b4c0f40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2427
-1
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.env
2+
results
3+
harvester/.env
4+
harvester/results
5+
harvester/__pycache__

LICENSE

+339
Large diffs are not rendered by default.

README.md

+88-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,91 @@
11
# SD-WAN Harvester
22

33
`SD-WAN Harvester` tool was created to automatically enumerate and fingerprint SD-WAN nodes on the Internet.
4-
It uses Shodan as a search engine and another custom tools like NMAP NSE scripts, masscan checks, etc.
4+
It uses Shodan search engine for discovering, NMAP NSE scripts for fingerprinting, and masscan to implement some specific checks.
5+
6+
## Requirements
7+
`SD-WAN Harvester` requires [Python 3.6](https://www.python.org/getit/) or later and [Nmap](https://nmap.org/download.html).
8+
9+
You also need an Shodan API key.
10+
11+
## Installation
12+
1. Clone the repository:
13+
```
14+
git clone https://github.com/sdnewhop/sdwan-harvester.git
15+
```
16+
2. Install `pip` requirements:
17+
```
18+
python3.6 -m pip install -r requirements.txt
19+
```
20+
3. Run the script:
21+
```
22+
python3.6 harvester.py -h
23+
```
24+
4. Set your Shodan key via a command line argument
25+
```
26+
./harvester.py -sk YOUR_SHODAN_KEY
27+
```
28+
or via an environment variable
29+
```
30+
export SHODAN_API_KEY=YOUR_API_KEY_HERE
31+
./harvester.py (without -sk key)
32+
```
33+
34+
## Usage
35+
### Command Line Arguments
36+
1. `-h, --help` - show the help message and exit.
37+
38+
2. `-sk SHODAN_KEY, --shodan-key SHODAN_KEY` - set a Shodan API key.
39+
40+
3. `-n, --new` - initiate a new discovery using Shodan.
41+
42+
4. `-q QUERIES, --queries QUERIES` - specify the file containing SD-WAN queries and filters for Shodan.
43+
*Default value is `shodan_queries.json`.*
44+
45+
5. `-d DESTINATION, --destination DESTINATION` - the directory where results will be stored.
46+
*Default value is `results`.*
47+
48+
6. `-C CONFIDENCE, --confidence CONFIDENCE` - set the confidence level (`certain`, `firm`, or `tentative`).
49+
*Default value is `certain`.*
50+
51+
7. `-v [VULNERS [VULNERS ...]], --vulners [VULNERS [VULNERS ...]]` - the list of venodrs checked by Shodan vulnerability scanner. For example, `--- vulners silver peak, arista, talari` command starts finding of known vulnerabilities for `silver peak`, `arista` and `talari` products. Use `--vulners all` to run scanning for all vendors.
52+
*By default, Shodan vulnerability scanning is turned off.*
53+
54+
8. `-mv MAX_VENDORS, --max-vendors MAX_VENDORS` - the Maximum Number of Vendors shown in reports.
55+
*Default value is `10`.*
56+
57+
9. `-mc MAX_COUNTRIES, --max-countries MAX_COUNTRIES` - the Maximum Number of Countries shown in reports.
58+
*Default value is `10`.*
59+
60+
10. `-maxv MAX_VULNERS, --max-vulners MAX_VULNERS` - the Maximum Number of Vulnerabilities shown in reports.
61+
*Default value is `10`.*
62+
63+
### Examples
64+
Show help
65+
```
66+
python3.6 harvester.py -h
67+
```
68+
Run an enumeration
69+
```
70+
python3.6 harvester.py -sk YOUR_API_KEY -n
71+
```
72+
Run an enumeration with `firm` level of confidence
73+
```
74+
python3.6 harvester.py -sk YOUR_API_KEY -n -c firm
75+
```
76+
Run a vulnerability scan against `talari` vendor
77+
```
78+
python3.6 harvester.py -sk YOUR_API_KEY -n -v talari
79+
```
80+
Run a new vulnerability scan for all vendors. The Maximum Number of Vendors is 8, the Maximum Number of Countries is 8, and the Maximum Number of CVEs is 8
81+
```
82+
python3.6 harvester.py -sk YOUR_API_KEY -n -v all -mv 8 -mc 8 -maxv 8
83+
```
84+
Run a new scan with all features enabled
85+
```
86+
python3.6harvester.py -sk YOUR_API_KEY -n -v all -c all
87+
```
88+
Process data from previous scan results (for example, if you want to build new charts and graphics containing fewer vendors, countries, or vulners.)
89+
```
90+
python3.6 harvester.py -v -mv <num> -mc <num> -maxv <num>
91+
```

harvester.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
import sys
6+
7+
import harvester.core as core
8+
9+
# Default input file with queries
10+
core.QUERIES_JSON_FILE = "shodan_queries.json"
11+
12+
# Default confidence level
13+
core.DEFAULT_CONFIDENCE = "certain"
14+
15+
# Default quantity of results
16+
core.MAX_COUNTRIES = 10
17+
core.MAX_VENDORS = 10
18+
core.MAX_VULNERS = 10
19+
20+
# Default paths and directories
21+
core.NMAP_SCRIPTS_PATH = "nse-scripts"
22+
core.RESULTS_DIR = "results"
23+
24+
25+
def get_key_from_env():
26+
"""
27+
Get Shodan API Key from environment variable
28+
29+
:return: Shodan API key from env variable (str)
30+
"""
31+
try:
32+
shodan_api_key = os.environ['SHODAN_API_KEY']
33+
return shodan_api_key
34+
except KeyError:
35+
print(
36+
'Please set the environment variable SHODAN_API_KEY or use -sk key')
37+
sys.exit(1)
38+
39+
40+
def main():
41+
"""
42+
Main interface for harvester core
43+
44+
:return: None
45+
"""
46+
if sys.version_info < (3, 6):
47+
print('Required python version is 3.6 or greater')
48+
sys.exit(1)
49+
50+
if len(sys.argv) == 1:
51+
print(
52+
"Usage: '{script_name} -h' for help".format(
53+
script_name=sys.argv[0]))
54+
sys.exit(1)
55+
56+
parser = argparse.ArgumentParser(description=".")
57+
parser.add_argument("-sk", "--shodan-key", action="store",
58+
default=None, help="Shodan API key")
59+
parser.add_argument("-n", "--new", action="store_true",
60+
help="New scan in shodan")
61+
parser.add_argument("-q", "--queries", action="store",
62+
default=core.QUERIES_JSON_FILE,
63+
help="File with queries")
64+
parser.add_argument("-d", "--destination", action="store",
65+
default=core.RESULTS_DIR, help="Destination directory")
66+
parser.add_argument("-c", "--confidence", default=core.DEFAULT_CONFIDENCE,
67+
action="store", help="""Confidence level. Available
68+
levels: certain, firm,
69+
tentative""")
70+
parser.add_argument("-v", "--vulners", action="store", nargs='*',
71+
help="""List of vendors for vulners scan, e.g.,
72+
'--vulners silver peak, arista, talari'.
73+
Use '--vulners all' to include all vendors
74+
in statistics.""")
75+
parser.add_argument("-mv", "--max-vendors", default=core.MAX_VENDORS, type=int,
76+
action="store",
77+
help="Max number of vendors in statistics")
78+
parser.add_argument("-mc", "--max-countries", default=core.MAX_COUNTRIES,
79+
type=int,
80+
action="store",
81+
help="Max number of countries in statistics")
82+
parser.add_argument("-maxv", "--max-vulners", default=core.MAX_VULNERS,
83+
type=int, action="store",
84+
help="Max number of vulners in statistics")
85+
args = parser.parse_args()
86+
87+
# Try to get key from environment if it was not passed with CLI
88+
if not args.shodan_key and args.new is True:
89+
args.shodan_key = get_key_from_env()
90+
91+
# Check confidence level
92+
if args.confidence.lower() not in ['certain', 'firm', 'tentative']:
93+
print('Wrong confidence level. Use -h key for help.')
94+
sys.exit(1)
95+
96+
# Run harvester
97+
core.run(args)
98+
99+
100+
if __name__ == '__main__':
101+
main()

harvester/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)