Skip to main content

A Python package and command line utility for scanning emails with YARA rules

Project description

yaramail

PyPI PyPI - Downloads

yaramail is a Python package and command line utility for scanning emails with YARA rules. It is Ideal for automated triage of phishing reports.

Features

yaramail scans all parts of an email via API or CLI

  • Headers
    • Removes header indents by default for consistent scanning
  • Plain text and HTML body content
    • Converts body content to Markdown by default for consistent scanning
  • Attachments
    • Raw file content
    • Emails attached to emails
    • Non-password-protected ZIP file contents, including nested ZIP files
    • PDF document text

CLI

usage: A YARA scanner for emails [-h] [-V] [-v] [--output OUTPUT]
                                 [--rules RULES] [--header-rules HEADER_RULES]
                                 [--body-rules BODY_RULES]
                                 [--header-body-rules HEADER_BODY_RULES]
                                 [--attachment-rules ATTACHMENT_RULES]
                                 [--trusted-domains TRUSTED_DOMAINS]
                                 scan_path

positional arguments:
  scan_path             The file(s) to scan (wildcards allowed)

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v, --verbose         Output the entire parsed email (default: False)
  --output OUTPUT, -o OUTPUT
                        Redirect output to a file (default: None)
  --rules RULES         A path to a directory that contains YARA rules. Can be
                        set by the YARA_RULES_DIR environment variable.
                        (default: .)
  --header-rules HEADER_RULES
                        Filename of the header rules file. Can be set by the
                        YARA_HEADER_RULES environment variable. (default:
                        header.yar)
  --body-rules BODY_RULES
                        Filename of the body rules file. Can be set by the
                        YARAMAIL_BODY_RULES environment variable. (default:
                        body.yar)
  --header-body-rules HEADER_BODY_RULES
                        Filename of the header_body rules file. Can be set by
                        the YARAMAIL_HEADER_BODY_RULES environment variable.
                        (default: header_body.yar)
  --attachment-rules ATTACHMENT_RULES
                        Filename of the body rules file. Can be set by the
                        YARAMAIL_BODY_RULES environment variable. (default:
                        attachment.yar)
  --trusted-domains TRUSTED_DOMAINS
                        A path to a file containing a list of trusted domains.
                        Can be set by the YARAMAIL_TRUSTED_DOMAINS environment
                        variable. (default: trusted_domains.txt)

Installation

It is not recommended to use `yaramail` in the same OS that is targeted by 
the potential malware you are scanning. Consider using `yaramail` inside of a
container or VM for additional security.

System dependencies

Some system dependencies must be installed before installing yaramail.

Debian, Ubuntu, and friends

sudo apt install build-essential libpoppler-cpp-dev pkg-config python3-dev libemail-outlook-message-perl

Fedora, Red Hat, and friends

sudo yum install gcc-c++ pkgconfig poppler-cpp-devel python3-devel

macOS

Install Homebrew, then run the following command in a terminal.

brew install pkg-config poppler python

Windows

  1. Install the Microsoft Visual Studio Build Tools
  2. Install Anaconda Distribution
  3. Use Anaconda Navigator to create a new Anaconda Environment
  4. Click the play button for the Anaconda Environment
  5. Click Open Terminal
  6. Run this command and leave the terminal open:
    conda install -c conda-forge poppler
    
  7. Configure your Python IDE/project to use the Anaconda Environment

Install yaramail

The official name for this project, package, and module is `yaramail`. 
Unfortunately, the Python Package Index (PyPI) [did not allow that name to be
used there][pypi-name-issue], so the PyPI project name for `yaramail` is 
`yara-mail`.

In a terminal, run

pip3 install -U yara-mail

Email samples and Outlook clients

Microsoft Outlook for Windows

If you save an email to a file using Microsoft Outlook on Windows, it will save the file in a proprietary Microsoft OLE format with a .msg extension. There are tools like msgconvert that make an attempt to convert a .msg file to a standard RFC 822 .eml file, and yaramail will attempt to use this tool when encountering a .msg file if it is installed on the system. However, anomalies are introduced during conversion that make the results unsuitable for forensic analysis.

Instead of using msgconvert, use one of these other Outlook clients.

Microsoft Outlook for macOS

Drag the email from the inbox or other folder and drop it on the desktop. Attached emails can be saved to a file like any other attachment.

Outlook Web Access (OWA)

  1. Create a new email and leave it open a separate window.
  2. Drag from the inbox or other folder and drop it in the message of the draft.
  3. Download the attachment that was created in step 2

Emails that are already attached to an email can be downloaded from OWA like any other attachment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yara_mail-1.0.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

yara_mail-1.0.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file yara_mail-1.0.1.tar.gz.

File metadata

  • Download URL: yara_mail-1.0.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for yara_mail-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4026d22a92ce46c38bec2c290920810e5664f9bc7daa0ea321836f1fb17f88e9
MD5 a607b9d4fd97b291cdcb8c81cbf02b07
BLAKE2b-256 37abface76b4d1296a3d4806502d6b856169edb0d1ae52c5470c9b435c5305e5

See more details on using hashes here.

File details

Details for the file yara_mail-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: yara_mail-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for yara_mail-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d460a40f2eb72f1ab9f0c6c40e72630bc86cf1566bc3ddaf8e95b34a151a1871
MD5 07fa4d339d4c824f2c9cd230c0f02ed9
BLAKE2b-256 10c7ea63cf8085334e5d534b9f1d736acfc35d1cb571cc5f947f53670121dc61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page