Ctrl + k

or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/yara-python@3.11.x
tile.json

tessl/pypi-yara-python

tessl install tessl/pypi-yara-python@3.11.0

Python interface for YARA, a powerful malware identification and classification tool

Agent Success

Agent success rate when using this tile

85%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.94x

Baseline

Agent success rate without this tile

90%

task.mdevals/scenario-1/

Warning Monitor for YARA Rule Scanning

Problem Statement

Build a YARA rule scanner that monitors and logs runtime warnings during file scanning operations. Your system should track situations where YARA generates warnings (such as when too many string matches occur) and provide detailed reporting about which rules and strings trigger these warnings.

Requirements

Implement a Python module that:

  1. Compiles YARA rules from a source string provided as input
  2. Scans data or files using the compiled rules
  3. Captures runtime warnings that occur during scanning (e.g., when a rule encounters too many matches)
  4. Reports warning details including:
    • The type of warning that occurred
    • The rule that triggered the warning
    • The specific string pattern (if applicable) that caused the warning
  5. Returns both scan results and warning information to the caller

Input Specifications

Your module should accept:

  • A string containing YARA rule definitions
  • Data to scan (either raw bytes/string or a file path)

Output Specifications

Your module should return:

  • A list of matches found during scanning
  • A list of warnings captured during scanning, where each warning includes:
    • Warning type description
    • Rule name
    • String identifier (if applicable)

Constraints

  • You must handle cases where no warnings occur
  • You must not modify the scanning behavior (i.e., continue scanning even when warnings occur)
  • Warning information must be accessible after the scan completes

Dependencies { .dependencies }

yara-python { .dependency }

Python interface for YARA pattern matching engine, used for malware detection and analysis.

Test Cases

Test Case 1: Basic Warning Detection @test

File: test_warning_monitor.py

Description: Verify that warnings are captured when a rule generates too many matches.

Setup:

# Create a rule that will match many times in repetitive data
rule_source = '''
rule test_rule {
    strings:
        $a = "A"
    condition:
        $a
}
'''

# Create data with many occurrences to trigger warning
test_data = b"A" * 100000

Expected Behavior:

  • Scanning should complete successfully
  • Warning information should be captured indicating too many matches
  • The warning should reference the rule name "test_rule" and string "$a"

Test Case 2: No Warnings Scenario @test

File: test_warning_monitor.py

Description: Verify that the system handles scans with no warnings correctly.

Setup:

rule_source = '''
rule simple_rule {
    strings:
        $b = "rare_pattern_xyz"
    condition:
        $b
}
'''

test_data = b"some normal data without the pattern"

Expected Behavior:

  • Scanning should complete successfully
  • No warnings should be captured
  • The warning list should be empty

Test Case 3: Multiple Rules with Warnings @test

File: test_warning_monitor.py

Description: Verify that warnings from multiple rules are all captured.

Setup:

rule_source = '''
rule rule_one {
    strings:
        $x = "X"
    condition:
        $x
}

rule rule_two {
    strings:
        $y = "Y"
    condition:
        $y
}
'''

# Data that causes warnings for both rules
test_data = (b"X" * 50000) + (b"Y" * 50000)

Expected Behavior:

  • Scanning should complete successfully
  • Warnings should be captured for both rule_one and rule_two
  • Each warning should correctly identify its associated rule and string