Skip to main content

Pyrattle

Overview

Pyrattle is a Python package designed to interface with Windows Defender, enabling users to perform various malware protection tasks, such as scanning for threats, updating signature definitions, and managing dynamic signatures. It leverages Windows Defender's command-line utility (MpCmdRun.exe) to execute its functions.

Features

  • Perform different types of scans (Quick, Full, Custom)
  • Update malware protection signatures from UNC file shares or the Microsoft Malware Protection Center (MMPC)
  • Add, list, and remove dynamic signatures for enhanced malware protection
  • Flexible configuration for scan options including remediation, boot sector scanning, and more

Installation

pip install pyrattle

Usage

Importing the Package

from pyrattle import PyDefender, ScanType

Initializing PyDefender

scanner = PyDefender()
# or
scanner = PyDefender(executable_path="C:\\Program Files\\Windows Defender\\MpCmdRun.exe")

Performing a Scan

It can perform multiple kinds of scan:

  • Quick Scan

    scan_result = scanner.scan(scan_type=ScanType.QUICK)
    
  • Full Scan

    scan_result = scanner.scan(scan_type=ScanType.FULL)
    
  • Custom Scan

    scan_result = scanner.scan(scan_type=ScanType.CUSTOM)
    print(scan_result)
    

Updating Signature Definitions

  • From UNC File Share

    success = scanner.updateSignature(unc=True, unc_path="\\\\path\\to\\unc\\share")
    
  • From Microsoft Malware Protection Center

    success = scanner.updateSignature(mmpc=True)
    

Managing Dynamic Signature

  • Adding a Dynamic Signature

    success = scanner.addDynamicSignature(path="C:\\path\\to\\signature\\file")
    print("Signature added successfully:", success)
    
  • Listing All Dynamic Signatures

    signatures = scanner.listAllDynamicSignatures()
    print("Dynamic Signatures:", signatures)
    
  • Removing a Dynamic Signature

    success = scanner.removeDynamicSignature(signature_id="signature_id")
    print("Signature removed successfully:", success)
    

API Reference

PyDefender

scan(scan_type=ScanType.DEFAULT, file=None, disable_remediation=False, boot_sector_scan=False, timeout=30, is_cancel=False)

Performs a system scan based on the provided parameters.

  • scan_type: The type of scan to perform (ScanType.DEFAULT, ScanType.QUICK, ScanType.FULL, ScanType.CUSTOM).
  • file: The file or directory to be scanned (required for ScanType.CUSTOM).
  • disable_remediation: If True, disables remediation actions for custom scans.
  • boot_sector_scan: If True, enables boot sector scanning (only valid for custom scans).
  • timeout: Timeout in days (maximum value is 30).
  • is_cancel: If True, attempts to cancel any ongoing quick or full scan.

Returns a ScanResult object if successful.

updateSignature(unc=False, unc_path=None, mmpc=False)

Updates the signature definitions for malware protection.

  • unc: If True, performs the update from a UNC file share.
  • unc_path: The path to the UNC file share (required if unc is True).
  • mmpc: If True, performs the update directly from the MMPC.

Returns True if the update was successful, False otherwise.

addDynamicSignature(path)

Adds a dynamic signature for malware protection from the specified path.

  • path: The path to the dynamic signature file.

Returns True if the dynamic signature was added successfully, False otherwise.

listAllDynamicSignatures()

Lists all dynamic signatures currently in use.

Returns a list of dynamic signatures.

removeDynamicSignature(signature_id)

Removes a dynamic signature based on the provided signature ID.

  • signature_id: The ID of the signature to be removed.

Returns True if the signature was removed successfully, False otherwise.

Contributing

Contributions are welcome! Please submit a pull request or open an issue on GitHub.

License

This project is licensed under the MIT License.

Metadata

Release files for pyrattle 0.2.0

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

Source distribution (sdist)

Source distribution for pyrattle 0.2.0
File Size Uploaded
pyrattle-0.2.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyrattle 0.2.0
File Interpreter ABI Platform
pyrattle-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / pyrattle-0.2.0.tar.gz

Download URL pyrattle-0.2.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
214be302811de973ee2c802367c6617b9eda6620751ee676eb4e0819c1bd8cbe
BLAKE2b-256 checksum
How to use checksums
717bebf4069f89312c76aa171be0697d718da47c0597a4c5a68c0e3cb0741e89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Windows/10

Release files / pyrattle-0.2.0-py3-none-any.whl

Download URL pyrattle-0.2.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e89cad2c0e8f7056d09643d05ffaa7c645a3b8ed88da02d52b6719d8027b0ece
BLAKE2b-256 checksum
How to use checksums
20b03c787d74ed5e0e392647eb860495a65d051342ba387673f2135cfe2300ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Windows/10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

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