Feature: validate targets before executing modules (-C)
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
- [x] I've followed the [contributing guidelines]contributing-guidelines
- [x] I've run
make pre-commit, it didn't generate any changes - [x] I've run
make test, all tests passed locally
Summary by CodeRabbit
- New Features
- Added pre-scan target validation to automatically skip unreachable targets before scanning.
- New
--validate-before-scancommand-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.
Comment @coderabbitai help to get the list of available commands and usage tips.
LGTM!
Hi @securestep9 , gentle nudge for a review whenever you get a chance. Happy to address any feedback. Thanks!