diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 4a36a5e1d..c66cb88db 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -643,6 +643,30 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { Metadata: metadata("consul-binary"), }, }, + { + name: "positive-nginx-1.25.1", + fixtureDir: "test-fixtures/classifiers/positive/nginx-1.25.1", + expected: pkg.Package{ + Name: "nginx", + Version: "1.25.1", + Type: "binary", + PURL: "pkg:generic/nginx@1.25.1", + Locations: locations("nginx"), + Metadata: metadata("nginx-binary"), + }, + }, + { + name: "positive-nginx-openresty-1.21.4.2", + fixtureDir: "test-fixtures/classifiers/positive/nginx-openresty-1.21.4.2", + expected: pkg.Package{ + Name: "nginx", + Version: "1.21.4", + Type: "binary", + PURL: "pkg:generic/nginx@1.21.4", + Locations: locations("nginx"), + Metadata: metadata("nginx-binary"), + }, + }, } for _, test := range tests { diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 5c2f2e17f..93ed25d30 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -254,6 +254,21 @@ var defaultClassifiers = []classifier{ PURL: mustPURL("pkg:golang/github.com/hashicorp/consul@version"), CPEs: singleCPE("cpe:2.3:a:hashicorp:consul:*:*:*:*:*:*:*:*"), }, + { + Class: "nginx-binary", + FileGlob: "**/nginx", + EvidenceMatcher: fileContentsVersionMatcher( + // [NUL]nginx version: nginx/1.25.1 - fetches '1.25.1' + // [NUL]nginx version: openresty/1.21.4.1 - fetches '1.21.4' as this is the nginx version part + `(?m)(\x00|\?)nginx version: [^\/]+\/(?P[0-9]+\.[0-9]+\.[0-9]+(?:\+\d+)?(?:-\d+)?)`, + ), + Package: "nginx", + PURL: mustPURL("pkg:generic/nginx@version"), + CPEs: []cpe.CPE{ + cpe.Must("cpe:2.3:a:f5:nginx:*:*:*:*:*:*:*:*"), + cpe.Must("cpe:2.3:a:nginx:nginx:*:*:*:*:*:*:*:*"), + }, + }, } // in both binaries and shared libraries, the version pattern is [NUL]3.11.2[NUL] diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/nginx-1.25.1/nginx b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/nginx-1.25.1/nginx new file mode 100644 index 000000000..6311b0515 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/nginx-1.25.1/nginx differ diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/nginx-openresty-1.21.4.2/nginx b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/nginx-openresty-1.21.4.2/nginx new file mode 100644 index 000000000..79aa8cda4 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/nginx-openresty-1.21.4.2/nginx differ