From d4733fac1dcae71200f0098bd0406a8fc1fc1748 Mon Sep 17 00:00:00 2001 From: Duane May Date: Tue, 21 Nov 2023 11:54:41 -0500 Subject: [PATCH] Add binary classifiers for MySQL and MariaDB (#2316) * Add MySQL and MariaDB binary classifiers Signed-off-by: Duane May Signed-off-by: Duane May * use smallest possible binary fixtures Signed-off-by: Alex Goodman --------- Signed-off-by: Duane May Signed-off-by: Duane May Signed-off-by: Alex Goodman Co-authored-by: Alex Goodman --- syft/pkg/cataloger/binary/cataloger_test.go | 36 ++++++++++++++++ .../cataloger/binary/default_classifiers.go | 20 +++++++++ .../positive/mariadb-10.6.15/README.md | 31 ++++++++++++++ .../positive/mariadb-10.6.15/mariadb | Bin 0 -> 40 bytes .../positive/mysql-5.6.51/README.md | 39 +++++++++++++++++ .../classifiers/positive/mysql-5.6.51/mysql | Bin 0 -> 100 bytes .../positive/mysql-8.0.34/README.md | 40 ++++++++++++++++++ .../classifiers/positive/mysql-8.0.34/mysql | Bin 0 -> 100 bytes 8 files changed, 166 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/README.md create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/mariadb create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mysql-5.6.51/README.md create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mysql-5.6.51/mysql create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mysql-8.0.34/README.md create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mysql-8.0.34/mysql diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 086807cf4..bf32d1828 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -72,6 +72,42 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { Metadata: metadata("postgresql-binary"), }, }, + { + name: "positive-mysql-8.0.34", + fixtureDir: "test-fixtures/classifiers/positive/mysql-8.0.34", + expected: pkg.Package{ + Name: "mysql", + Version: "8.0.34", + Type: "binary", + PURL: "pkg:generic/mysql@8.0.34", + Locations: locations("mysql"), + Metadata: metadata("mysql-binary"), + }, + }, + { + name: "positive-mysql-5.6.51", + fixtureDir: "test-fixtures/classifiers/positive/mysql-5.6.51", + expected: pkg.Package{ + Name: "mysql", + Version: "5.6.51", + Type: "binary", + PURL: "pkg:generic/mysql@5.6.51", + Locations: locations("mysql"), + Metadata: metadata("mysql-binary"), + }, + }, + { + name: "positive-mariadb-10.6.15", + fixtureDir: "test-fixtures/classifiers/positive/mariadb-10.6.15", + expected: pkg.Package{ + Name: "mariadb", + Version: "10.6.15", + Type: "binary", + PURL: "pkg:generic/mariadb@10.6.15", + Locations: locations("mariadb"), + Metadata: metadata("mariadb-binary"), + }, + }, { name: "positive-traefik-2.9.6", fixtureDir: "test-fixtures/classifiers/positive/traefik-2.9.6", diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 9b4b2dc2c..88e16454e 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -211,6 +211,26 @@ var defaultClassifiers = []classifier{ Package: "postgresql", PURL: mustPURL("pkg:generic/postgresql@version"), }, + { + Class: "mysql-binary", + FileGlob: "**/mysql", + EvidenceMatcher: fileContentsVersionMatcher( + // ../../mysql-8.0.34 + // /mysql-5.6.51/bld/client + `(?m).*/mysql-(?P[0-9]+(\.[0-9]+)?(\.[0-9]+)?(alpha[0-9]|beta[0-9]|rc[0-9])?)`), + Package: "mysql", + PURL: mustPURL("pkg:generic/mysql@version"), + CPEs: singleCPE("cpe:2.3:a:oracle:mysql:*:*:*:*:*:*:*:*"), + }, + { + Class: "mariadb-binary", + FileGlob: "**/mariadb", + EvidenceMatcher: fileContentsVersionMatcher( + // 10.6.15-MariaDB + `(?m)(?P[0-9]+(\.[0-9]+)?(\.[0-9]+)?(alpha[0-9]|beta[0-9]|rc[0-9])?)-MariaDB`), + Package: "mariadb", + PURL: mustPURL("pkg:generic/mariadb@version"), + }, { Class: "rust-standard-library-linux", FileGlob: "**/libstd-????????????????.so", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/README.md b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/README.md new file mode 100644 index 000000000..20b6bc50c --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/README.md @@ -0,0 +1,31 @@ +The binary snippet was gathered with: + +```bash +$ cat ./original-mariadb | strings | grep '-MariaDB' +# assert you can see the value + + +$ xxd ./original-mariadb | grep '\-MariaDB' +# get the address... + + +$ xxd -s 0x003dd5c0 -l 40 ./original-mariadb + +003dd5c0: 2900 4c69 6e75 7800 3130 2e36 2e31 352d ).Linux.10.6.15- +003dd5d0: 4d61 7269 6144 4200 7265 6164 6c69 6e65 MariaDB.readline +003dd5e0: 0078 3836 5f36 3400 .x86_64. + + +$ dd if=./original-mariadb of=mariadb bs=1 skip=$((0x003dd5c0)) count=40 + +40+0 records in +40+0 records out +40 bytes transferred in 0.000264 secs (151515 bytes/sec) + + +$ xxd mariadb + +00000000: 2900 4c69 6e75 7800 3130 2e36 2e31 352d ).Linux.10.6.15- +00000010: 4d61 7269 6144 4200 7265 6164 6c69 6e65 MariaDB.readline +00000020: 0078 3836 5f36 3400 .x86_64. +``` \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/mariadb b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/mariadb-10.6.15/mariadb new file mode 100644 index 0000000000000000000000000000000000000000..26b2463e6769dae80d26ecd52aa9248ea124f5b3 GIT binary patch literal 40 vcmdO7@X5?8tza-T&@Ts0?c=3gsDB2Jbff%lQ>K iC#i9g(Y4Ss&@(pC2QicLb93|a^pkTk nQ}asV3vx=+GxPM4lNt0&i;MJg@{<#DAbRw3GL!Tn(hQye3?U$f literal 0 HcmV?d00001