A Go library and CLI for detecting automatic execution entry points in software packages. It inspects package archives for install hooks, build scripts and plugins without executing package code. Each finding identifies the mechanism, its phase and the archive member that supplies the evidence. A finding describes a capability. Legitimate packages use these features too, and whether the code runs depends on the installation method and the client's script policy.
The module requires Go 1.27.4 or later. Use go get to add the library to a project.
go get github.com/git-pkgs/malwareInstall the CLI with go install github.com/git-pkgs/malware/cmd/malware@latest. From a local checkout, use go install ./cmd/malware.
Pass a versioned PURL to download a release, or pass the ecosystem and a local artifact path. Both commands below report the same install hook in esbuild.
malware pkg:npm/esbuild@0.24.0
malware npm esbuild-0.24.0.tgz[{"mechanism":"npm.postinstall","phase":"install","path":"package/package.json","field":"scripts.postinstall","value":"node install.js"}]A single scan writes a JSON array to standard output. An empty array means the rules applied and found no entry points. Exit status 3 means no rules apply to the ecosystem or artifact format. An inspection error exits with status 1, and a usage error exits with status 2. Diagnostics go to standard error.
PURL input supports npm, Cargo, PyPI, Composer, Dart pub, Hex, NuGet and RubyGems on their public registries. Use pkg:composer/composer/installers@v2.3.0 for a Composer release or pkg:gem/racc@1.8.1 for a gem. The platform qualifier selects a gem build. PyPI defaults to the source distribution. Use file_name to select a specific distribution if a release has several. CRAN PURLs resolve current source releases. Pass a local archive for older CRAN releases, CPAN distributions and Crystal packages.
Pass a CycloneDX document (JSON or XML) or an SPDX document (JSON or tag-value). Use - to read from standard input.
malware sbom inventory.spdx.json
git pkgs sbom | malware sbom -The JSON array contains one result per parsed package, in document order. Components that refer to the same registry artifact share a scan. Each result carries its component ID when supplied, its declared PURL, and one of five statuses.
| Status | Meaning |
|---|---|
matched |
The artifact has findings, with the mechanism, phase and evidence for each. |
no_match |
The rules applied and found no entry points. |
no_applicable_rules |
The detector has no rules for the ecosystem or distribution format. |
unresolved |
The component could not be mapped to a registry artifact, for example because it lacks a versioned PURL. |
scan_error |
Download, checksum verification or inspection failed. |
The filename and SHA-256 identify the downloaded bytes. An SPDX package filename or PURL file_name selects a distribution. A PyPI artifact SHA-256 can also select a wheel or source archive. Without either selector, PyPI defaults to the source distribution. The scanner checks supplied SHA-256, SHA-384 and SHA-512 values. A component with only other checksum algorithms is unresolved.
A completed batch exits with status 0 even when individual packages have errors. Invalid input exits with status 1. Go callers can process the same results with malware.InspectSBOM(ctx, documentBytes).
Go callers can use malware.InspectPURL(ctx, "pkg:npm/esbuild@0.24.0") or pass an open file or a bytes.Reader to malware.Inspect. Pass the original artifact filename so the detector can distinguish a Python wheel from a source distribution. Use errors.Is(err, malware.ErrNoApplicableRules) to distinguish a coverage gap from an inspection failure.
import (
"context"
"os"
"github.com/git-pkgs/malware"
)
func inspectFile(ctx context.Context, ecosystem, filename string) ([]malware.Finding, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return nil, err
}
return malware.Inspect(ctx, ecosystem, filename, f, info.Size())
}Pass the baseline first and the candidate second. You can compare any two published versions of the same package or supply two local archives.
malware diff pkg:npm/core-js@2.5.7 pkg:npm/core-js@2.6.12
malware diff npm ./core-js-2.5.7.tgz ./core-js-2.6.12.tgzFor this pair, introduced contains the npm.postinstall finding from the newer tarball. removed contains findings for mechanisms that disappeared. If a mechanism remains in the same phase but its evidence changes, changed includes the findings from both versions under before and after. Each change also lists the individual findings in added and removed. Adding a second Composer plugin class puts just that class in changed[].added. Reordering classes preserves their original and new order in before and after and leaves both evidence deltas empty. Edits to the contents of a script at the same path are outside this comparison.
The diff ignores changes to the enclosing archive directory and preserves the original paths in its output. Gem comparisons check the platform recorded inside each artifact. A platform mismatch returns an error that identifies both builds. Three empty top-level arrays mean both scans succeeded and their signals matched. If either input fails inspection or lacks coverage, the command returns the scan error and emits no diff.
Go callers can use malware.DiffPURLs(ctx, before, after) or malware.Diff(ctx, ecosystem, before, after) with two malware.Artifact values. Each artifact takes a filename, an io.ReaderAt and its size in bytes.
| Ecosystem | Entry points in the artifact | When they apply |
|---|---|---|
| npm | scripts.preinstall, scripts.install, scripts.postinstall |
Installing a published dependency with lifecycle scripts enabled |
| npm | Root binding.gyp |
npm's implicit native build, unless an install or preinstall script overrides it or gypfile is false |
| PyPI | Root setup.py |
Building a source distribution with setuptools, including its default backend |
| PyPI | An in-tree PEP 517 backend | The build imports a Python module supplied on backend-path |
| PyPI | tool.poetry.build |
Poetry's build backend runs the declared script when building the distribution |
| Cargo | Root build.rs or a script selected by package.build |
Cargo builds the crate with build scripts enabled. A false package.build disables the script |
RubyGems (gem or rubygems) |
A declared extensions build file in the gem payload |
RubyGems builds the extension during installation |
| RubyGems | rubygems_plugin.rb directly under a gem require path |
RubyGems loads installed plugins on a later invocation (post-install phase) |
| Composer | A composer-plugin package requiring composer-plugin-api and declaring one or more plugin classes in extra.class |
Composer activates the plugin during installation when client policy allows it |
| NuGet | Package-ID-named .props and .targets files in build, buildMultiTargeting or buildTransitive, including framework-specific subdirectories |
MSBuild imports the selected assets for the consuming project and target framework |
| CRAN | Executable root configure on Unix, or configure.ucrt in preference to configure.win on current Windows R |
R CMD INSTALL configures a source package with configure scripts enabled |
| CPAN | Root Makefile.PL or Build.PL |
A Perl installer runs the selected configuration script during a source build. A distribution can ship both alternatives. A client using static installation can skip them. |
| Hex | Root rebar.config with literal pre_hooks or post_hooks for compile |
Rebar3 compiles the dependency on a platform matching the hook. The evidence includes the command and any platform expression. |
| Dart pub | Root hook/build.dart and hook/link.dart |
The Dart SDK runs build hooks during supported builds and link hooks when bundling an application |
| Crystal | scripts.postinstall in shard.yml |
Shards installs the dependency with postinstall hooks enabled |
The npm rules apply to registry tarballs. Git dependency preparation, publishing hooks and manually invoked scripts have different triggers. For Python, installing a wheel skips the source build. Wheels and eggs return ErrNoApplicableRules. The RubyGems rules read the packaged specification and check the files in data.tar.gz. The Composer rule covers dependency plugins. Root-project scripts have a separate trigger. See the RubyGems specification, RubyGems plugin guide and Composer plugin guide.
Hex packages with only a Mix build or with a dynamic rebar.config.script return ErrNoApplicableRules. The Hex rule covers top-level shell hooks. Profile overrides and provider hooks are outside its scope. Rebar3 hook reference
Each ecosystem has a package under rules. Its detector implements Detect(*rules.Artifact) ([]rules.Finding, error). The shared artifact reader indexes archive members, accepts one enclosing directory and bounds manifest reads to 4 MiB. The detector reads declarations and filenames without launching a package manager or running package code.
The rule selection draws on Andrew Nesbitt's posts about package manager threat models, package manager magic files and install-script allowlists.
Build the module and run the same checks as CI from the repository root.
go build ./...
go test -race ./...
go vet ./...- git-pkgs/archives reads package archives.
- git-pkgs/manifests parses package manager manifests.
- git-pkgs/registries resolves release artifacts and downloads them for PURL scans.
MIT.
The detector found install hooks in 80 of 128 Datadog npm packages (62.5%), compared with 0 of 128 npm packages sampled from the css-loader lockfile. The most common hook in the Datadog sample was preinstall (52 packages), followed by postinstall (31). Packages can declare both.
For PyPI source distributions, 99 of 107 Datadog packages (92.5%) had a finding, compared with 43 of 110 comparison packages (39.1%). All 99 Datadog findings came from setup.py. Of the 128 selected Datadog PyPI packages, 17 contained wheels outside current rule coverage and four could not be evaluated. The comparison also found Cargo build scripts in 22 of 128 crates (17.2%) and Shards postinstall hooks in 0 of 13 Crystal packages.
Among releases with a recoverable preceding artifact, 10 of 28 npm releases and one of six PyPI source releases introduced an execution mechanism. Eight of the 11 comparable npm releases labeled as compromises introduced a hook. Static review of the 48 unmatched npm packages found 19 with a concrete module, API or browser execution path and no confirmed missing package-local install rule.
These are package samples. A live feed weights each new release separately, and its mix of package types and versions will affect review volume. Sampling details, mechanism counts and individual outcomes are in the evaluation report.