Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions syft/pkg/cataloger/binary/classifier_cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("deno-binary"),
},
},
{
logicalFixture: "deno/1.10.3/linux-amd64",
expected: pkg.Package{
Name: "deno",
Version: "1.10.3",
Type: "binary",
PURL: "pkg:generic/deno@1.10.3",
Locations: locations("deno"),
Metadata: metadata("deno-binary"),
},
},
{
logicalFixture: "deno/2.6.3/linux-amd64",
expected: pkg.Package{
Expand Down Expand Up @@ -1485,6 +1496,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("openssl-binary"),
},
},
{
logicalFixture: "aws-lc/1.69.0/linux-amd64",
expected: pkg.Package{
Name: "aws-lc",
Version: "1.69.0",
Type: "binary",
PURL: "pkg:generic/aws-lc@1.69.0",
Locations: locations("openssl"),
Metadata: metadata("openssl-binary-aws-lc"),
},
},
{
logicalFixture: "openldap/2.6.10/linux-amd64",
expected: pkg.Package{
Expand Down Expand Up @@ -1754,6 +1776,25 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
},
},
},
{
// release-candidate elixir image — pre-fix the matchers stripped the
// "-rc.1" suffix from the elixir-library result and missed the
// elixir-binary entirely (#4819).
logicalFixture: "elixir/1.12.0-rc.1/linux-amd64",
expected: pkg.Package{
Name: "elixir",
Version: "1.12.0-rc.1",
Type: "binary",
PURL: "pkg:generic/elixir@1.12.0-rc.1",
Locations: locations("elixir", "lib/elixir/ebin/elixir.app"),
Metadata: pkg.BinarySignature{
Matches: []pkg.ClassifierMatch{
match("elixir-binary", "elixir"),
match("elixir-library", "lib/elixir/ebin/elixir.app"),
},
},
},
},
{
logicalFixture: "istio_pilot-discovery/1.29.0-alpha.0/linux-amd64",
expected: pkg.Package{
Expand Down Expand Up @@ -2227,6 +2268,105 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("envoy-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.15.1/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.15.1",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.15.1",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.11.8/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.11.8",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.11.8",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.9.6/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.9.6",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.9.6",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.7.1/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.7.1",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.7.1",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.12.0-beta.0/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.12.0-beta.0",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.12.0-beta.0",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.2.0-beta.1/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.2.0-beta.1",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.2.0-beta.1",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/1.0.0-alpha.2/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "1.0.0-alpha.2",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@1.0.0-alpha.2",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/0.34.0/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "0.34.0",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@0.34.0",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
{
logicalFixture: "nginx-ingress-controller/0.33.0/linux-amd64",
expected: pkg.Package{
Name: "nginx-ingress-controller",
Version: "0.33.0",
Type: "binary",
PURL: "pkg:generic/nginx-ingress-controller@0.33.0",
Locations: locations("nginx-ingress-controller"),
Metadata: metadata("ingress-nginx-binary"),
},
},
}

for _, test := range tests {
Expand Down
69 changes: 58 additions & 11 deletions syft/pkg/cataloger/binary/classifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,13 @@ func DefaultClassifiers() []binutils.Classifier {
EvidenceMatcher: m.FileContentsVersionMatcher(
// Deno/2.6.3
// Deno/1.41.0
`Deno/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
// Deno/X.Y.Z in binary string table
`Deno/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`,
// Deno 1.32.x and earlier: Rust embedded version string
// e.g., "deno::tools::standalone" or "cli/tools/standalone.rs" with version suffix
// Pattern: "deno" followed by path segment containing version
`deno[\s\-]*(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`,
),
Package: "deno",
PURL: mustPURL("pkg:generic/deno@version"),
CPEs: singleCPE("cpe:2.3:a:deno:deno:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
Expand Down Expand Up @@ -564,14 +570,29 @@ func DefaultClassifiers() []binutils.Classifier {
{
Class: "openssl-binary",
FileGlob: "**/openssl",
EvidenceMatcher: m.FileContentsVersionMatcher(
// [NUL]OpenSSL 3.1.4'
// [NUL]OpenSSL 1.1.1w'
`\x00OpenSSL (?P<version>[0-9]+\.[0-9]+\.[0-9]+([a-z]+|-alpha[0-9]|-beta[0-9]|-rc[0-9])?)`,
),
Package: "openssl",
PURL: mustPURL("pkg:generic/openssl@version"),
CPEs: singleCPE("cpe:2.3:a:openssl:openssl:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
EvidenceMatcher: binutils.BranchingEvidenceMatcher([]binutils.Classifier{
{
Class: "openssl-binary-aws-lc",
EvidenceMatcher: m.FileContentsVersionMatcher(
// [NUL]OpenSSL 1.1.1 (compatible; AWS-LC 1.69.0)[NUL]
`AWS-LC (?P<version>[0-9]+\.[0-9]+\.[0-9]+)\)\x00`,
),
Package: "aws-lc",
PURL: mustPURL("pkg:generic/aws-lc@version"),
CPEs: singleCPE("cpe:2.3:a:amazon:aws_libcrypto:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "openssl-binary",
EvidenceMatcher: m.FileContentsVersionMatcher(
// [NUL]OpenSSL 3.1.4'
// [NUL]OpenSSL 1.1.1w'
`\x00OpenSSL (?P<version>[0-9]+\.[0-9]+\.[0-9]+([a-z]+|-alpha[0-9]|-beta[0-9]|-rc[0-9])?)`,
),
Package: "openssl",
PURL: mustPURL("pkg:generic/openssl@version"),
CPEs: singleCPE("cpe:2.3:a:openssl:openssl:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
}...),
},
{
Class: "openldap-search-binary",
Expand Down Expand Up @@ -768,7 +789,9 @@ func DefaultClassifiers() []binutils.Classifier {
Class: "elixir-binary",
FileGlob: "**/elixir",
EvidenceMatcher: m.FileContentsVersionMatcher(
`(?m)ELIXIR_VERSION=(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
// Capture optional pre-release suffix (-rc.1, -alpha.0, -beta.2,
// etc.) so release-candidate elixir images (#4819) match.
`(?m)ELIXIR_VERSION=(?P<version>[0-9]+\.[0-9]+\.[0-9]+(?:-[a-z0-9]+(?:\.[0-9]+)?)?)`),
Package: "elixir",
PURL: mustPURL("pkg:generic/elixir@version"),
CPEs: []cpe.CPE{
Expand All @@ -779,7 +802,8 @@ func DefaultClassifiers() []binutils.Classifier {
Class: "elixir-library",
FileGlob: "**/elixir/ebin/elixir.app",
EvidenceMatcher: m.FileContentsVersionMatcher(
`(?m)\{vsn,"(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?)"\}`),
// Same pre-release extension as elixir-binary above.
`(?m)\{vsn,"(?P<version>[0-9]+\.[0-9]+\.[0-9]+(?:-[a-z0-9]+(?:\.[0-9]+)?)?)"\}`),
Package: "elixir",
PURL: mustPURL("pkg:generic/elixir@version"),
CPEs: singleCPE("cpe:2.3:a:elixir-lang:elixir:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
Expand Down Expand Up @@ -911,6 +935,29 @@ func DefaultClassifiers() []binutils.Classifier {
PURL: mustPURL("pkg:generic/mongodb@version"),
CPEs: singleCPE("cpe:2.3:a:mongodb:mongodb:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "ingress-nginx-binary",
FileGlob: "**/nginx-ingress-controller",
EvidenceMatcher: binutils.MatchAny(
// [NUL][NUL]v1.15.1[NUL][NUL]@e[ETX][NUL][NUL][NUL][NUL]go1.26.1[NUL][NUL][NUL]
// �v1.15.1[NUL][NUL]�z[ETX][NUL][NUL][NUL][NUL]go1.24.4[NUL][NUL][NUL]
m.FileContentsVersionMatcher(`v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00+.{0,50}go[0-9]+\.[0-9]+(\-(alpha|beta)\.[0-9])?\.[0-9]+\x00+`),
// �Lv1.9.6[NUL][NUL]$a�c[SOH][NUL][NUL][NUL]
// [NUL][NUL]v0.34.0[NUL]......�$a�...[NUL]
m.FileContentsVersionMatcher(`v(?P<version>[0-9]+\.[0-9]+\.[0-9]+(\-(alpha|beta)\.[0-9])?)\x00+.{0,800}\$a.{0,10}\x00+`),
// [NUL][NUL]v1.7.1[NUL][NUL][NUL]...S=v<y5...
// [NUL]0.33.0[NUL][NUL]...[NUL][NUL]...S=v<y5
m.FileContentsVersionMatcher(`\x00+v?(?P<version>[0-9]+\.[0-9]+\.[0-9]+(\-(alpha|beta)\.[0-9])?)\x00+.{0,100}S=v<y5`),
// [NUL][NUL]go1.22.8[NUL][NUL][NUL][NUL][NUL][NUL][NUL][NUL][NUL]v1.12.0-beta.0[NUL][NUL]
m.FileContentsVersionMatcher(`\x00+go[0-9]+\.[0-9]+\.[0-9]+\x00+v(?P<version>[0-9]+\.[0-9]+\.[0-9]+(\-(alpha|beta)\.[0-9])?)\x00+`),
// [NUL][NUL]v1.2.0-beta.1[NUL][NUL]
// [NUL][NUL]v1.0.0-alpha.2[NUL][NUL]
m.FileContentsVersionMatcher(`\x00+v(?P<version>[0-9]+\.[0-9]+\.[0-9]+\-(alpha|beta)\.[0-9])\x00+`),
),
Package: "nginx-ingress-controller",
PURL: mustPURL("pkg:generic/nginx-ingress-controller@version"),
CPEs: singleCPE("cpe:2.3:a:kubernetes:ingress-nginx:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
}

return append(classifiers, defaultJavaClassifiers()...)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: deno
offset: 100
length: 100
snippetSha256: test123
fileSha256: test456

### byte snippet to follow ###
t recognize flag ''.
deno 1.10.3cli/
worker.rsmain_mo
dule deno::worke
r[ext:cli/worker
Loading