Skip to main content

Classifier karton service

File type classifier for the Karton framework.

Entrypoint for samples. Classifies type of samples labeled as kind: raw, which makes them available for subsystems that receive samples with specific type only (e.g. raw => runnable:win32:exe)

Author: CERT.pl

Maintainers: psrok1, msm, nazywam

Consumes:

{
    "type": "sample",
    "kind": "raw"
    "payload": {
        "magic":  "output from 'file' command",
        "sample": <Resource>
    }
} 

Produces:

{
    "type":      "sample",
    "stage":     "recognized",
    "kind":      "runnable"  # Executable format default for OS platform
              || "document"  # Office document
              || "archive"   # Archive containing samples (zip, e-mails)
              || "dump"      # Dump from sandbox
              || "script",   # Script (js/vbs/bat...)
              || "misc",     # No platform or extension
    "platform":  "win32" 
              || "win64" 
              || "linux" 
              || "android",
              || "macos",
              || "freebsd",
              || "netbsd",
              || "openbsd",
              || "solaris",
    "extension": "*",        # Expected file extension
    "mime": "*",        # Expected file mimetype
    ... (other fields are derived from incoming task)
}

Warning the output mime field is not deterministic across libmagic versions and can change depending on the version you're using. We don't recommend creating consumers that listen on it directly.

Usage

First of all, make sure you have setup the core system: https://github.com/CERT-Polska/karton

Then install karton-classifier from PyPi:

$ pip install karton-classifier

$ karton-classifier

YARA rule classifiers

Since karton-classifier v2.1.0 it's possible to extend the classifier logic using YARA rules.

You can enable it by passing --yara-rules with the path to the directory containing the rules. Each rule has to specify the resulting kind using the meta section. Other meta-attributes (platform and extension) are supported but optional. A working rule looks like this:

rule pe_file
{
    meta:
        description = "classifies incoming windows executables"
        kind = "runnable"
        platform = "win32"
        extension = "exe"
    strings:
        $mz = "MZ"
    condition:
        $mz at 0 and uint32(uint32(0x3C)) == 0x4550
}

Some caveats to consider:

  • Classifier will still process files normally, so in some cases it may report the same file twice.
  • Classifier will report all matching Yara rules (so N matches on a single file will create N tasks)
  • The outgoing task includes the matched rule name in rule-name in the task header
  • All Yara rules must have a .yar extension. All other files in the specified directory are ignored. In particular, .yara extension is not supported.
  • Directories are not supported too - all Yara rules must reside directly in the specified directory.

Co-financed by the Connecting Europe Facility by of the European Union

Metadata

Release files for karton-classifier 2.2.0

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

Built distribution (wheel)

Table of built distributions (wheels) for karton-classifier 2.2.0
File Interpreter ABI Platform
karton_classifier-2.2.0-py3-none-any.whl Python 3 none any Details

Release files / karton_classifier-2.2.0-py3-none-any.whl

Download URL karton_classifier-2.2.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
486368624fba448f1019f6de8b4ee5b57d9ac624b9c45aec09bfb94966a1b16b
BLAKE2b-256 checksum
How to use checksums
1ec0085caaf82781feeded1c24704bd8e86f71503af8a6d5257ed9f5b9a13ad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release history Release notifications | RSS feed

This release

2.2.0 This release

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

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