Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into chore/refactor-cach…
Browse files Browse the repository at this point in the history
…e-to-lib
  • Loading branch information
kzantow committed Sep 20, 2024
2 parents 9fdc999 + 6a95a5f commit d25b33a
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .binny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tools:
# used to release all artifacts
- name: goreleaser
version:
want: v2.3.1
want: v2.3.2
method: github-release
with:
repo: goreleaser/goreleaser
Expand Down Expand Up @@ -103,15 +103,15 @@ tools:
# used for running all local and CI tasks
- name: task
version:
want: v3.39.0
want: v3.39.1
method: github-release
with:
repo: go-task/task

# used for triggering a release
- name: gh
version:
want: v2.56.0
want: v2.57.0
method: github-release
with:
repo: cli/cli
Expand Down
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/[email protected]",
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/[email protected]",
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/[email protected]",
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/[email protected]",
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/[email protected]",
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/[email protected]",
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/[email protected]",
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/[email protected]",
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
7 changes: 6 additions & 1 deletion syft/pkg/cataloger/binary/test-fixtures/capture-snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ if ! command -v xxd &> /dev/null; then
exit 1
fi

# check if xargs is even installed
if ! command -v xargs &> /dev/null; then
echo "xargs not found. Please install xargs."
exit 1
fi

PATTERN=${SEARCH_FOR:-$VERSION}

Expand Down Expand Up @@ -116,7 +121,7 @@ while $CONTINUE_LOOP; do
fi

# search for the pattern in the binary file and capture the offset
OFFSET=$(echo "${SELECTED_RESULT}" | cut -d ' ' -f 1)
OFFSET=$(echo "${SELECTED_RESULT}" | xargs | cut -d ' ' -f 1)

if [ -z "$OFFSET" ]; then
echo "Pattern not found."
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 d25b33a

Please sign in to comment.