Skip to content

Fix NVD version comparator to remove undesired suffixes#5362

Merged
chemamartinez merged 4 commits into4.0-vdt-tmpfrom
5281-nvd-comparison
Jul 8, 2020
Merged

Fix NVD version comparator to remove undesired suffixes#5362
chemamartinez merged 4 commits into4.0-vdt-tmpfrom
5281-nvd-comparison

Conversation

@chemamartinez
Copy link
Copy Markdown
Contributor

Description

This PR modifies the way that the version part is compared between the installed packages and the NVD packages for Linux. Since the NVD contains a generic version in most of the cases, the version of the installed package should be truncated in the following cases:

  • By finding a . followed by a non-numeric character
1:1.2.8.dfsg
1:9.10.3.dfsg.P4
2.4+20151223.gitfa8646d.1
2.10.2.is.2.10.1
1:9.9.5.dfsg
  • By finding a + followed by a non-numeric character
3.113+nmu3
2.11+dfsg
4.6.0+git+20161106
1:8.11+urwcyr1.0.7~pre44
  • By finding a ~ followed by a non-numeric character
0.60.7~20110707
0.7.6~bzr976
2.02~beta2
9.26a~dfsg

Finally, the following cases have been ignored for this change:

  • When finding .0 at the end of the version: In this case, the comparator itself has to compare the versions properly.
  • When finding alpha characters in the version (e.g. openssl 1.1.0h): In these cases, the version found in the NVD generally contains those characters.

Logs/Alerts example

Here an example of the comparison affected by this change:

2020/06/30 03:49:50 wazuh-modulesd:vulnerability-detector[95726] wm_vuln_detector_nvd.c:2418 at wm_vuldet_check_generic_package(): DEBUG: (5459): Trying to insert duplicated package 'openldap' into the vulnerability 'CVE-2017-14159'. Version (2.4.45+dfsg-1ubuntu1.5) 'less than or equal' '2.4.45' (feed 'NVD').

Tests

  • Compilation without warnings in every supported platform
    • Linux
  • Source installation
  • Analyzed the added and removed alerts
  • Memory tests for Linux
    • Scan-build report
    • Valgrind (memcheck and descriptor leaks check)
  • Added unit tests (for new features)

if ((a[i] == '.'
|| a[i] == '~'
|| a[i] == '+')
&& !c_isdigit(a[i + 1])) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is a number after a ~ or a +?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included that condition 0362989

@chemamartinez chemamartinez changed the base branch from 3.14 to 4.0 July 1, 2020 15:58
Copy link
Copy Markdown
Member

@TomasTurina TomasTurina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chemamartinez chemamartinez changed the base branch from 4.0 to 4.0-vdt-tmp July 8, 2020 14:34
@chemamartinez chemamartinez merged commit 59102d3 into 4.0-vdt-tmp Jul 8, 2020
@chemamartinez chemamartinez deleted the 5281-nvd-comparison branch July 8, 2020 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants