-
Notifications
You must be signed in to change notification settings - Fork 627
fix(yara): modified Source0 with malware-scanner-tripping fixture stripped #17097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PawelWMS
wants to merge
2
commits into
tomls/base/main
Choose a base branch
from
pawelwi/yara-strip-obfuscated
base: tomls/base/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # yara — strip benign-but-scanner-tripping fixture from upstream tarball. | ||
| # | ||
| # Background | ||
| # ---------- | ||
| # An automated malware scan in the package signing pipeline rejects | ||
| # `tests/oss-fuzz/dotnet_fuzzer_corpus/obfuscated` inside the upstream | ||
| # `yara-4.5.4.tar.gz` tarball. The file is a deliberately obfuscated | ||
| # .NET binary used as an oss-fuzz seed-corpus input for YARA's `.NET` | ||
| # parser fuzzer; it is benign but matches generic .NET-obfuscator | ||
| # heuristics by design. | ||
| # | ||
| # The `*_fuzzer.cc` oss-fuzz harnesses (and their `*_fuzzer_corpus/` | ||
| # directories) are NOT referenced from upstream's `Makefile.am`, so the | ||
| # autotools `make check` driver does not exercise them. Removing | ||
| # `tests/oss-fuzz/dotnet_fuzzer_corpus/obfuscated` (and, optionally, | ||
| # the rest of the dotnet fuzzer corpus) does not affect the Azure Linux | ||
| # build or `%check`. | ||
| # | ||
| # This script repacks the upstream tarball with the offending file | ||
| # stripped, then prints the SHA512 of the modified artefact for use in | ||
| # `base/comps/yara/yara.comp.toml`'s `source-files` block. The | ||
| # modified tarball must be uploaded to the Azure Linux modified-source | ||
| # blob storage; its blob URL becomes the `source-files.origin.uri` in | ||
| # the comp TOML. | ||
| # | ||
| # Reproducibility notes | ||
| # --------------------- | ||
| # - The script uses `tar --sort=name --mtime=` flags to produce a | ||
| # byte-deterministic output, so re-running on the same upstream | ||
| # tarball must always yield the same SHA512. | ||
| # - `gzip -n` strips mtime/filename metadata from the gzip header for | ||
| # the same reason. | ||
| # | ||
| # Output location | ||
| # --------------- | ||
| # The script writes its outputs to `base/build/work/scratch/yara/` | ||
| # (resolved relative to the repository root). This path is covered by | ||
| # the repository's top-level `.gitignore` via `build/`, so no | ||
| # component-level `.gitignore` is needed and no script artefact can be | ||
| # accidentally committed. | ||
| # | ||
| # Usage: | ||
| # bash modify_source.sh | ||
| # | ||
| # Outputs (under base/build/work/scratch/yara/): | ||
| # yara-4.5.4-azl-stripped.tar.gz | ||
| # yara-4.5.4-azl-stripped.tar.gz.sha512 | ||
| # | ||
| # After running upload `yara-4.5.4-azl-stripped.tar.gz` as the blob payload at | ||
| # the lookaside URL pattern (modified container) for filename | ||
| # `yara-4.5.4.tar.gz`. The exact URL is printed by this script. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| UPSTREAM_URL="https://github.com/VirusTotal/yara/archive/v4.5.4.tar.gz" | ||
| ORIGINAL_NAME="yara-4.5.4.tar.gz" | ||
| ORIGINAL_SHA512="b1da40636f9e55bb07cc911479e6dfa8dc7a4fa3f6b9f10b9f669d741d7af51a1d31e044f9842ec3ab9c6ac9788fbdb89a1686c9e3f22f68d1f9e5fb3db22167" | ||
| MODIFIED_NAME="yara-4.5.4-azl-stripped.tar.gz" | ||
| EXTRACTED_DIRNAME="yara-4.5.4" | ||
|
|
||
| # Files to remove from the upstream tarball. | ||
| declare -a STRIP_PATHS=( | ||
| "${EXTRACTED_DIRNAME}/tests/oss-fuzz/dotnet_fuzzer_corpus/obfuscated" | ||
| ) | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$(realpath "$0")")" && pwd)" | ||
| REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)" | ||
| WORKDIR="${REPO_ROOT}/base/build/work/scratch/yara" | ||
| mkdir -p "${WORKDIR}" | ||
| cd "${WORKDIR}" | ||
|
|
||
| echo "[1/5] Downloading ${ORIGINAL_NAME} from upstream into ${WORKDIR}" | ||
| curl -fsSL --retry 3 -o "${ORIGINAL_NAME}" "${UPSTREAM_URL}" | ||
|
|
||
| echo "[2/5] Verifying original SHA512" | ||
| COMPUTED_ORIGINAL_SHA512=$(sha512sum "${ORIGINAL_NAME}" | awk '{print $1}') | ||
| if [[ "${COMPUTED_ORIGINAL_SHA512}" != "${ORIGINAL_SHA512}" ]]; then | ||
| echo "ERROR: upstream SHA512 mismatch" >&2 | ||
| echo " expected: ${ORIGINAL_SHA512}" >&2 | ||
| echo " computed: ${COMPUTED_ORIGINAL_SHA512}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "[3/5] Extracting" | ||
| rm -rf "${EXTRACTED_DIRNAME}" | ||
| tar -xzf "${ORIGINAL_NAME}" | ||
|
|
||
| echo "[4/5] Stripping flagged paths" | ||
| for p in "${STRIP_PATHS[@]}"; do | ||
| if [[ ! -e "${p}" ]]; then | ||
| echo "ERROR: expected path not present in upstream: ${p}" >&2 | ||
| exit 1 | ||
| fi | ||
| rm -v "${p}" | ||
| done | ||
|
|
||
| echo "[5/5] Repacking deterministically as ${MODIFIED_NAME}" | ||
| # --sort=name : deterministic file ordering | ||
| # --mtime : pin mtime to a fixed epoch so the output is reproducible | ||
| # --owner=0 --group=0 --numeric-owner : strip uid/gid/uname/gname | ||
| # gzip -n : do not store the mtime/filename in the gzip header | ||
| rm -f "${MODIFIED_NAME}" | ||
| tar --sort=name \ | ||
| --mtime='2024-01-01 00:00:00 UTC' \ | ||
| --owner=0 --group=0 --numeric-owner \ | ||
| -cf - "${EXTRACTED_DIRNAME}" | gzip -n -9 > "${MODIFIED_NAME}" | ||
|
|
||
| MODIFIED_SHA512=$(sha512sum "${MODIFIED_NAME}" | awk '{print $1}') | ||
| echo "${MODIFIED_SHA512} ${MODIFIED_NAME}" > "${MODIFIED_NAME}.sha512" | ||
|
|
||
| cat <<EOF | ||
|
|
||
| ================================================================ | ||
| DONE | ||
| modified tarball: ${WORKDIR}/${MODIFIED_NAME} | ||
| SHA512: ${MODIFIED_SHA512} | ||
| ================================================================ | ||
|
|
||
| Next steps: | ||
| 1. Make sure you are logged in to Azure (one-time per shell): | ||
| az login | ||
| 2. Upload the modified tarball with this ready-to-paste command | ||
| (uploads to the lookaside 'repo' container under the | ||
| 'pkgs_modified/' prefix at the exact path | ||
| base/comps/yara/yara.comp.toml's source-files.origin.uri expects): | ||
|
|
||
| az storage blob upload \\ | ||
| --auth-mode login \\ | ||
| --account-name azltempstaginglookaside \\ | ||
| --container-name repo \\ | ||
| --name "pkgs_modified/yara/yara-4.5.4.tar.gz/sha512/${MODIFIED_SHA512}/yara-4.5.4.tar.gz" \\ | ||
| --file "${WORKDIR}/${MODIFIED_NAME}" | ||
|
|
||
| 3. The hash + URI in base/comps/yara/yara.comp.toml are | ||
| already populated for SHA512 ${MODIFIED_SHA512:0:16}...; if the | ||
| SHA512 above does NOT match, this means the regeneration was not deterministic. | ||
| This requires further investigation and the comp TOML must NOT be updated with | ||
| the new hash/URI until the root cause of non-determinism is identified and resolved. | ||
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [components.yara] | ||
|
|
||
| # Upstream Fedora dist-git ships a `sources` file with the hash of | ||
| # the original `yara-4.5.4.tar.gz` tarball. Since we want to serve | ||
| # a *modified* tarball under the SAME filename (so the spec's | ||
| # Source0 line does not need to change), drop the upstream | ||
| # `sources` file before the `source-files` block below re-creates | ||
| # it with the modified-tarball SHA512. | ||
| [[components.yara.overlays]] | ||
| description = "Drop upstream Fedora `sources` file so the modified-tarball SHA512 in `source-files` below replaces (rather than conflicts with) the original `yara-4.5.4.tar.gz` entry." | ||
| type = "file-remove" | ||
| file = "sources" | ||
|
|
||
| [[components.yara.source-files]] | ||
| filename = "yara-4.5.4.tar.gz" | ||
| hash = "57d3388dc9a84f58769679e26624be852d7c83e403ed60a21ae3ba4e1da9162dbc9bacf53d439793df67f4bc6a7fd38d600f10052df2e62255aed50687d2754a" | ||
| hash-type = "SHA512" | ||
| # The URI below mirrors the `lookaside-base-uri` pattern from | ||
| # `overrides/fedora.distro.azl.sources.toml` but routes to the | ||
| # `pkgs_modified` first path segment (instead of `pkgs`) inside | ||
| # the same `repo` container, so the source-fetch pipeline can | ||
| # serve the locally-modified tarball alongside upstream lookaside | ||
| # content while keeping all locally-modified tarballs trivially | ||
| # enumerable under one prefix. Pattern: | ||
| # https://azltempstaginglookaside.blob.core.windows.net/repo/pkgs_modified/$pkg/$filename/$hashtype/$hash/$filename | ||
| # The maintainer must upload `yara-4.5.4-azl-stripped.tar.gz` | ||
| # (produced by `modify_source.sh` in this directory; its output | ||
| # lands at `base/build/work/scratch/yara/`) to this blob path | ||
| # before the component can fetch its source. | ||
| origin = { type = "download", uri = "https://azltempstaginglookaside.blob.core.windows.net/repo/pkgs_modified/yara/yara-4.5.4.tar.gz/sha512/57d3388dc9a84f58769679e26624be852d7c83e403ed60a21ae3ba4e1da9162dbc9bacf53d439793df67f4bc6a7fd38d600f10052df2e62255aed50687d2754a/yara-4.5.4.tar.gz" } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| SHA512 (yara-4.5.4.tar.gz) = b1da40636f9e55bb07cc911479e6dfa8dc7a4fa3f6b9f10b9f669d741d7af51a1d31e044f9842ec3ab9c6ac9788fbdb89a1686c9e3f22f68d1f9e5fb3db22167 | ||
| SHA512 (yara-4.5.4.tar.gz) = 57d3388dc9a84f58769679e26624be852d7c83e403ed60a21ae3ba4e1da9162dbc9bacf53d439793df67f4bc6a7fd38d600f10052df2e62255aed50687d2754a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if we can do better than this or a pattern replacement in the
sourcesfile.