Skip to content
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

Updated existing checkers using Helper Script #1189

Merged
merged 58 commits into from
Aug 18, 2021

Conversation

peb-peb
Copy link
Contributor

@peb-peb peb-peb commented Jun 23, 2021

  • add # Alternate optional contains patterns, see <link to helper script docs> for more details

checkers checked against the Helper Script:

  • avahi
  • bash
  • bind
  • binutils (not scanned - already has good signatures)
  • busybox
  • bzip2
  • cups
  • curl
  • dnsmasq
  • dovecot
  • dpkg --not scanned
  • expat --not getting the exact vendor-product pair
  • ffmpeg --breaks the script
  • freeradius
  • gcc
  • gimp
  • glibc
  • gnupg
  • gstreamer
  • haproxy
  • hostpad
  • icecast
  • icu fix: icu checker #1208
  • irissi
  • kerberos
  • libarchive (no proper strings available for CONTAINS_PATTERNS)
  • libcurl
  • libdb
  • libgcrypt
  • libjpeg
  • libnss (not scanned - already has good signatures)
  • linsndfile
  • libsoup (no proper strings available for CONTAINS_PATTERNS)
  • libssh2
  • libtiff
  • libvirt
  • libxslt
  • lighttpd
  • logrotate
  • mariadb
  • memchand
  • mysql
  • ncurses
  • nessus
  • netpbm
  • nginx
  • node
  • ntp
  • openafs
  • openjpeg
  • openldap
  • openssh
  • openssl
  • openvpn
  • p7zip
  • png
  • polarssl_fedora
  • postgresql
  • pspp
  • python
  • qt
  • radare2
  • rsyslog
  • samba
  • sqlite
  • strongswan
  • subversion
  • syslogng
  • systemd
  • tcpdump
  • varnish
  • webkitgtk
  • wireshark
  • wpa_supplicant
  • xerces
  • xml2
  • zlib

@peb-peb
Copy link
Contributor Author

peb-peb commented Jun 23, 2021

While looking for common strings in bash, I found about ~70 common stings. I choose only a few to include here. Should we comment all the common strings? (I was going for about 4-5 strings)

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2021

Codecov Report

Merging #1189 (eaed3cf) into main (3ccda67) will increase coverage by 1.52%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1189      +/-   ##
==========================================
+ Coverage   79.31%   80.84%   +1.52%     
==========================================
  Files         271      271              
  Lines        4908     4908              
  Branches      593      593              
