Skip to content

Commit

Permalink
Updated tenablesc agent to match agent_parameter_types variables
Browse files Browse the repository at this point in the history
also reformated to remove unnused code
  • Loading branch information
Dante Acosta committed Apr 26, 2024
1 parent c2db552 commit fc58ca9
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions faraday_agent_dispatcher/static/executors/official/tenablesc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import io
import sys
import zipfile as zp
from urllib.parse import urlparse
from tenable.sc import TenableSC
from faraday_plugins.plugins.repo.nessus.plugin import NessusPlugin
from faraday_agent_dispatcher.utils.url_utils import resolve_hostname


def log(msg):
Expand Down Expand Up @@ -38,44 +36,37 @@ def main():
host_tag = host_tag.split(",")

TENABLE_SCAN_ID = os.getenv("EXECUTOR_CONFIG_TENABLE_SCAN_ID")
TENABLE_SCAN_TARGETS = os.getenv("EXECUTOR_CONFIG_TENABLE_SCAN_TARGETS")
TENABLE_ACCESS_KEY = os.getenv("TENABLE_ACCESS_KEY")
TENABLE_SECRET_KEY = os.getenv("TENABLE_SECRET_KEY")
TENABLE_URL = os.getenv("TENABLE_URL")
TENABLE_HOST = os.getenv("TENABLE_HOST")

if not (TENABLE_ACCESS_KEY and TENABLE_SECRET_KEY):
log("TenableIo access_key and secret_key were not provided")
log("TenableSC access_key and secret_key were not provided")
exit(1)

if not TENABLE_URL:
log("Tenable Url not provided")
if not TENABLE_HOST:
log("TenableSC Host not provided")
exit(1)

targets = []
if TENABLE_SCAN_TARGETS:
for target in TENABLE_SCAN_TARGETS.split(","):
parse_target = urlparse(target)
if parse_target.netloc:
targets.append(resolve_hostname(parse_target.netloc))
else:
targets.append(resolve_hostname(target))
log(f"Targets ip {targets}")
if not TENABLE_SCAN_ID:
log("TenableSC Scan ID not provided")
exit(1)

tsc = TenableSC(host=TENABLE_URL, access_key=TENABLE_ACCESS_KEY, secret_key=TENABLE_SECRET_KEY)
tsc = TenableSC(host=TENABLE_HOST, access_key=TENABLE_ACCESS_KEY, secret_key=TENABLE_SECRET_KEY)

if TENABLE_SCAN_ID:
scan = search_scan_id(tsc, TENABLE_SCAN_ID)
report = tsc.scan_instances.export_scan(scan["id"])
with zp.ZipFile(io.BytesIO(report.read()), "r") as zip_ref:
with zip_ref.open(zip_ref.namelist()[0]) as file:
plugin = NessusPlugin(
ignore_info=ignore_info,
hostname_resolution=hostname_resolution,
host_tag=host_tag,
service_tag=service_tag,
vuln_tag=vuln_tag,
)
plugin.parseOutputString(file.read())
print(plugin.get_json())
scan = search_scan_id(tsc, TENABLE_SCAN_ID)
report = tsc.scan_instances.export_scan(scan["id"])
with zp.ZipFile(io.BytesIO(report.read()), "r") as zip_ref:
with zip_ref.open(zip_ref.namelist()[0]) as file:
plugin = NessusPlugin(
ignore_info=ignore_info,
hostname_resolution=hostname_resolution,
host_tag=host_tag,
service_tag=service_tag,
vuln_tag=vuln_tag,
)
plugin.parseOutputString(file.read())
print(plugin.get_json())


if __name__ == "__main__":
Expand Down

0 comments on commit fc58ca9

Please sign in to comment.