Deepfence YaraHunter Documentation

repository·release-2.5·Indexed 23 days ago

https://github.com/deepfence/yarahunter

A portable malware scanner that uses YARA rules to detect indicators of compromise (IOCs) within container images, running containers, and filesystems. Designed for CI/CD pipelines and runtime security monitoring, it provides JSON output for automation and includes a convert-rules CLI to transform JSON feeds into .yar files.

Tokens
5.8K
Snippets
25
Records
36
Agent score
78%

What's inside YaraHunter

  1. Overview of Deepfence YaraHunter

    release-2.5

    Deepfence YaraHunter is a malware scanner designed to find indicators of compromise (IOCs) in container images, running Docker containers, and filesystems. It utilizes a YARA ruleset to identify resources matching known malware signatures.

    Use Cases:

    • Build-and-test: Scan build artifacts in CI/CD pipelines.
    • At rest: Scan local container images before deployment.
    • At runtime: Scan running Docker containers to detect unusual activity.
    • Filesystems: Scan local filesystems for indicators of compromise.

    Key Features:

    • Highly portable via a Docker container form factor.
    • Designed for automation with easy-to-parse JSON output.
  2. Use cases for YaraHunter

    release-2.5

    YaraHunter is designed for multiple security workflows:

    • Build-and-test: Scan build artifacts within CI/CD pipelines to detect malware before deployment.
    • At rest: Scan local container images before they are deployed to verify integrity.
    • At runtime: Scan running Docker containers to detect compromises (e.g., in response to unusual network or CPU activity).
    • Filesystems: Scan local filesystems at any time for indicators of compromise.
  3. Run the website in local development mode

    release-2.5

    To start a local development server, use the yarn start command. This will open a browser window and support live reloading for most changes. By default, the server runs on port 3000. You can specify a different port using the --port flag.

    $ yarn start
  4. Scan a running container with YaraHunter

    release-2.5

    To scan a container that is currently running, you must mount the host's root directory into the YaraHunter container at a chosen location (e.g., /deepfence/mnt). You must then provide the --host-mount-path (the path inside the YaraHunter container) and the --container-id of the target running container.

    docker run -it --rm --name=yara-hunter \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /:/deepfence/mnt \
        quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 \
        --host-mount-path /deepfence/mnt --container-id 69221b948a73
  5. Export and process scan results as JSON

    release-2.5

    To programmatically process scan results, use the --output=json flag and redirect the container's stdout to a file. You can also mount a local directory to /home/deepfence/output inside the container to persist output files.

    Once you have the JSON output, you can use jq to extract specific fields, such as the Matched Rule Name from the IOC array.

    docker run -i --rm --name=yara-hunter \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /tmp:/home/deepfence/output \
        quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 \
        --image-name node:latest \
        --output=json > node-latest.json
    
    cat /tmp/node-latest.json | jq '.IOC[] | ."Matched Rule Name"'
  6. Scan a container image for malware with YaraHunter

    release-2.5

    You can scan container images for indicators of compromise (IOCs) by running the YaraHunter Docker container. To scan an image, provide the --image-name argument and specify the output format using --output=json.

    To ensure the scanner can access the Docker daemon, you must mount /var/run/docker.sock. To save the results to your host machine, mount a local directory to /home/deepfence/output inside the container.

    docker run -i --rm --name=deepfence-yarahunter \
         -v /var/run/docker.sock:/var/run/docker.sock \
         -v /tmp:/home/deepfence/output \
         quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 \
         --image-name metal3d/xmrig:latest \
         --output=json > xmrig-scan.json
  7. Provide custom YARA rules to YaraHunter

    release-2.5

    YaraHunter scans for malware using YARA rules (*.yar or *.yara). By default, it looks in /home/deepfence/rules inside the container. You can provide your own rules using one of two methods:

    1. Mount over the default directory: Mount your local rules directory directly to /home/deepfence/rules using a Docker volume.
    2. Mount to a custom path: Mount your rules to a different location in the container and use the --rules-path flag to tell YaraHunter where to find them.

    Ensure your rule files use the .yar or .yara extension.

    # Method 1: Mount over the default directory
    docker run -it --rm --name=yara-hunter \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v $(pwd)/my-rules:/home/deepfence/rules \
        quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 --image-name node:latest
    
    # Method 2: Mount to a custom path and use --rules-path
    mkdir ./my-rules
    docker run -it --rm --name=yara-hunter \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v $(pwd)/my-rules:/tmp/my-rules \
        quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 --image-name node:latest \
        --rules-path /tmp/my-rules
  8. Run the MalwareScanner gRPC server

    release-2.5

    To use YaraHunter via gRPC, you must first run the MalwareScanner service as a persistent server. This can be done using Docker by mounting the Docker socket and a specific socket path for communication.

    Note: Ensure you provide a -socket-path argument to define where the Unix domain socket will be created.

    docker run -it --rm --name=deepfence-malwarescanner \
    	-v $(pwd):/home/deepfence/output \
    	-v /var/run/docker.sock:/var/run/docker.sock \
    	-v /tmp/sock:/tmp/sock \
    	quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 \
    	-socket-path /tmp/sock/s.sock
  9. Install YaraHunter via Docker

    release-2.5

    You can pull the official YaraHunter image from Quay.io or build it from the source repository.

    Pulling the image:

    docker pull quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8

    Building from source: Clone the repository and run:

    make docker
    docker pull quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8
  10. Scan a container image with YaraHunter

    release-2.5

    To scan a container image, run the YaraHunter Docker container. You must mount the Docker socket to allow the scanner to interact with the Docker daemon and mount a local directory for output storage.

    Basic Scan Command: Use the --image-name flag to specify the target image and --output=json to generate machine-readable results.

    Scanning with cached rules: To speed up subsequent runs, you can mount a directory containing YARA rules and provide the path using the --rules-path argument.

    Note: To get human-readable table formatted output instead of JSON, omit the --output=json flag.

    docker run -i --rm --name=deepfence-yarahunter \
         -v /var/run/docker.sock:/var/run/docker.sock \
         -v /tmp:/home/deepfence/output \
         quay.io/deepfenceio/deepfence_malware_scanner_ce:2.5.8 \
         --image-name metal3d/xmrig:latest \
         --output=json > xmrig-scan.json