Malduck
Malduck is a Python utility library designed for malware researchers, offering a comprehensive suite of tools for malware analysis. It provides functionalities for cryptography, compression, memory model objects (for PE/ELF/raw files and IDA dumps), a modular extraction engine for configuration, fixed integer types, and string operations. Currently at version 4.4.1, the project is actively maintained with frequent updates addressing bugfixes and introducing new features.
Common errors
-
YaraError: rules are not compatible with this version of YARA-Python
cause An incompatibility between the installed `malduck` version and your `yara-python` version, especially around `yara-python 4.3.0`.fixIf using Malduck v4.3.1, downgrade `yara-python` to `4.2.3` (`pip install "yara-python==4.2.3"`). If using a newer Malduck version, ensure `yara-python` is updated (`pip install --upgrade yara-python`). -
AttributeError: module 'malduck.dnpe' has no attribute 'dnfile'
cause The `dnpe` module's typing or dependencies were incorrectly defined or fixed in a patch release.fixUpgrade `malduck` to version 4.4.1 or later to get the fix: `pip install --upgrade malduck`. -
TypeError: __init__() missing 1 required positional argument: 'parent' (or similar errors with Extractor decorators)
cause When defining custom extractor modules, the class or its methods are not correctly initialized or decorated according to `malduck.extractor` API changes in v4.0.0.fixEnsure your custom `Extractor` class inherits from `malduck.Extractor` and its methods are decorated correctly (e.g., `@Extractor.string('rule_name')`). Consult the official Malduck extractor documentation for the correct method signatures and decorator usage for your specific version.
Warnings
- breaking Minimum Python version changed from 3.6 to 3.8. Users on older Python versions will encounter installation or runtime errors.
- gotcha Compatibility issues with `yara-python` version 4.3.0. Malduck v4.3.1 strictly pinned `yara-python` to `4.2.3` but later versions fixed compatibility with `>=v4.3.0`.
- breaking Extractor methods in `malduck.extractor` require explicit decorators (e.g., `@Extractor.extractor`, `@Extractor.string`) prior to v4.0.0. After v4.0.0, the decorator application order and arguments changed.
- gotcha The `pefile` dependency was bumped to `>=2022.5.30` in v4.3.0, and a `FastPE` patch for `pefile.PE` was removed. Older `pefile` versions might cause unexpected behavior or missing functionality.
Install
-
pip install malduck
Imports
- aes
from malduck import aes
- aplib
from malduck import aplib
- DWORD
from malduck import DWORD
- Extractor
from malduck.extractor import Extractor
from malduck import Extractor
- procmempe
from malduck import procmempe
- Yara
from malduck.yara import Yara
Quickstart
from malduck import aes
key = b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10'
iv = b'\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20'
plaintext = b'This is a secret message.'
ciphertext = aes.cbc.encrypt(key, iv, plaintext)
decrypted_text = aes.cbc.decrypt(key, iv, ciphertext)
print(f"Original Plaintext: {plaintext}")
print(f"Ciphertext (hex): {ciphertext.hex()}")
print(f"Decrypted Text: {decrypted_text}")