Yara rule writing malware

From ShulkwiSEC/bb-huge · View interactive version

Yara rule writing malware is an AI agent skill from the GitHub repository ShulkwiSEC/bb-huge. Write custom YARA rules to identify and classify malware based on textual and binary patterns. This skill focuses on creating robust signatures using strings, regular expressions, and hexadecimal opcodes extracted during malware analysis for enterprise threat hunting.

How to use this skill

Skill file

YARA Rule Writing for Malware Detection

When to Use

Prerequisites

Workflow

Phase 1: Understanding Basic YARA Structure

# Concept: Rule syntax rule Basic_Ransomware_Detection {
    meta:
        description = "Detects generic ransomware strings"
        author = "CyberSkills"
        date = "2024-05-10"
    
    strings:
        $s1 = "Your files have been encrypted" ascii wide nocase
        $s2 = "比特币" // Bitcoin in Chinese (UTF-8)
        $s3 = "vssadmin.exe Delete Shadows /All /Quiet" ascii wide
        
    condition:
        2 of them
}

Phase 2: Utilizing Hexadecimal Signatures

# rule Emotet_Hex_Pattern {
    meta:
        description = "Detects Emotet unpacking loop pattern"

    strings:
        // 8B 45 ?? 03 45 ?? 50 FF 15
        $hex_pattern = { 8B 45 ?? 03 45 ?? 50 FF 15 [4] }
        
    condition:
        $hex_pattern
}

Phase 3: Leveraging the PE Module (Windows Executables)

# import module import "pe"

rule Suspicious_Document_Icon {
    meta:
        description = "Executable disguised as PDF/Word doc"
        
    condition:
        uint16(0) == 0x5a4d and // MZ header
        pe.number_of_resources > 0 and 
        (
            pe.version_info["OriginalFilename"] contains ".pdf" or
            pe.version_info["OriginalFilename"] contains ".docx"
        )
}

Phase 4: Validating and Executing the Scan

# yara -r my_rules.yar /path/to/suspicious/files/
Decision Point 🔀
flowchart TD
    A[Extract Strings ] --> B{Are Strings Unique? }
    B -->|Yes| C[Create String Rule ]
    B -->|No| D[Extract Hex/Opcodes ]
    C --> E[Test Rule Avoid FPs ]

🔵 Blue Team Detection & Defense

| Concept | Description |

|---------|-------------|

Output Format

Yara Rule Writing Malware — Assessment Report
============================================================
Target: [Target identifier]
Assessor: [Operator name]
Date: [Assessment date]
Scope: [Authorized scope]
MITRE ATT&CK: [Relevant technique IDs]

Findings Summary:
  [Finding 1]: [Severity] — [Brief description]
  [Finding 2]: [Severity] — [Brief description]

Detailed Results:
  Phase 1: [Phase name]
    - Result: [Outcome]
    - Evidence: [Screenshot/log reference]
    - Impact: [Business impact assessment]

  Phase 2: [Phase name]
    - Result: [Outcome]
    - Evidence: [Screenshot/log reference]
    - Impact: [Business impact assessment]

Risk Rating: [Critical/High/Medium/Low/Informational]
Recommendations:
  1. [Immediate remediation step]
  2. [Long-term hardening measure]
  3. [Monitoring/detection improvement]

📚 Shared Resources

For cross-cutting methodology applicable to all vulnerability classes, see:

- CODE0 — Exploit chaining methodology and high-payout chain patterns

- CODE0 — HackerOne-optimized report writing, CWE quick reference

- CODE0 — Verified disclosed bounties by vulnerability class

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.