Skip to content

Commit

Permalink
feat: add binary classifiers for lighttp, proftpd, zstd, xz, gzip, jq…
Browse files Browse the repository at this point in the history
…, and sqlcipher (#3252)

* feat: detect lighttpd binaries

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* feat: detect proftpd binaries

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* feat: detect zstd binaries

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* feat: detect xz utils binarie

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* feat: detect gzip binaries

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* feat: detect sqlcipher binaries

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* feat: detect jq binaries

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>

* add tests + snippets

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Krystian Gorny <krystian.gorny@wipotec.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Krystian Gorny <krystian.gorny@wipotec.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent cb0de97 commit 6a95a5f
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 0 deletions.
88 changes: 88 additions & 0 deletions syft/pkg/cataloger/binary/classifier_cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,94 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
Metadata: metadata("wordpress-cli-binary"),
},
},
{
logicalFixture: "lighttpd/1.4.76/linux-amd64",
expected: pkg.Package{
Name: "lighttpd",
Version: "1.4.76",
Type: "binary",
PURL: "pkg:generic/lighttpd@1.4.76",
Locations: locations("lighttpd"),
Metadata: metadata("lighttpd-binary"),
},
},
{
logicalFixture: "proftpd/1.3.8b/linux-amd64",
expected: pkg.Package{
Name: "proftpd",
Version: "1.3.8b",
Type: "binary",
PURL: "pkg:generic/proftpd@1.3.8b",
Locations: locations("proftpd"),
Metadata: metadata("proftpd-binary"),
},
},
{
logicalFixture: "zstd/1.5.6/linux-amd64",
expected: pkg.Package{
Name: "zstd",
Version: "1.5.6",
Type: "binary",
PURL: "pkg:generic/zstd@1.5.6",
Locations: locations("zstd"),
Metadata: metadata("zstd-binary"),
},
},
{
logicalFixture: "zstd/1.5.6/linux-amd64",
expected: pkg.Package{
Name: "zstd",
Version: "1.5.6",
Type: "binary",
PURL: "pkg:generic/zstd@1.5.6",
Locations: locations("zstd"),
Metadata: metadata("zstd-binary"),
},
},
{
logicalFixture: "xz/5.6.2/linux-amd64",
expected: pkg.Package{
Name: "xz",
Version: "5.6.2",
Type: "binary",
PURL: "pkg:generic/xz@5.6.2",
Locations: locations("xz"),
Metadata: metadata("xz-binary"),
},
},
{
logicalFixture: "gzip/1.12/linux-amd64",
expected: pkg.Package{
Name: "gzip",
Version: "1.12",
Type: "binary",
PURL: "pkg:generic/gzip@1.12",
Locations: locations("gzip"),
Metadata: metadata("gzip-binary"),
},
},
{
logicalFixture: "sqlcipher/4.5.5/linux-amd64",
expected: pkg.Package{
Name: "sqlcipher",
Version: "4.5.5",
Type: "binary",
PURL: "pkg:generic/sqlcipher@4.5.5",
Locations: locations("sqlcipher"),
Metadata: metadata("sqlcipher-binary"),
},
},
{
logicalFixture: "jq/1.7.1/linux-amd64",
expected: pkg.Package{
Name: "jq",
Version: "1.7.1",
Type: "binary",
PURL: "pkg:generic/jq@1.7.1",
Locations: locations("jq"),
Metadata: metadata("jq-binary"),
},
},
}