==========================================
+ Hits         3893     3968      +75     
+ Misses        866      797      -69     
+ Partials      149      143       -6     
Flag Coverage Δ
longtests 80.84% <100.00%> (+1.52%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cve_bin_tool/checkers/dnsmasq.py 100.00% <ø> (ø)
cve_bin_tool/checkers/libsndfile.py 100.00% <ø> (ø)
test/test_data/bzip2.py 100.00% <ø> (ø)
test/test_data/cups.py 100.00% <ø> (ø)
test/test_data/curl.py 100.00% <ø> (ø)
test/test_data/dovecot.py 100.00% <ø> (ø)
test/test_data/freeradius.py 100.00% <ø> (ø)
test/test_data/gcc.py 100.00% <ø> (ø)
test/test_data/gnupg.py 100.00% <ø> (ø)
test/test_data/irssi.py 100.00% <ø> (ø)
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ccda67...eaed3cf. Read the comment docs.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Looking pretty good, let's just make sure we've got an explanation and/or a link to docs about the helper script so people can see why there's commented out values.

cve_bin_tool/checkers/avahi.py Show resolved Hide resolved
@peb-peb
Copy link
Contributor Author

peb-peb commented Jun 26, 2021

# Alternate optional contains patterns, see <link to helper script docs> for more details

I'll update it it once I finish writing up the docs.

Comment on lines 32 to +34
VERSION_PATTERNS = [
r"gcc ([0-9]+\.[0-9]+\.[0-9]+)",
r"gcc ([0-9]+\.[0-9]+)",
r"GCC: \(GNU\) ([0-9]+\.[0-9]+(\.[0-9]+)?)",
# r"gcc ([0-9]+\.[0-9]+(\.[0-9]+)?)", # does not return correct version number on some packages
Copy link
Contributor Author

Choose a reason for hiding this comment

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

        # Make sure the product and version are in the results
        assert (
            product in list_products
        ), f"""{product} not found in {package_name}.
        The checker signature or url may be incorrect."""
>       assert version in list_versions
E       AssertionError: assert '8.4.1' in {'8.3.1'}

test/test_scanner.py:262: AssertionError

after scanning a few files, found that r"gcc ([0-9]+\.[0-9]+(\.[0-9]+)?)" is not consistent and changed it.
Also, I was not able to find any appropriate version pattern for debian packages. (I've added a note at top for this)

@peb-peb
Copy link
Contributor Author

peb-peb commented Jul 7, 2021

for gnupg, I am receiving this error: (all tests seems to fail)

        # Make sure the product and version are in the results
>       assert (
            product in list_products
        ), f"""{product} not found in {package_name}.
        The checker signature or url may be incorrect."""
E       AssertionError: gnupg not found in gnupg-1.4.23nb11.tgz.
E                 The checker signature or url may be incorrect.
E       assert 'gnupg' in set()

test/test_scanner.py:258: AssertionError

this is what my checker looks like:

class GnupgChecker(Checker):
    CONTAINS_PATTERNS = [
        r"# \(Use \"gpg --import-ownertrust\" to restore them\)",
        r"Comment: Use \"gpg --dearmor\" for unpacking",
        # r"standalone revocation - use \"gpg --import\" to apply",
        # r"you can update your preferences with: gpg --edit-key %s updpref save",
    ]
    FILENAME_PATTERNS = [
        "gpg",  # to match gpg, gpg2, gpg1
        # "g13",
    ]
    VERSION_PATTERNS = [
        r"gpg\.conf\-([0-9]+\.[0-9]+\.[0-9]+)",
        # r"(GnuPG) ([0-9]+\.[0-9]+\.[0-9]+)",
        # r"GNU Privacy Guard's OpenPGP server ([0-9]+\.[0-9]+\.[0-9]+) ready",
        # r"GNU Privacy Guard's G13 server ([0-9]+\.[0-9]+\.[0-9]+) ready",
    ]
    VENDOR_PRODUCT = [("gnupg", "gnupg")]

and the test_data for it is:

mapping_test_data = [
    {
        "product": "gnupg",
        "version": "2.2.27",
        "version_strings": ["gpg.conf-2.2.27"],
    },
    {
        "product": "gnupg",
        "version": "2.2.23",
        "version_strings": ["gpg.conf-2.2.23"],
    },
]

package_test_data = [
    {
        "url": "http://mirror.centos.org/centos/7/os/x86_64/Packages/",
        "package_name": "gnupg2-2.0.22-5.el7_5.x86_64.rpm",
        "product": "gnupg",
        "version": "2.0.22",
    },
    {
        "url": "http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/",
        "package_name": "gnupg2-2.2.20-2.el8.x86_64.rpm",
        "product": "gnupg",
        "version": "2.2.20",
    },
    {
        "url": "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/34/Everything/x86_64/os/Packages/g/",
        "package_name": "gnupg1-1.4.23-15.fc34.x86_64.rpm",
        "product": "gnupg",
        "version": "1.4.23",
    },
    {
        "url": "https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/9.1/All/",
        "package_name": "gnupg-1.4.23nb11.tgz",
        "product": "gnupg",
        "version": "1.4.23",
    },
]

I am not pushing this in this pr due to the errors :(

peb-peb and others added 21 commits July 18, 2021 00:10
* fixes: intel#1159
* test: change way pytest is run in CI

Switch to using a full pytest gather for the async tests. Several test files are singled out to be run synchronously because they touch NVD and can cause us to get rate limited if they run in parallel.

This will ensure that no one needs to add new test files explicitly to CI unless they need to be run synchronously.

Several test files are (temporarily) disabled because they are not passing; we'll enable those as they are fixed.

Signed-off-by: Terri Oda <[email protected]>
* refactor(scanner): Remove scanned string splitting

refactor(strings): Return a string instead of array of string

* fix(checker): with respect to changes from b240fa0

fix: xml2 checker
fix: sqlite checker
fix: glibc checker and test
fix: systemd checker
fix: libdb checker
fix: systemd checker v229 .deb
fix: universal python package checker
* feat(checker): Add sudo checker

* add condensed downloads for sudo
* Fix yaml and toml tests in test_config
* Related to intel#1159
* Add test_config back to updated CI

Two of the tests in test_config were failing, presumably because they'd
gotten out of date when we changed the default for extraction. These
tests were not being run in CI (thanks to @Molkree for noticing that) so
they didn't get fixed in a timely manner.

Signed-off-by: Terri Oda <[email protected]>
* Add recommdended dev tools list
* Moved isort to dev requirements file.
* fix: pip install from dev-recommended for isort CI
* fix: remove isort also from requirements.csv

Signed-off-by: Terri Oda <[email protected]>
* fix: Add gnome-shell checker
* fix: Improve regex(multiline)
* fix: Windows test for gnome-shell checker
* fix: rename development requirements file for Snyk

Snyk picks up files named `*req*.txt` so we're switching
dev-recommended.txt to dev-requirements.txt so gets scanned
automatically.

Signed-off-by: Terri Oda <[email protected]>
* fix: condensed downloads

The condensed downloads were made without any proper strings in it due to the changes in intel#1227.

* refactor: writelines -> write
…#1246)

* refactor: helper script for is_executable() and parse_string()
* helper script: Instantiate instance of VersionScanner

Previously we were only using VersionScanner.clean_file_path() which is
a static method. In this case we did not need to instantiate and
instance.

We started using the is_executable() and parse_strings() methods, which
are regular methods which use self. When a method takes self as the
first positional argument we must instantiate its class before we use
call the attached method.

As such, we've created a new instance of VersionScanner as the
version_scanner property within HelperScript.

Tested with

$ curl -sfLo /tmp/libmatroska-1.5.0-1.el8.aarch64.rpm \
  https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/libmatroska-1.5.0-1.el8.x86_64.rpm
$ python cve_bin_tool/helper_script.py /tmp/libmatroska-1.5.0-1.el8.aarch64.rpm
[07:09:05] INFO     cve_bin_tool.VersionScanner - Updating version_scanner.py:42
                    egg_info
           WARNING  cve_bin_tool.HelperScript - False        helper_script.py:74
           WARNING  cve_bin_tool.HelperScript - False        helper_script.py:74
           WARNING  cve_bin_tool.HelperScript - False        helper_script.py:74
           WARNING  cve_bin_tool.HelperScript - False        helper_script.py:74
           WARNING  cve_bin_tool.HelperScript - (True, '/tmp helper_script.py:74
                    /cve-bin-tool-3shnb9ex/libmatroska-1.5.0
                    -1.el8.aarch64.rpm.extracted/usr/lib64/l
                    ibmatroska.so.6.0.0: ELF 64-bit LSB
                    shared object, x86-64, version 1 (SYSV),
                    dynamically linked, BuildID[sha1]=4e7b21
                    76f1dc3f381571a2c873532ab0ce254c24,
                    stripped, too many notes (256)\n')
           WARNING  cve_bin_tool.HelperScript - False        helper_script.py:74
────────────────────────────── LibmatroskaChecker ──────────────────────────────
CONTAIN_PATTERNS = [
        r"N11libmatroska24KaxChapterProcessCodecIDE",
        r"N11libmatroska24KaxChapterProcessCommandE",
        r"N11libmatroska24KaxChapterProcessPrivateE",
libmatroska::KaxVideoGamma::RenderData(libebml::IOCallback&, bool, bool)",
        ... <output shortened> ...
        r"virtual libmatroska::DataBuffer* libmatroska::DataBuffer::Clone()",
        r"void
libmatroska::KaxBlockBlob::SetBlockGroup(libmatroska::KaxBlockGroup&)",
        r"void libmatroska::KaxBlockGroup::SetBlockDuration(uint64)",
        r"void libmatroska::KaxReferenceBlock::SetReferencedBlock(const
libmatroska::KaxBlockBlob*)",
]
FILENAME_PATTERNS = [
        r"libmatroska.so.6.0.0",
]
VERSION_PATTERNS = [
        r"/builddir/build/BUILD/libmatroska-1.5.0/matroska/KaxBlock.h",
        r"/builddir/build/BUILD/libmatroska-1.5.0/matroska/KaxTracks.h",
        r"/builddir/build/BUILD/libmatroska-1.5.0/src/KaxBlock.cpp",
        r"/builddir/build/BUILD/libmatroska-1.5.0/src/KaxBlockData.cpp",
        r"/builddir/build/BUILD/libmatroska-1.5.0/matroska/KaxCluster.h",
        r"/builddir/build/BUILD/libmatroska-1.5.0/src/KaxCluster.cpp",
        r"/builddir/build/BUILD/libmatroska-1.5.0/matroska/KaxCues.h",
        r"/builddir/build/BUILD/libmatroska-1.5.0/src/KaxCues.cpp",
        r"/builddir/build/BUILD/libmatroska-1.5.0/src/KaxCuesData.cpp",
        r"/builddir/build/BUILD/libmatroska-1.5.0/src/KaxSemantic.cpp",
]
VENDOR_PRODUCT = [('matroska', 'libmatroska')]
────────────────────────────────────────────────────────────────────────────────

Signed-off-by: John Andersen <[email protected]>

* refactor(helperscript): removed unused imports

fix for black and isort
commented the log messages

* fix: typo

* refactor(version_scanner): now is_executable would retrun (True, output) or (False, None)

* refactor(helper_script): removed try/except block

* fix: black

Co-authored-by: John Andersen <[email protected]>
peb-peb added 24 commits August 15, 2021 00:35
updated CONTAINS_PATTERNS and VERSIONS_PATTERNS for bzip2 checker
also added tests for wireshark, since latest versions of wireshark
have "wireshark" as their common filename
added strings in CONTAINS_PATTERNS
added a new string in VERSION_PATTERNS
added strings for CONTAINS_PATTERNS
added another mapping_test_data
added new version string regex
added tests
added CONTAIN_PATTERNS
replaced the old version string with a more consistent one
added tests for the same
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants