Hunt Hypothesis
This detection rule identifies adversaries attempting to compromise Python supply chains by distributing malicious or counterfeit packages on the PyPI repository. Proactively hunting for these anomalies in Azure Sentinel is critical to prevent the installation of compromised dependencies that could serve as an initial foothold for lateral movement and code execution within the organization’s cloud infrastructure.
YARA Rule
rule MALW_FakePyPI
{
meta:
description = "Identifies fake PyPI Packages."
author = "@bartblaze"
reference = "http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/"
date = "2017-09"
tlp = "white"
strings:
$ = "# Welcome Here! :)"
$ = "# just toy, no harm :)"
$ = "[0x76,0x21,0xfe,0xcc,0xee]"
condition:
all of them
}
Deployment Notes
This YARA rule can be deployed in the following contexts:
- Microsoft Defender for Endpoint — Custom indicators / advanced hunting
- Email Gateway — Attachment scanning
- File Share Monitoring — Periodic scanning of shared drives
- YARA CLI — Manual threat hunting on endpoints
References
False Positive Guidance
Here are 4 specific false positive scenarios for the “Identifies fake PyPI Packages” detection rule, tailored for a legitimate enterprise environment:
-
CI/CD Pipeline Dependency Installation
- Scenario: Automated build agents (e.g., Jenkins or GitHub Actions runners) frequently install transient dependencies during nightly integration tests. These builds often pull packages from internal mirrors that might have slightly different metadata signatures than the public PyPI registry, triggering a “fake” flag due to signature mismatches or unusual versioning patterns in test environments.
- Filter/Exclusion: Exclude traffic originating from known CI/CD subnet ranges (e.g.,
10.20.30.0/24) and restrict the rule to only trigger on packages installed by user accounts rather than service accounts like jenkins-agent or github-runner.
-
Internal Artifact Repository Synchronization
- Scenario: Enterprise artifact repositories (such as JFrog Artifactory, Sonatype Nexus, or AWS CodeArtifact) periodically synchronize with the public PyPI. During these sync windows, internal proxy servers may download and re-publish packages using their own signing keys or metadata wrappers to enforce compliance policies, which the detection logic might misinterpret as a “fake” package due to non-standard publisher IDs.
- Filter/Exclusion: Create an allowlist for specific hostnames associated with the organization’s artifact management tools (e.g.,
artifactory.internal.corp, nexus-prod.io) and exclude any events where the source IP matches these internal proxy servers.
-
Scheduled Security Scanning Jobs
- Scenario: Scheduled vulnerability scanning jobs using tools like Snyk, Mend (formerly WhiteSource), or Black Duck actively probe the network by simulating package installations to assess supply chain risks. These scanners often download “shadow” versions of packages or utilize test registries that mimic PyPI