for _, test := range tests {
Expand Down
70 changes: 70 additions & 0 deletions syft/pkg/cataloger/binary/classifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,76 @@ func DefaultClassifiers() []Classifier {
PURL: mustPURL("pkg:generic/curl@version"),
CPEs: singleCPE("cpe:2.3:a:haxx:curl:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "lighttpd-binary",
FileGlob: "**/lighttpd",
EvidenceMatcher: FileContentsVersionMatcher(
`\x00lighttpd/(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00`,
),
Package: "lighttpd",
PURL: mustPURL("pkg:generic/lighttpd@version"),
CPEs: singleCPE("cpe:2.3:a:lighttpd:lighttpd:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "proftpd-binary",
FileGlob: "**/proftpd",
EvidenceMatcher: FileContentsVersionMatcher(
`\x00ProFTPD Version (?P<version>[0-9]+\.[0-9]+\.[0-9]+[a-z]?)\x00`,
),
Package: "proftpd",
PURL: mustPURL("pkg:generic/proftpd@version"),
CPEs: singleCPE("cpe:2.3:a:proftpd:proftpd:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "zstd-binary",
FileGlob: "**/zstd",
EvidenceMatcher: FileContentsVersionMatcher(
`\x00v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00`,
),
Package: "zstd",
PURL: mustPURL("pkg:generic/zstd@version"),
CPEs: singleCPE("cpe:2.3:a:facebook:zstandard:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "xz-binary",
FileGlob: "**/xz",
EvidenceMatcher: FileContentsVersionMatcher(
`\x00xz \(XZ Utils\) (?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00`,
),
Package: "xz",
PURL: mustPURL("pkg:generic/xz@version"),
CPEs: singleCPE("cpe:2.3:a:tukaani:xz:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "gzip-binary",
FileGlob: "**/gzip",
EvidenceMatcher: FileContentsVersionMatcher(
`\x00(?P<version>[0-9]+\.[0-9]+)\x00`,
),
Package: "gzip",
PURL: mustPURL("pkg:generic/gzip@version"),
CPEs: singleCPE("cpe:2.3:a:gnu:gzip:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "sqlcipher-binary",
FileGlob: "**/sqlcipher",
EvidenceMatcher: FileContentsVersionMatcher(
`[^0-9]\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00`,
),
Package: "sqlcipher",
PURL: mustPURL("pkg:generic/sqlcipher@version"),
CPEs: singleCPE("cpe:2.3:a:zetetic:sqlcipher:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
{
Class: "jq-binary",
FileGlob: "**/jq",
EvidenceMatcher: FileContentsVersionMatcher(
`\x00(?P<version>[0-9]{1,3}\.[0-9]{1,3}(\.[0-9]+)?)\x00`,
),
Package: "jq",
PURL: mustPURL("pkg:generic/jq@version"),
CPEs: singleCPE("cpe:2.3:a:jqlang:jq:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
},
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions syft/pkg/cataloger/binary/test-fixtures/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,58 @@ from-images:
paths:
- /usr/bin/curl

- name: lighttpd
version: 1.4.76
images:
- ref: jitesoft/lighttpd:1.4.76-cgi@sha256:f5d4500bfb992a20ca39369ae1ca1d8a7a9463bb8c59ee8dd85ddb6d96fc9fc1
platform: linux/amd64
paths:
- /usr/local/sbin/lighttpd

- name: proftpd
version: 1.3.8b
images:
- ref: mekayelanik/proftpd-server-alpine:1.3.8b-r2@sha256:a1ef73a2de04999e53bf728b548ef9922febab8f5709037e40e0141cedcd66db
platform: linux/amd64
paths:
- /usr/sbin/proftpd

- name: zstd
version: 1.5.6
images:
- ref: danysk/zstd:1.5.6@sha256:5eceba085b3a399592755dd66a37b8adfb83538af3f56b51bec6e6cc955e3b5f
platform: linux/amd64
paths:
- /usr/local/bin/zstd

- name: xz
version: 5.6.2
images:
- ref: docker:27.2.1@sha256:c51fa20028ff6590588d9ed97d3b16865d503a3d7228aa885871c5c292afa5ca
platform: linux/amd64
paths:
- /usr/bin/xz

- name: gzip
version: 1.12
images:
- ref: ubuntu:24.04@sha256:d35dfc2fe3ef66bcc085ca00d3152b482e6cafb23cdda1864154caf3b19094ba
platform: linux/amd64
paths:
- /usr/bin/gzip

- name: sqlcipher
version: 4.5.5
images:
- ref: yspreen/sqlcipher@sha256:93189cc465661f16ad23f3ace4206179bdd19967deaf08c54da5ac1e34bb6fb7
platform: linux/amd64
paths:
- /usr/local/bin/sqlcipher

- name: jq
version: 1.7.1
images:
- ref: efrecon/jq:1.7.1@sha256:0ad05e2e6d1dea5fe0852ecc23114eb768d60c4ce0985d729eb958809e7f31dd
platform: linux/amd64
paths:
- /usr/local/bin/jq

0 comments on commit 6a95a5f

Please sign in to comment.