Skip to main content

A framework for malware configuration parsers.

Project description

DC3-MWCP

Changelog | Releases

DC3 Malware Configuration Parser (DC3-MWCP) is a framework for parsing configuration information from malware. The information extracted from malware includes items such as addresses, passwords, filenames, and mutex names. A parser module is usually created per malware family. DC3-MWCP is designed to help ensure consistency in parser function and output, ease parser development, and facilitate parser sharing. DC3-MWCP supports both analyst directed analysis and large-scale automated execution, utilizing either the native python API, a REST API, or a provided command line tool. DC3-MWCP is authored by the Defense Cyber Crime Center (DC3).

Guides

Install

> pip install mwcp

Alternatively you can clone this repo and install locally.

> git clone https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP.git
> pip install ./DC3-MWCP

For a development mode use the -e flag to install in editable mode:

> git clone https://github.com/Defense-Cyber-Crime-Center/DC3-MWCP.git
> pip install -e ./DC3-MWCP

DC3-Kordesii Support

DC3-MWCP optionally supports DC3-Kordesii if it is installed. This will allow you to run any DC3-Kordesii decoder from the mwcp.FileObject object with the run_kordesii_decoder function.

You can install DC3-Kordesii along with DC3-MWCP by adding [kordesii] to your appropriate install command:

pip install mwcp[kordesii]
pip install ./DC3-MWCP[kordesii]
pip install -e ./DC3-MWCP[kordesii]

Usage

DC3-MWCP is designed to allow easy development and use of malware config parsers. DC3-MWCP is also designed to ensure that these parsers are scalable and that DC3-MWCP can be integrated in other systems.

Most automated processing systems will use a condition, such as a yara signature match, to trigger execution of an DC3-MWCP parser.

There are 3 options for integration of DC3-MWCP:

  • CLI: mwcp
  • REST API: mwcp serve
  • Python API

DC3-MWCP also includes a utility for test case generation and execution.

CLI tool

DC3-MWCP can be used directly from the command line using the mwcp command.

> mwcp parse foo ./README.md

----Standard Metadata----

url                  http://127.0.0.1
address              127.0.0.1

----Debug----

size of inputfile is 7963 bytes
outputfile: fooconfigtest.txt
operating on inputfile README.md

----Output Files----

fooconfigtest.txt    example output file
                     5eb63bbbe01eeed093cb22bb8f5acdc3

see mwcp parse -h for full set of options

REST API

DC3-MWCP can be used as a web service. The REST API provides two commonly used functions:

  • /run_parser/<parser> -- executes a parser on uploaded file
  • /descriptions -- provides list of available parsers

To use, first start the server by running:

> mwcp serve

Then you can either use an HTTP client to create REST requests.

Using cURL:

> curl --form data=@README.md http://localhost:8080/run_parser/foo

Using Python requests:

import requests
req = requests.post("http://localhost:8080/run_parser/foo", files={'data': open("README.md", 'rb')})
req.json()

Output:

{
    "url": [
        "http://127.0.0.1"
    ],
    "address": [
        "127.0.0.1"
    ],
    "debug": [
        "size of inputfile is 7128 bytes",
        "outputfile: fooconfigtest.txt",
        "operating on inputfile C:\\Users\\JOHN.DOE\\AppData\\Local\\Temp\\mwcp-managed_tempdir-pk0f12oh\\mwcp-inputfile-n4mw7uw3"
    ],
    "outputfile": [
        [
            "fooconfigtest.txt",
            "example output file",
            "5eb63bbbe01eeed093cb22bb8f5acdc3",
            "aGVsbG8gd29ybGQ="
        ]
    ],
    "output_text": "\n----Standard Metadata----\n\nurl                  http://127.0.0.1\naddress              127.0.0.1\n\n----Debug----\n\nsize of inputfile
is 7128 bytes\noutputfile: fooconfigtest.txt\noperating on inputfile C:\\Users\\JOHN.DOE\\AppData\\Local\\Temp\\mwcp-managed_tempdir-pk0f12oh\\mwcp-inputfi
le-n4mw7uw3\n\n----Output Files----\n\nfooconfigtest.txt    example output file\n                     5eb63bbbe01eeed093cb22bb8f5acdc3\n"
}

A simple HTML interface is also available at the same address. By default this is http://localhost:8080/. Individual samples can be submitted and results saved as JSON, plain text, or ZIP archives.

Python API

DC3-MWCP can be run directly from Python.

#!/usr/bin/env python
"""
Simple example to demonstrate use of the API provided by DC3-MWCP framework.
"""

# first, import mwcp
import mwcp

# register the builtin MWCP parsers and any other parser packages installed on the system
mwcp.register_entry_points()

# register a directory containing parsers
mwcp.register_parser_directory(r'C:\my_parsers')

# view all available parsers
print(mwcp.get_parser_descriptions(config_only=False))


