Chuyển đến nội dung
Skillpedia
Bảo mật35k · #8322

performing-threat-hunting-with-yara-rules

Skill này làm gì

Công cụ này dùng các luật đặc biệt (gọi là YARA) để tìm file và mã độc hại, đáng ngờ hoặc nguy hiểm trong máy tính hoặc các file bạn đã lưu. Nó giúp tìm ra các mối đe dọa được che giấu.

Khi nào nên dùng

  • ✓Khi bạn muốn chủ động tìm virus mới và chưa biết trong nhiều file.
  • ✓Khi bạn phân tích các file đã bị cách ly hoặc đến từ môi trường thử nghiệm.
  • ✓Khi bạn muốn kiểm tra xem file đáng ngờ có khớp với các mối đe dọa đã biết dựa trên thông tin tình báo bảo mật không.

Liên kết skill

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/performing-threat-hunting-with-yara-rules/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/performing-threat-hunting-with-yara-rules/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Săn tìm mối đe dọa trong các file của thư mục 'Downloads' bằng luật YARA giúp tôi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn viết các 'luật' mô tả hình dạng của file hoặc mã độc. Sau đó, công cụ dùng các luật này để quét file của bạn và cho biết có phát hiện nào khớp không.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Performing Threat Hunting with YARA Rules

Scan files, directories, and memory dumps using YARA rules to identify malware families, suspicious patterns, and IOC matches.

When to Use

  • Proactively hunting for unknown malware variants across network shares, endpoints, and email attachments
  • Scanning quarantine directories or sandbox outputs for malware family classification
  • Searching process memory dumps for injected code or in-memory-only payloads
  • Validating threat intelligence IOCs against a large corpus of collected samples
  • Triaging incident response artifacts to identify known malware families quickly
  • Building automated detection pipelines that scan new files on ingestion

Do not use for real-time endpoint protection (use EDR agents instead); YARA scanning is best suited for batch hunting, triage, and post-collection analysis where scan latency is acceptable.

Prerequisites

  • YARA 4.x installed (apt install yara on Debian/Ubuntu, brew install yara on macOS)
  • Python 3.8+ with yara-python (pip install yara-python)
  • yarGen for automated rule generation (git clone https://github.com/Neo23x0/yarGen)
  • Sample malware corpus or suspicious files for scanning (from malware zoos, VT, or incident artifacts)
  • Optional: pefile for PE header analysis, malduck for memory carving
  • Threat intel YARA rule sets (e.g., YARA-Rules community repository, Florian Roth signature-base)

Workflow

Step 1: Install YARA and Python Bindings

# Linux
sudo apt update && sudo apt install -y yara

# Python bindings
pip install yara-python

# Verify installation
yara --version
python3 -c "import yara; print(yara.YARA_VERSION)"

Step 2: Write a Basic YARA Rule

Create rules that match on strings, hex patterns, and file metadata:

// File: rules/emotet_loader.yar
rule Emotet_Loader_2026 {
    meta:
        author = "Threat Intel Team"
        description = "Detects Emotet first-stage loader DLL"
        date = "2026-01-20"
        reference = "https://attack.mitre.org/software/S0367/"
        mitre_attack = "T1059.001, T1055.001"
        severity = "critical"

    strings:
        // Emotet export function name patterns
        $export1 = "DllRegisterServer" ascii
        $export2 = "RunDLL" ascii nocase

        // Obfuscated string decryption routine
        $decrypt_loop = { 8B 45 ?? 33 45 ?? 89 45 ?? 8B 4D ?? 03 4D ?? }

        // PowerShell download cradle in embedded script
        $ps_cradle = /powershell[^\n]{0,50}-e(nc|ncodedcommand)/i

        // Known C2 URI patterns
        $uri1 = "/wp-content/uploads/" ascii
        $uri2 = "/wp-admin/css/" ascii
        $uri3 = "/wp-includes/" ascii

        // PE characteristics
        $mz = "MZ" at 0

    condition:
        $mz and
        filesize < 2MB and
        (
            ($export1 and $decrypt_loop) or
            ($ps_cradle and any of ($uri*)) or
            (2 of ($uri*) and $decrypt_loop)
        )
}

Step 3: Write Advanced Rules with Modules

Use YARA modules for PE header inspection and math-based entropy checks:

import "pe"
import "math"

rule Suspicious_Packed_Executable {
    meta:
        author = "Threat Hunting Team"
        description = "Detects PE files with high entropy sections indicating packing or encryption"
        severity = "medium"

    condition:
        pe.is_pe and
        pe.number_of_sections > 0 and
        for any section in pe.sections : (
            math.entropy(section.offset, section.size) > 7.2 and
            section.size > 1024
        ) and
        pe.imports("kernel32.dll", "VirtualAlloc") and
        pe.imports("kernel32.dll", "VirtualProtect")
}

rule Suspicious_UPX_Modified {
    meta:
        description = "Detects UPX-packed binaries with tampered section names"
        severity = "medium"

    strings:
        $upx_magic = { 55 50 58 21 }  // UPX!

    condition:
        pe.is_pe and
        $upx_magic and
        not (
            pe.sections[0].name == "UPX0" and
            pe.sections[1].name == "UPX1"
        )
}

Step 4: Scan Files and Directories with yara-python

import yara
import os
import json
from datetime import datetime
from pathlib import Path

def compile_rules(rule_paths):
    """Compile YARA rules from one or more .yar files."""
    rule_files = {}
    for i, path in enumerate(rule_paths):
        namespace = Path(path).stem
        rule_files[namespace] = path
    return yara.compile(filepaths=rule_files)


…
Câu hỏi thường gặp

Luật YARA là gì?

Đó giống như công thức mô tả các mẫu cụ thể trong file hoặc mã. Chúng cho công cụ biết cần tìm gì, chẳng hạn như chuỗi văn bản, mẫu hexadecimal hoặc đặc điểm của file.

Tôi có cần là lập trình viên để dùng công cụ này không?

Bạn không cần là lập trình viên có kinh nghiệm. Bạn sẽ cần cài đặt một số công cụ và làm theo các bước để tạo hoặc dùng luật YARA, nhưng ý tưởng chính là mô tả điều bạn muốn tìm.

Công cụ này có thay thế phần mềm diệt virus không?

Không. Công cụ này chủ yếu dùng để chủ động tìm kiếm mối đe dọa trong các file bạn đã có hoặc đã thu thập (săn tìm mối đe dọa), chứ không bảo vệ máy tính theo thời gian thực trước các lây nhiễm mới.

Chi tiết

Mô tả gốc của tác giả

Use YARA pattern-matching rules to hunt for malware, suspicious files, and indicators of compromise across filesystems and memory dumps. Covers rule authoring, yara-python scanning, and integration with threat intel feeds. '

repo: mukul975/Anthropic-Cybersecurity-Skills

Độ phổ biến

Sao GitHub
35k
Vị trí xếp hạng
#8322
Giấy phép
Apache-2.0
Cập nhật
31/8/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự