Skip to content

Plugins use all pentests tools #3

@ws-idontop

Description

@ws-idontop

from Config.Utils import *
from Program.NSAdvancedScanner import AdvancedScanner
from Program.NSUrlDiscoveryCrawler import UrlDiscoveryCrawler
from Program.NSVulnerabilityScanner import VulnerabilityScanner
from Program.NSPortScanner import PortScanner
from Program.NSHostDiscovery import HostDiscovery
from Program.Utils.NetworkScanningUtils import DetectTarget, TargetGetIp

import Config.Utils as ConfigUtils
import Program.NSAdvancedScanner as AdvancedScannerModule
import Program.NSUrlDiscoveryCrawler as UrlDiscoveryCrawlerModule
import Program.NSVulnerabilityScanner as VulnerabilityScannerModule
import Program.NSPortScanner as PortScannerModule
import Program.NSHostDiscovery as HostDiscoveryModule

class StepFinished(Exception):
pass

def Register():
return {
"name": "Full Pentest Analysis",
"description": "Run the main pentesting scanners in sequence for a complete authorized analysis.",
"function": Run,
"arguments": {
"target": {"required": True, "type": str, "help": "Authorized target: / / <IP[:port]>"},
"network-cidr": {"required": False, "type": str, "help": "Optional network discovery target: /"},
"url-mode": {"required": False, "type": str, "help": "URL crawler mode: onlypage / allwebsite", "default": "allwebsite", "choices": ["onlypage", "allwebsite"]},
"port-mode": {"required": False, "type": str, "help": "Port scan mode: default / all / single / multiple / range", "default": "default", "choices": ["default", "all", "single", "multiple", "range"]},
"port": {"required": False, "type": str, "help": "Port(s) for single/multiple/range mode: / <port,port> / "},
"protocol-scan": {"required": False, "type": str, "help": "Protocol scan: TCP / UDP / TCP,UDP", "default": "TCP", "choices": ["TCP", "UDP", "TCP,UDP"]},
"http-timeout": {"required": False, "type": float, "help": "HTTP timeout in seconds", "default": 5},
"socket-timeout": {"required": False, "type": float, "help": "Socket timeout in seconds", "default": 1},
"http-proxy": {"required": False, "type": str, "help": "HTTP proxy: proxy:port"},
"socket-proxy": {"required": False, "type": str, "help": "Socket proxy: proxy:port"},
"useragent": {"required": False, "type": str, "help": "User-Agent: random / "},
"cookie": {"required": False, "type": str, "help": "Cookie: "},
"skip-vuln": {"required": False, "action": "store_true", "help": "Skip vulnerability scanner."},
"skip-url": {"required": False, "action": "store_true", "help": "Skip URL discovery crawler."},
"skip-port-scan": {"required": False, "action": "store_true", "help": "Skip port scanner."},
"output": {"required": False, "action": "store_true", "help": "Create JSON output files."},
},
}

def _finish_without_reset():
raise StepFinished()

def _stats_without_keyboard(state, time_start=None):
while True:
if state.get("stop") is True:
break
if "completed" in state and "completed_total" in state:
if int(state["completed"]) >= int(state["completed_total"]):
break
time.sleep(0.1)

def _patch_navigation():
modules = [
ConfigUtils,
AdvancedScannerModule,
UrlDiscoveryCrawlerModule,
VulnerabilityScannerModule,
PortScannerModule,
HostDiscoveryModule,
]
originals = []
for module in modules:
originals.append((
module,
getattr(module, "Reset", None),
getattr(module, "Continue", None),
getattr(module, "has_cli_args", None),
getattr(module, "StatsPressed", None),
))
module.Reset = _finish_without_reset
module.Continue = lambda: None
module.has_cli_args = True
module.StatsPressed = _stats_without_keyboard
return originals

def _restore_navigation(originals):
for module, reset_func, continue_func, has_cli_args_value, stats_pressed_func in originals:
if reset_func:
module.Reset = reset_func
if continue_func:
module.Continue = continue_func
if has_cli_args_value is not None:
module.has_cli_args = has_cli_args_value
if stats_pressed_func:
module.StatsPressed = stats_pressed_func

def _run_step(name, function, **kwargs):
Info(f"Starting: {white}{name}")
try:
function(**kwargs)
except StepFinished:
Info(f"Finished: {white}{name}")
except SystemExit:
Info(f"Stopped: {white}{name}")
except KeyboardInterrupt:
raise
except Exception as error:
Error(f"{name} failed: {white}{error}")

def _resolve_ip(target):
try:
detect_target = DetectTarget(target)
ip, _, _ = TargetGetIp(target, detect_target, log=False)
return ip
except Exception:
return None

def _is_web_target(target):
return DetectTarget(target) in [
"url",
"url/page",
"domain",
"domain/page",
"localhost:port",
"localhost:port/page",
"ip:port",
"ip:port/page",
]

def Run(
target=None,
network_cidr=None,
url_mode=None,
port_mode=None,
port=None,
protocol_scan=None,
http_timeout=None,
socket_timeout=None,
http_proxy=None,
socket_proxy=None,
useragent=None,
cookie=None,
skip_vuln=None,
skip_url=None,
skip_port_scan=None,
output=None,
):
Title("Full Pentest Analysis")

if not target and has_cli_args:
    Error("Missing required argument: --target")
    sys.exit(1)
if not target:
    target = Input("Target -> ")
if not network_cidr and not has_cli_args:
    network_cidr = Input("CIDR discovery target (optional, press enter to skip) -> ")

Info("Run this plugin only on systems you own or are authorized to test.")

if not url_mode:
    url_mode = "allwebsite"
if not port_mode:
    port_mode = "default"
if not protocol_scan:
    protocol_scan = "TCP"

originals = _patch_navigation()
try:
    _run_step(
        "Advanced Scanner",
        AdvancedScanner,
        target=target,
        output=output,
        http_timeout=http_timeout,
        socket_timeout=socket_timeout,
        http_proxy=http_proxy,
        socket_proxy=socket_proxy,
        useragent=useragent,
        cookie=cookie,
    )

    if not skip_url and _is_web_target(target):
        _run_step(
            "URL Discovery Crawler",
            UrlDiscoveryCrawler,
            target=target,
            mode=url_mode,
            output=output,
            http_timeout=http_timeout,
            http_proxy=http_proxy,
            useragent=useragent,
            cookie=cookie,
        )
    elif not skip_url:
        Info("URL Discovery Crawler skipped: target is not a web target.")

    if not skip_vuln and _is_web_target(target):
        _run_step(
            "Vulnerability Scanner",
            VulnerabilityScanner,
            target=target,
            output=output,
            http_timeout=http_timeout,
            http_proxy=http_proxy,
            useragent=useragent,
            cookie=cookie,
        )
    elif not skip_vuln:
        Info("Vulnerability Scanner skipped: target is not a web target.")

    if not skip_port_scan:
        ip = _resolve_ip(target)
        if ip:
            _run_step(
                "Port Scanner",
                PortScanner,
                target=ip,
                mode=port_mode,
                protocol_scan=protocol_scan,
                port=port,
                output=output,
                socket_timeout=socket_timeout,
                socket_proxy=socket_proxy,
            )
        else:
            Info("Port Scanner skipped: could not resolve target IP.")

    if network_cidr:
        _run_step(
            "Host Discovery",
            HostDiscovery,
            target=network_cidr,
            output=output,
            port=port,
            tcp_icmp_timeout=socket_timeout,
            socket_proxy=socket_proxy,
        )
finally:
    _restore_navigation(originals)

Info("Full pentest analysis completed.")
Continue()
Reset()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions