feat(cli): add --exclude and --skip-self target filters (#674)#1227
feat(cli): add --exclude and --skip-self target filters (#674)#1227ChrisJr404 wants to merge 1 commit intoPennyw0rth:mainfrom
Conversation
Currently nxc has no way to remove specific hosts or networks from a
resolved target list, which means scanning a /24 during an engagement
sometimes hits the attacker host itself (or sensitive infrastructure
inside the same range that shouldn't be touched). The user fix to
that today is "split your scope into smaller CIDRs and run the tool
multiple times" — error-prone.
Add two related flags on the standard parser:
--exclude HOST [HOST ...] IP / range / CIDR / hostname entries to
remove from the resolved target list.
Accepts the same forms the positional
`target` accepts, including ranges
(`10.0.0.1-50`) and CIDRs.
--skip-self Convenience flag: detect the attacker
host's primary outbound IPv4 (UDP
connect to a non-routable address; no
traffic actually leaves the host) and
add it to the exclusion set.
The exclusion set is built after target resolution, so a user can
exclude a single IP from a CIDR scope without having to break the
range up. Closes Pennyw0rth#674.
|
It looks like the PR template may not have been filled out. The following sections appear to be missing:
Please edit your PR description to include them. The template helps reviewers understand and test your changes. Thanks! |
|
Closing this myself — re-reading NetExec's AI_POLICY.md after the template-check bot fired, two of the rules apply here:
Apologies for the noise on the issue tracker. Closing rather than refilling the template feels like the right call for the project's contributor culture. |
|
Thanks for the PR :)
Actually this is an accepted issue, but closing this PR is probably still the right call as we already have people that are working on this, see #732, #1204. Therefore, this PR would have been duplicate. |
Closes #674.
Background
Right now
nxccan't remove specific hosts or networks from a resolved target list. On engagements that scan a/24containing the attacker host or sensitive infrastructure, the only workarounds are (a) break the scope into smaller CIDRs and feed each separately, or (b) edit the target file by hand — both error-prone, and #674 calls out that "funny things happen" when the attacker host gets caught in its own scan.Change
Add two related flags on the standard parser (
std_parserinnxc/cli.py):--exclude HOST [HOST ...]targetaccepts, including ranges (10.0.0.1-50) and CIDRs.--skip-selfBoth run after target resolution in
nxc/netexec.py, so a user can exclude a single IP from a CIDR scope without having to fragment the CIDR into smaller pieces.Verification
python3 -m py_compile nxc/cli.py nxc/netexec.pyclean.Notes
+40 / 0lines across two files.set-based membership for O(1) filter, so a/16scan with--exclude 192.0.2.0/24is still O(n) in the resolved target count.--skip-selfonly handles IPv4. Adding IPv6 detection would mean a second UDP-connect probe to an unreachable v6 destination — happy to follow up if you'd like that included.--excludearen't resolved before set-membership comparison (matches the wayparse_targetshandles them today). If a future PR wants resolved-hostname matching, the natural place to add it is inparse_targetsitself.