Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

Feature: validate targets before executing modules (-C)

Open Aarush289 opened this issue 1 year ago โ€ข 3 comments

Proposed change

This PR adds an optional target validation step before running any scans. When -C (or --validate-before-scan) is used, Nettacker resolves each target first and filters out invalid or unreachable ones.

This improves performance and reduces unnecessary resource usage by skipping modules for targets that cannot be resolved. If -C is not used, behavior remains unchanged and all targets are scanned as before.

No breaking changes.

Type of change

  • [x] New core framework functionality

Checklist


Aarush289 avatar Oct 30 '25 14:10 Aarush289

Summary by CodeRabbit

  • New Features
    • Added pre-scan target validation to automatically skip unreachable targets before scanning.
    • New --validate-before-scan command-line option to enable target validation with parallel processing.
    • Enhanced hostname and DNS resolution capabilities with improved validation and error handling.

โœ๏ธ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Adds pre-scan target validation feature, DNS/hostname utilities, a probe parser, CLI flag and locale key, integrates parallel target resolution into scanning flow, and updates .gitignore.

Changes

Cohort / File(s) Summary
Build configuration
โ€‹.gitignore
Added three new ignore entries: Public_sign, Public_sign.pub, cks_proxy.
Feature configuration & CLI
nettacker/config.py, nettacker/core/arg_parser.py, nettacker/locale/en.yaml
Added validate_before_scan = False default setting; added -C / --validate-before-scan CLI flag; added validate_before_scan localization key.
DNS & hostname utilities
nettacker/core/hostcheck.py
New module: valid_hostname() RFC1123 validation, _gai_once() wrapper, _clean_host() normalizer, and resolve_quick() fast DNS resolution with timeout and AI_ADDRCONFIG fallback.
Scan integration
nettacker/core/app.py
Added Nettacker.filter_valid_targets(...) using ThreadPoolExecutor and integrated conditional pre-scan validation into scan_target_group() when validate_before_scan is enabled and no SOCKS proxy.
Probe parser & YAML writer
nettacker/core/parser.py
New module: parsers for excluded ports, ports, sslports; parse_probe_file() to parse probe definitions (nmap-style) into structured probes and signatures; write_yaml() to emit probes YAML; includes CLI entry logic and debug prints.

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~45 minutes

Areas requiring extra attention:

  • nettacker/core/hostcheck.py โ€” correctness of hostname validation, DNS resolution timeout behavior, and dual AI_ADDRCONFIG attempts.
  • nettacker/core/app.py โ€” thread pool usage, concurrency limits, error/log handling, and interactions with existing scan flow (socks_proxy conditions).
  • nettacker/core/parser.py โ€” parsing correctness for range syntax, signatures extraction, YAML output consistency, and debug prints that may be unintended.

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
โœ… Passed checks (2 passed)
Check name Status Explanation
Title check โœ… Passed The title clearly and specifically describes the main feature being added: target validation before scan execution with the -C flag.
Description check โœ… Passed The description is well-related to the changeset, explaining the purpose of target validation, its implementation via -C flag, and confirming no breaking changes.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

[!TIP]

โœจ Issue Enrichment is now available for GitHub issues!

CodeRabbit can now help you manage issues more effectively:

  • Duplicate Detection โ€” Identify similar or duplicate issues
  • Related Issues & PRs โ€” Find relevant issues and PR's from your repository
  • Suggested Assignees โ€” Find the best person to work on the issue
  • Implementation Planning โ€” Generate detailed coding plans for engineers and agents
Disable automatic issue enrichment

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 30 '25 14:10 coderabbitai[bot]

LGTM!

pUrGe12 avatar Oct 30 '25 18:10 pUrGe12

Hi @securestep9 , gentle nudge for a review whenever you get a chance. Happy to address any feedback. Thanks!

Aarush289 avatar Nov 04 '25 17:11 Aarush289