From 5602c80edbbb5b235489a70904edf8a985150372 Mon Sep 17 00:00:00 2001 From: Laurent Goderre Date: Wed, 17 Jan 2024 11:42:03 -0500 Subject: [PATCH] feat: classifier for wordpress cli binary (#2473) Signed-off-by: Laurent Goderre --- syft/pkg/cataloger/binary/cataloger_test.go | 11 +++++++++++ syft/pkg/cataloger/binary/default_classifiers.go | 11 +++++++++++ .../classifiers/snippets/wp/2.9.0/linux-amd64/wp | 10 ++++++++++ syft/pkg/cataloger/binary/test-fixtures/config.yaml | 7 +++++++ 4 files changed, 39 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/wp/2.9.0/linux-amd64/wp diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index c80a2a743..a586f615b 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -872,6 +872,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("gcc-binary"), }, }, + { + logicalFixture: "wp/2.9.0/linux-amd64", + expected: pkg.Package{ + Name: "wp-cli", + Version: "2.9.0", + Type: "binary", + PURL: "pkg:generic/wp-cli@2.9.0", + Locations: locations("wp"), + Metadata: metadata("wordpress-cli-binary"), + }, + }, } for _, test := range tests { diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index c0ef9de6b..ca4992919 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -403,6 +403,17 @@ func DefaultClassifiers() []Classifier { PURL: mustPURL("pkg:generic/gcc@version"), CPEs: singleCPE("cpe:2.3:a:gnu:gcc:*:*:*:*:*:*:*:*"), }, + { + Class: "wordpress-cli-binary", + FileGlob: "**/wp", + EvidenceMatcher: FileContentsVersionMatcher( + // wp-cli/wp-cli 2.9.0' + `(?m)wp-cli/wp-cli (?P[0-9]+\.[0-9]+\.[0-9]+)`, + ), + Package: "wp-cli", + PURL: mustPURL("pkg:generic/wp-cli@version"), + CPEs: singleCPE("cpe:2.3:a:wp-cli:wp-cli:*:*:*:*:*:*:*:*"), + }, } } diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/wp/2.9.0/linux-amd64/wp b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/wp/2.9.0/linux-amd64/wp new file mode 100644 index 000000000..30e33085c --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/wp/2.9.0/linux-amd64/wp @@ -0,0 +1,10 @@ +name: wp +offset: 6967657 +length: 120 +snippetSha256: fe7afa7db1b4efc55b3099b5b1fb46a34e34b147c708be0a74d1dd9fce2b5cac +fileSha256: af6b7ccc21ed0907cb504db5a059f0e120117905a6017bfdd4375cee3c93d864 + +### byte snippet to follow ### +ND CERTIFICATE----- +wp-cli/wp-cli 2.9.0 2023-10-25T09:10:40+00:00 +composer/ca-bundle 1.3.7 76e46335014860eec1aa5a724799a \ No newline at end of file diff --git a/syft/pkg/cataloger/binary/test-fixtures/config.yaml b/syft/pkg/cataloger/binary/test-fixtures/config.yaml index 478a74d5d..98f29f634 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/config.yaml +++ b/syft/pkg/cataloger/binary/test-fixtures/config.yaml @@ -315,6 +315,13 @@ from-images: paths: - /usr/local/bin/redis-server + - version: 2.9.0 + images: + - ref: wordpress:cli-2.9.0-php8.3@sha256:3a008aafccc6a8d2d7ec2b069722cb43b3569b61cd833f9f2f13d74a9284746e + platform: linux/amd64 + paths: + - /usr/local/bin/wp + - version: 1.9.3p551 images: - ref: ruby:1.9.3-p551@sha256:56b4a74e4fc2492b3b857bc94454dfa910f61e823a4bfab275d279bfa218eb05