Changing the order of the IP ranges inside the excludefile changes the outcome. Having a smaller IP-Range which is included in a bigger IP-Range and both defined in the excludefile, might excludes everything, if small IP-Range is in front of the big IP-Range.
This can be a single IP Address as well instead of an IP-Range.
It only happens if the smaller range is included in the bigger range.
To Reproduce
Running: nmap --excludefile exclude.list 192.168.0.0/16 with the following two different excludefiles:
Small Range in front of Big Range:
-> % cat exclude.list.doesnotwork
192.168.1.64/25
192.168.1.0/24
-> % nmap --excludefile exclude.list.doesnotwork 192.168.0.0/16
Starting Nmap 7.80 ( https://nmap.org ) at 2021-02-25 10:28 CET
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 0.04 seconds
Thanks for reporting this. I'm hunting down the problem, which seems to be an edge case I missed when implementing the exclusion trie merging code. Specifically, it seems that if the address part of a CIDR spec falls within a CIDR spec already in the trie, we end up doing the wrong thing, probably when we assume this means the earlier spec is the larger one. For example, if you use a different pair of specs such that the base address of the larger spec does not fall within the smaller one, the bug doesn't trigger: 192.168.1.128/25 and 192.168.1.0/24, for instance.
if (this->mask[i] > mask[i]) {
/* broader mask, truncate this one */
this->mask[i] = mask[i];
for (; i < 4; i++) {
this->mask[i] = 0;
}
We correctly take the new, broader mask for this u32 (in the case of IPv4, that's the entire mask), but then we set each u32 in the mask to 0. We should skip the current one since we already grabbed the correct value.
I'm actually rewriting a few portions of this to do the work in trie_split() instead, since that is going to be a bit more efficient. Will update this issue when I push a fix.
Changing the order of the IP ranges inside the excludefile changes the outcome. Having a smaller IP-Range which is included in a bigger IP-Range and both defined in the excludefile, might excludes everything, if small IP-Range is in front of the big IP-Range.
This can be a single IP Address as well instead of an IP-Range.
It only happens if the smaller range is included in the bigger range.
To Reproduce
Running:
nmap --excludefile exclude.list 192.168.0.0/16
with the following two different excludefiles:Small Range in front of Big Range:
Small Range after Big Range
Expected behavior
It shouldn't matter which option the IP-Ranges are inside the excludefile.
Version info (please complete the following information):
Same behaviour with: Nmap version 7.91
The text was updated successfully, but these errors were encountered: