-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up hosts strings before using them (20.08) #1352
Clean up hosts strings before using them (20.08) #1352
Conversation
Before sending hosts strings to the OSPd-OpenVAS scanner and before calculating the number of hosts, leading zeroes in IPv4 addresses are removed because the addresses would be considered invalid otherwise.
The function did not recognize short form IPv4 ranges like "192.168.123.001-010", so the zeroes were not cleaned up.
Would it be a good idea to add this function to the gvm-libs/base/hosts.c ? |
Maybe yes. Our rule from way back is that it only goes in libs when it's used by two modules.
Agreed. |
Maybe |
The variable `clean_exclude_hosts` is only used in the if block checking `exclude_hosts` so it only needs to be declared there.
The strings for the cleaned hosts are copied by osp_target_new, so they need to be freed by the caller.
Comments were added to clarify what the matching and replacement regular expressions do.
Before this fix the regex matched some non-leading zeroes in numbers such as "100". Also, the limits of digit groups are now more clearly defined as the start/end of the line and non-digit characters.
I've added some unit tests and fixed a problem with non-leading zeroes being removed that I found with one of the test cases. |
What:
Before sending hosts strings to the OSPd-OpenVAS scanner and before
calculating the number of hosts, leading zeroes in IPv4 addresses
are removed.
Why:
The addresses would be considered invalid otherwise, resulting in the hosts count to be reported as -1.
Starting a scan with a target using an IPv4 address with leading zeroes would also cause the scanner to crash.
How:
This was tested by:
max_hosts
SQL function containing IPv4 addresses with extra zeroes, e.g.SELECT max_hosts('192.168.123.001-192.168.123.035', '192.168.123.033');
SELECT max_hosts('192.168.123.000/26, host001.example.com, 127.000.000.001', '');
which should now return a positive number of hosts instead of -1.
(e.g.
UPDATE targets SET hosts='192.168.123.045' WHERE name='ipv4test';
)A scan using it should run the same as one with the same address without extra zeroes and not end in the "Interrupted" status.
clean_hosts_string
function was added to verify IPv4 addresses are cleaned up in the cases for single addresses, simple host ranges (e.g. 192.168.123.001-192.168.123.035) and CIDR notation ranges are handled while extra zeroes in hostnames like host001.example.com are kept intact.Checklist: