Skip to main content

ThreatCheck-Py

Started as a python port of Rasta-Mouse's ThreatCheck.

A tool to find AV signatures in files.

Requirements

  • Python 3.8 or higher
  • Windows OS (for Defender and AMSI scanners)

Supported Scanners

File Scanners

  • Defender
  • Amsi
  • Clamav

Process Scanners:

  • Yara

Installation

From PyPi

pip install threatcheck-py

From Source

git clone https://github.com/ruvolof/threatcheck-py.git
cd threatcheck-py
pip install -e .

Usage

Command Line Options

$ threatcheck --help
usage: threatcheck [-h] [-e {defender,amsi,clamav,yara}] (-f FILE | -u URL | -d DIRECTORY | -p PID) [-r RULES] [--debug] [--version]

Identify AV signatures in files

options:
  -h, --help            show this help message and exit
  -e, --engine {defender,amsi,clamav,yara}
                        Scanning engine (default: defender)
  -f, --file FILE       Analyze a file on disk
  -u, --url URL         Analyze a file from a URL
  -d, --directory DIRECTORY
                        Analyze all files in a directory
  -p, --pid PID         Analyze a process by PID
  -r, --rules RULES     Path to YARA rules directory. Will recursively search for all .yar and .yara files.
  --debug               Enable debug output
  --version             show program's version number and exit

As a Python library

All scanners share a common interface: instantiate one, then call analyze(file_bytes=...) (or analyze(pid=...) for YARA) and inspect the returned ScanResult.

from pathlib import Path
from threatcheck import DefenderScanner, ScanStatus

scanner = DefenderScanner()
result = scanner.analyze(file_bytes=Path('sample.exe').read_bytes())

if result.malicious:
    print(f'Threat: {result.signature}')
    print(f'Bad bytes end at offset 0x{result.end_offset:X}')
elif result.status == ScanStatus.ERROR:
    print(f'Scan failed: {result.error_message}')
else:
    print('Clean')

AmsiScanner and ClamAVScanner use the same pattern. YaraScanner takes a rules_path and can scan a running process as well as file bytes:

from threatcheck import YaraScanner

scanner = YaraScanner(rules_path='/path/to/rules')
result = scanner.analyze(pid=1234)

for match in result.matches or []:
    print(f'Rule: {match.rule}')
    for s in match.strings:
        print(f'  {s.identifier} @ 0x{s.offset:X}: {s.matched_data!r}')

ScanResult exposes:

  • status — a ScanStatus (NO_THREAT_FOUND, THREAT_FOUND, FILE_NOT_FOUND, TIMEOUT, ERROR)
  • malicious — True when status == THREAT_FOUND
  • success — True when the scan completed (threat found or not)
  • signature — signature name, when the engine reports one (Defender, ClamAV)
  • matches — list of YaraMatch when using YaraScanner
  • offending_bytes / end_offset — populated by split scanners (Defender, AMSI, ClamAV) that bisect the file to locate bad bytes
  • error_message — set when status == ERROR

Defender Test Environment Setup

It is recommended to force autosubmission of samples to never send them, or the amount of notification can be overwhelming.

Method 1: PowerShell

Open and administrative PowerShell session and type the following:

Set-MpPreference -SubmitSamplesConsent 2

Method 2: Group Policies

This can be forced through group policies:

  1. Open Local Group Policy Editor (gpedit.msc)
  2. Navigate to Computer Configuration > Administrative Templates > Windows Components > Microsoft Defender Antivirus > MAPS
  3. Double click on "Send file samples when further analysis is required"
  4. Set it to "Enabled" and in the bottom-left panel select "Never send"

Exceptions

All other Defender settings can be left on as long:

  1. There's a path exception in place for the original location of your samples (otherwise real-time protection will prevent the initial loading of the files).
  2. (Maybe?) The original location has to be on your C drive. In my experience Defender ignores exception for external drives and I run in problem 1 above.

Credits

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for threatcheck-py 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for threatcheck-py 0.4.1
File Size Uploaded Provenance
threatcheck_py-0.4.1.tar.gz 34.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for threatcheck-py 0.4.1
File Interpreter ABI Platform
threatcheck_py-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 61.9 kB

Release files / threatcheck_py-0.4.1.tar.gz

Download URL threatcheck_py-0.4.1.tar.gz
Size 34.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ffaf3ff3995ce2d24bdf517b63a7b9def254406692feeabd6b28e848e68a607a
BLAKE2b-256 checksum
How to use checksums
210ffc4933409a12fd280118e6ad3c229b77a4521cbaeb97d1ed6030532d8993
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / threatcheck_py-0.4.1-py3-none-any.whl

Download URL threatcheck_py-0.4.1-py3-none-any.whl
Size 27.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34452c8be393dbbf484c228e94754af270df4cf7d851dc5f19af85d298164db2
BLAKE2b-256 checksum
How to use checksums
518b2085343eadc00b8f501de63ce0412907181c47d8029608f32f05dc609262
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Security for threatcheck-py 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for threatcheck_py-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page