# create an instance of the Reporter class
reporter = mwcp.Reporter()
"""
The mwcp.Reporter object is the primary DC3-MWCP framework object, containing most input and output data
and controlling execution of the parser modules.
"""

# run the dummy config parser, view the output
reporter.run_parser("foo", "README.md")

# alternate, run on provided buffer:
reporter.run_parser("foo", data="lorem ipsum")

reporter.print_report()

Configuration

DC3-MWCP uses a configuration file which is located within the user's profile directory. (%APPDATA%\Local\mwcp\config.yml for Windows or ~/.config/mwcp/config.yml for Linux)

This configuration file is used to manage configurable parameters, such as the location of the malware repository used for testing or the default parser source.

To configure this file, run mwcp config to open up the file in your default text editor.

An alternative configuration file can also be temporarily set using the --config parameter.

> mwcp --config='new_config.yml' test Foo

Individual configuration parameters can be overwritten on the command line using the respective parameter.

Logging

DC3-MWCP uses Python's builtin in logging module to log all messages. By default, logging is configured using the log_config.yml configuration file. Which is currently set to log all messages to the console and error messages to %LOCALAPPDATA%/mwcp/errors.log.

You can provide your own custom log configuration file by adding the path to the configuration parameter LOG_CONFIG_PATH. (Please see Python's documentation for more information on how to write your own configuration file.)

You may also use the --verbose or --debug flags to adjust the logging level when using the mwcp tool.

Updates

DC3-MWCP code updates are implemented to be backwards compatible.

One exception to backwards compatibility is when new attributes are amended to previously existing fields. An example of this is the MD5 entry being amended to the 'outputfile' field. When attribute additions like this are made, it causes a backwards compatibility conflict with test cases. If mwcp test is being used to manage regression tests, the amended attributes can cause previously passing test cases to fail. To resolve this issue, work in an environment where parsers are in a known good state and run the command mwcp test -u to update all test cases. The newly generated test cases will include the updated field values.

Schema

One of the major goals of DC3-MWCP is to standardize output for malware configuration parsers, making the data from one parser comparable with that of other parsers. This is achieved by establishing a schema of standardized fields that represent the common malware attributes seen across malware families. To see the list of standardized fields and their definitions, see fields.json.

It is acknowledged that a set of generic fields will often not be adequate to capture the nuances of individual malware families. To ensure that malware family specific attributes are appropriately captured in parser output, the schema includes an "other" field which supports arbitrary key-value pairs. Information not captured in the abstract standardized fields is captured through this mechanism.

Duplication of data items is encouraged both to provide additional family specific context and to simplify access of data through both composite fields and individual fields. The DC3-MWCP framework extracts individual items reported in composite fields to the degree possible. For example, the address in a url will be extracted automatically by DC3-MWCP.

See fields.txt for additional explanation.

Helper Utilities

MWCP comes with a few helper utilities (located in mwcp.utils) that may become useful for parsing malware files.

  • pefileutils - Provides helper functions for common routines done with the pefile library. (obtaining or checking for exports, imports, resources, sections, etc.)
  • elffileutils - Provides helper functions for common routines done with the elftools library. Provides a consistent interface similar to pefileutils.
  • custombase64 - Provides functions for base64 encoding/decoding data with a custom alphabet.
  • construct - Provides extended functionality to the construct library and brings back some lost features from version 2.8 into 2.9.
    • This library has replaced the enstructured library originally found in the resources directory.
    • Please follow this tutorial for migrating from enstructured to construct.
  • pecon - PE file reconstruction utility.
    • Please see docstring in pecon.py for more information.
  • poshdeob - An experimental powershell deobfuscator utility used to statically deobfuscate code and extract strings.

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

mwcp-3.1.0.tar.gz (117.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mwcp-3.1.0-py3-none-any.whl (127.5 kB view details)

Uploaded Python 3

File details

Details for the file mwcp-3.1.0.tar.gz.

File metadata

  • Download URL: mwcp-3.1.0.tar.gz
  • Upload date:
  • Size: 117.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.2

File hashes

Hashes for mwcp-3.1.0.tar.gz
Algorithm Hash digest
SHA256 8d9114ff821a47bcd0c41ada383480b7905b372a820b1abf69da48d5c81f9bdc
MD5 745e0291b070a4715258b4972ffede93
BLAKE2b-256 4c1fc5901f13b2916b3ad0d0f6be9d994b94bf027d189035877cf4d133c71fd1

See more details on using hashes here.

File details

Details for the file mwcp-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: mwcp-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 127.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.2

File hashes

Hashes for mwcp-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43bb33c6578e6fb0798f236b8dc9bf299287ebbc57cdaf3262c357b7034b9840
MD5 b6af809b58bbf5c5618462859e1e516c
BLAKE2b-256 d5166e4f8965899c59a0fa3c3be7c4ca93cbcaa4859450a2fc9fac1486dcc610

See more details on using hashes here.

Supported by

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