-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
68 lines (47 loc) · 2.3 KB
/
example.py
File metadata and controls
68 lines (47 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import click
import logging
import json
from datetime import datetime
from offensity_api_client import OffensityApiClient
log = logging.getLogger(__name__)
"""
Offensity API Python3 Script - Please note: currently only "GET"-requests are supported!
"""
def export_to_json(filename: str, data: list):
time_now = datetime.now()
timestamp = f"{time_now.year}{time_now.month}{time_now.day}_{time_now.hour}{time_now.minute}{time_now.second}"
filename += f"_{timestamp}.json"
with open(filename, "w") as outfile:
outfile.write(
json.dumps(data, sort_keys=True, indent=4)
)
log.info(f"Successfully exported to: {filename}")
@click.command()
@click.option("--token", required=True, type=str, help="Offensity API Token")
@click.option("--verbose", required=False, is_flag=True, help="Set the logging level to INFO")
def main(token, verbose):
logging.basicConfig(level=logging.INFO if verbose else logging.WARNING)
api_client = OffensityApiClient(token=token)
enabled_scanprofiles = api_client.scanprofiles_list(is_enabled=True)
amount_of_running_scans = len(list(api_client.report_list(status="started")))
log.info(f"Currently are {amount_of_running_scans} scan(s) in progress!")
for scanprofile in enabled_scanprofiles:
tld_domain = scanprofile.get("domain")
scanprofile_id = scanprofile.get("id")
all_reports_per_scanprofile_finished = api_client.report_list_for_scanprofile(scanprofile_id=scanprofile_id)
for report in all_reports_per_scanprofile_finished:
report_id = report.get("id")
issue_count = report.get("issue_count")
log.info(f"The report with ID: {report_id} ({tld_domain}) has {issue_count} issues!")
issues_per_report = api_client.issues(report_id=report_id)
for issue in issues_per_report:
log.info(f"\t\t*) {issue.get('data', dict()).get('title', '')}")
systems_with_open_port_21 = api_client.infrastructure_data(
report_id=report_id,
query="port:21"
)
log.info(f"The scanprofile >>{tld_domain}<< has {len(list(systems_with_open_port_21))} open port 21!")
# export as .json file
export_to_json(report_id, report)
if __name__ == "__main__":
main()