[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6AG3ST9RW6GK95FGNZ19NS2":3,"skill-same:01M6AG3ST9RW6GK95FGNZ19NS2":135},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":44,"linkOnly":45,"markdownContent":46,"markdownBody":47,"frontMatter":48,"refName":70,"commitSha":71,"skillDirectory":72,"forksCount":73,"repositoryHtmlUrl":74,"repositoryHomepageUrl":75,"ownerHtmlUrl":76,"ownerBlogUrl":77,"ownerDescription":78,"updatedAt":79,"install":80,"resources":93},"01M6AG3ST9RW6GK95FGNZ19NS2","performing-threat-hunting-with-yara-rules",null,"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.","mukul975\u002FAnthropic-Cybersecurity-Skills","mukul975","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F42860185?v=4","01M6ADEQR8T5M4EEG6C67BQCWF","Mahipal","01M6ADJPMYWG1E5GM1FWBE3128",36078,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fperforming-threat-hunting-with-yara-rules\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43],"performing threat hunting with yara rules","threat hunting","yara","malware","malware-detection","pattern-matching","analysis","indicators","execution","detection","feeds","suspicious","threat-hunting","integration","file","content","validation","cybersecurity","memory","python","2026-11-10 10:12:30",false,"---\nname: performing-threat-hunting-with-yara-rules\ndescription: 'Use YARA pattern-matching rules to hunt for malware, suspicious files,\n  and indicators of compromise across filesystems and memory dumps. Covers rule authoring,\n  yara-python scanning, and integration with threat intel feeds.\n\n  '\ndomain: cybersecurity\nsubdomain: threat-hunting\ntags:\n- yara\n- malware-detection\n- threat-hunting\n- pattern-matching\nversion: '1.0'\nauthor: mahipal\nlicense: Apache-2.0\nd3fend_techniques:\n- Executable Denylisting\n- Execution Isolation\n- File Metadata Consistency Validation\n- Content Format Conversion\n- File Content Analysis\nnist_csf:\n- DE.CM-01\n- DE.AE-02\n- DE.AE-07\n- ID.RA-05\nmitre_attack:\n- T1046\n- T1057\n- T1082\n- T1083\n- T1005\n---\n\n# Performing Threat Hunting with YARA Rules\n\nScan files, directories, and memory dumps using YARA rules to identify\nmalware families, suspicious patterns, and IOC matches.\n\n## When to Use\n\n- Proactively hunting for unknown malware variants across network shares, endpoints, and email attachments\n- Scanning quarantine directories or sandbox outputs for malware family classification\n- Searching process memory dumps for injected code or in-memory-only payloads\n- Validating threat intelligence IOCs against a large corpus of collected samples\n- Triaging incident response artifacts to identify known malware families quickly\n- Building automated detection pipelines that scan new files on ingestion\n\n**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.\n\n## Prerequisites\n\n- YARA 4.x installed (`apt install yara` on Debian\u002FUbuntu, `brew install yara` on macOS)\n- Python 3.8+ with `yara-python` (`pip install yara-python`)\n- `yarGen` for automated rule generation (`git clone https:\u002F\u002Fgithub.com\u002FNeo23x0\u002FyarGen`)\n- Sample malware corpus or suspicious files for scanning (from malware zoos, VT, or incident artifacts)\n- Optional: `pefile` for PE header analysis, `malduck` for memory carving\n- Threat intel YARA rule sets (e.g., YARA-Rules community repository, Florian Roth signature-base)\n\n## Workflow\n\n### Step 1: Install YARA and Python Bindings\n\n```bash\n# Linux\nsudo apt update && sudo apt install -y yara\n\n# Python bindings\npip install yara-python\n\n# Verify installation\nyara --version\npython3 -c \"import yara; print(yara.YARA_VERSION)\"\n```\n\n### Step 2: Write a Basic YARA Rule\n\nCreate rules that match on strings, hex patterns, and file metadata:\n\n```yara\n\u002F\u002F File: rules\u002Femotet_loader.yar\nrule Emotet_Loader_2026 {\n    meta:\n        author = \"Threat Intel Team\"\n        description = \"Detects Emotet first-stage loader DLL\"\n        date = \"2026-01-20\"\n        reference = \"https:\u002F\u002Fattack.mitre.org\u002Fsoftware\u002FS0367\u002F\"\n        mitre_attack = \"T1059.001, T1055.001\"\n        severity = \"critical\"\n\n    strings:\n        \u002F\u002F Emotet export function name patterns\n        $export1 = \"DllRegisterServer\" ascii\n        $export2 = \"RunDLL\" ascii nocase\n\n        \u002F\u002F Obfuscated string decryption routine\n        $decrypt_loop = { 8B 45 ?? 33 45 ?? 89 45 ?? 8B 4D ?? 03 4D ?? }\n\n        \u002F\u002F PowerShell download cradle in embedded script\n        $ps_cradle = \u002Fpowershell[^\\n]{0,50}-e(nc|ncodedcommand)\u002Fi\n\n        \u002F\u002F Known C2 URI patterns\n        $uri1 = \"\u002Fwp-content\u002Fuploads\u002F\" ascii\n        $uri2 = \"\u002Fwp-admin\u002Fcss\u002F\" ascii\n        $uri3 = \"\u002Fwp-includes\u002F\" ascii\n\n        \u002F\u002F PE characteristics\n        $mz = \"MZ\" at 0\n\n    condition:\n        $mz and\n        filesize \u003C 2MB and\n        (\n            ($export1 and $decrypt_loop) or\n            ($ps_cradle and any of ($uri*)) or\n            (2 of ($uri*) and $decrypt_loop)\n        )\n}\n```\n\n### Step 3: Write Advanced Rules with Modules\n\nUse YARA modules for PE header inspection and math-based entropy checks:\n\n```yara\nimport \"pe\"\nimport \"math\"\n\nrule Suspicious_Packed_Executable {\n    meta:\n        author = \"Threat Hunting Team\"\n        description = \"Detects PE files with high entropy sections indicating packing or encryption\"\n        severity = \"medium\"\n\n    condition:\n        pe.is_pe and\n        pe.number_of_sections > 0 and\n        for any section in pe.sections : (\n            math.entropy(section.offset, section.size) > 7.2 and\n            section.size > 1024\n        ) and\n        pe.imports(\"kernel32.dll\", \"VirtualAlloc\") and\n        pe.imports(\"kernel32.dll\", \"VirtualProtect\")\n}\n\nrule Suspicious_UPX_Modified {\n    meta:\n        description = \"Detects UPX-packed binaries with tampered section names\"\n        severity = \"medium\"\n\n    strings:\n        $upx_magic = { 55 50 58 21 }  \u002F\u002F UPX!\n\n    condition:\n        pe.is_pe and\n        $upx_magic and\n        not (\n            pe.sections[0].name == \"UPX0\" and\n            pe.sections[1].name == \"UPX1\"\n        )\n}\n```\n\n### Step 4: Scan Files and Directories with yara-python\n\n```python\nimport yara\nimport os\nimport json\nfrom datetime import datetime\nfrom pathlib import Path\n\ndef compile_rules(rule_paths):\n    \"\"\"Compile YARA rules from one or more .yar files.\"\"\"\n    rule_files = {}\n    for i, path in enumerate(rule_paths):\n        namespace = Path(path).stem\n        rule_files[namespace] = path\n    return yara.compile(filepaths=rule_files)\n\ndef scan_directory(rules, target_dir, recursive=True):\n    \"\"\"Scan a directory for matches and return structured results.\"\"\"\n    results = []\n    scan_count = 0\n    error_count = 0\n\n    for root, dirs, files in os.walk(target_dir):\n        for filename in files:\n            filepath = os.path.join(root, filename)\n            scan_count += 1\n            try:\n                matches = rules.match(filepath, timeout=60)\n                if matches:\n                    for match in matches:\n                        result = {\n                            \"file\": filepath,\n                            \"rule\": match.rule,\n                            \"namespace\": match.namespace,\n                            \"tags\": match.tags,\n                            \"meta\": match.meta,\n                            \"strings\": [],\n                            \"scan_time\": datetime.utcnow().isoformat()\n                        }\n                        for offset, identifier, data in match.strings:\n                            result[\"strings\"].append({\n                                \"offset\": hex(offset),\n                                \"identifier\": identifier,\n                                \"data\": data.hex() if isinstance(data, bytes) else data\n                            })\n                        results.append(result)\n                        print(f\"  MATCH: {match.rule} -> {filepath}\")\n            except yara.TimeoutError:\n                error_count += 1\n                print(f\"  TIMEOUT scanning {filepath}\")\n            except yara.Error as e:\n                error_count += 1\n\n        if not recursive:\n            break\n\n    print(f\"\\nScan complete: {scan_count} files scanned, \"\n          f\"{len(results)} matches, {error_count} errors\")\n    return results\n\n# Compile and scan\nrules = compile_rules([\n    \"rules\u002Femotet_loader.yar\",\n    \"rules\u002Fsuspicious_packed.yar\"\n])\n\nmatches = scan_directory(rules, \"\u002Fmnt\u002Fevidence\u002Fcollected_samples\u002F\")\n\n# Export results\nwith open(\"yara_scan_results.json\", \"w\") as f:\n    json.dump(matches, f, indent=2)\n```\n\n### Step 5: Scan Process Memory Dumps\n\nHunt for in-memory indicators that only exist in running processes:\n\n```python\nimport yara\n\ndef scan_memory_dump(rules, dump_path):\n    \"\"\"Scan a process memory dump for YARA matches.\"\"\"\n    matches = rules.match(dump_path, timeout=120)\n\n    for match in matches:\n        print(f\"Rule: {match.rule}\")\n        print(f\"  Severity: {match.meta.get('severity', 'unknown')}\")\n        for offset, identifier, data in match.strings:\n            # Show context around the match\n            print(f\"  String {identifier} at offset {hex(offset)}\")\n            if len(data) \u003C= 64:\n                print(f\"    Data: {data.hex()}\")\n\n    return matches\n\n# Rules targeting in-memory artifacts\nmemory_rules = yara.compile(source=\"\"\"\nrule Cobalt_Strike_Beacon_Memory {\n    meta:\n        description = \"Detects Cobalt Strike beacon in process memory\"\n        severity = \"critical\"\n    strings:\n        $config_start = { 2E 2F 2E 2F 2E 2C }\n        $sleep_mask = { 48 8B 44 24 ?? 48 89 44 24 ?? 48 8B 44 24 }\n        $named_pipe = \"\\\\\\\\\\\\\\\\.\\\\\\\\pipe\\\\\\\\msagent_\" ascii\n        $watermark = { 00 00 00 00 00 00 ?? ?? 00 00 }\n    condition:\n        2 of them\n}\n\"\"\")\n\nscan_memory_dump(memory_rules, \"\u002Fmnt\u002Fevidence\u002Flsass_dump.dmp\")\n```\n\n### Step 6: Generate Rules Automatically with yarGen\n\nUse yarGen to create rules from malware samples by extracting unique strings:\n\n```bash\n# Clone and set up yarGen\ngit clone https:\u002F\u002Fgithub.com\u002FNeo23x0\u002FyarGen.git\ncd yarGen\npip install -r requirements.txt\n\n# Download the string databases (run once)\npython3 yarGen.py --update\n\n# Generate rules from a directory of malware samples\npython3 yarGen.py \\\n    -m \u002Fmnt\u002Fevidence\u002Fmalware_samples\u002F \\\n    -o generated_rules.yar \\\n    --excludegood \\\n    -p \"AutoGen\" \\\n    -a \"Threat Hunting Team\" \\\n    --score 50\n\n# Generate rules for a single sample with maximum detail\npython3 yarGen.py \\\n    -m \u002Fmnt\u002Fevidence\u002Fmalware_samples\u002Fsuspicious.exe \\\n    -o single_sample_rule.yar \\\n    --opcodes \\\n    --debug\n```\n\n### Step 7: Integrate Community Rule Sets\n\nDownload and combine rules from public threat intelligence repositories:\n\n```bash\n# Clone Florian Roth's signature-base (large community rule set)\ngit clone https:\u002F\u002Fgithub.com\u002FNeo23x0\u002Fsignature-base.git\n\n# Clone YARA-Rules community repository\ngit clone https:\u002F\u002Fgithub.com\u002FYara-Rules\u002Frules.git yara-community-rules\n\n# Clone ReversingLabs YARA rules\ngit clone https:\u002F\u002Fgithub.com\u002Freversinglabs\u002Freversinglabs-yara-rules.git\n```\n\n```python\nimport yara\nfrom pathlib import Path\n\ndef load_rule_directory(rule_dir, extensions=(\".yar\", \".yara\")):\n    \"\"\"Load all YARA rules from a directory tree.\"\"\"\n    rule_files = {}\n    for ext in extensions:\n        for rule_file in Path(rule_dir).rglob(f\"*{ext}\"):\n            namespace = rule_file.stem\n            # Avoid namespace collisions\n            if namespace in rule_files:\n                namespace = f\"{rule_file.parent.name}_{namespace}\"\n            rule_files[namespace] = str(rule_file)\n\n    print(f\"Loading {len(rule_files)} rule files from {rule_dir}\")\n    try:\n        compiled = yara.compile(filepaths=rule_files)\n        return compiled\n    except yara.SyntaxError as e:\n        print(f\"Syntax error in rules: {e}\")\n        # Fall back to loading rules one by one, skipping broken ones\n        valid_rules = {}\n        for ns, path in rule_files.items():\n            try:\n                yara.compile(filepath=path)\n                valid_rules[ns] = path\n            except yara.SyntaxError:\n                print(f\"  Skipping broken rule: {path}\")\n        return yara.compile(filepaths=valid_rules)\n\n# Load and scan with community rules\ncommunity_rules = load_rule_directory(\"signature-base\u002Fyara\u002F\")\nmatches = community_rules.match(\"\u002Fmnt\u002Fevidence\u002Fsuspicious_file.exe\", timeout=120)\n\nfor m in matches:\n    print(f\"Matched: {m.rule} (namespace: {m.namespace})\")\n```\n\n### Step 8: Build a Continuous Hunting Pipeline\n\nAutomate scanning of new files as they arrive using filesystem monitoring:\n\n```python\nimport yara\nimport time\nimport json\nimport hashlib\nfrom pathlib import Path\nfrom watchdog.observers import Observer\nfrom watchdog.events import FileSystemEventHandler\n\nclass YaraHuntingHandler(FileSystemEventHandler):\n    def __init__(self, rules, alert_file=\"yara_alerts.jsonl\"):\n        self.rules = rules\n        self.alert_file = alert_file\n        self.scanned_hashes = set()\n\n    def on_created(self, event):\n        if event.is_directory:\n            return\n        self._scan_file(event.src_path)\n\n    def _scan_file(self, filepath):\n        # Deduplicate by file hash\n        try:\n            file_hash = hashlib.sha256(Path(filepath).read_bytes()).hexdigest()\n        except (PermissionError, FileNotFoundError):\n            return\n\n        if file_hash in self.scanned_hashes:\n            return\n        self.scanned_hashes.add(file_hash)\n\n        matches = self.rules.match(filepath, timeout=60)\n        if matches:\n            alert = {\n                \"timestamp\": time.strftime(\"%Y-%m-%dT%H:%M:%SZ\", time.gmtime()),\n                \"file\": filepath,\n                \"sha256\": file_hash,\n                \"matches\": [\n                    {\"rule\": m.rule, \"severity\": m.meta.get(\"severity\", \"unknown\")}\n                    for m in matches\n                ]\n            }\n            with open(self.alert_file, \"a\") as f:\n                f.write(json.dumps(alert) + \"\\n\")\n            print(f\"ALERT: {filepath} matched {len(matches)} rules\")\n\n# Set up continuous monitoring\nrules = yara.compile(filepaths={\"hunting\": \"rules\u002Fall_hunting_rules.yar\"})\nhandler = YaraHuntingHandler(rules)\nobserver = Observer()\nobserver.schedule(handler, path=\"\u002Fmnt\u002Fquarantine\u002F\", recursive=True)\nobserver.start()\nprint(\"YARA hunting pipeline active. Monitoring \u002Fmnt\u002Fquarantine\u002F ...\")\n```\n\n## Verification\n\n- Compile all custom rules without syntax errors: `yara -w rules\u002F*.yar \u002Fdev\u002Fnull`\n- Confirm rules match known-good malware samples from your test corpus (true positive validation)\n- Verify rules do NOT match a goodware corpus of common system files (false positive testing)\n- Test scanning performance: single file scan should complete within timeout threshold\n- Validate yarGen output rules compile and produce meaningful matches against the input samples\n- Check that community rule sets load without critical syntax errors after filtering\n- Confirm the continuous hunting pipeline generates alerts in JSONL format when test files are dropped\n- Cross-reference YARA matches against VirusTotal or sandbox results to validate detection accuracy\n","# Performing Threat Hunting with YARA Rules\n\nScan files, directories, and memory dumps using YARA rules to identify\nmalware families, suspicious patterns, and IOC matches.\n\n## When to Use\n\n- Proactively hunting for unknown malware variants across network shares, endpoints, and email attachments\n- Scanning quarantine directories or sandbox outputs for malware family classification\n- Searching process memory dumps for injected code or in-memory-only payloads\n- Validating threat intelligence IOCs against a large corpus of collected samples\n- Triaging incident response artifacts to identify known malware families quickly\n- Building automated detection pipelines that scan new files on ingestion\n\n**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.\n\n## Prerequisites\n\n- YARA 4.x installed (`apt install yara` on Debian\u002FUbuntu, `brew install yara` on macOS)\n- Python 3.8+ with `yara-python` (`pip install yara-python`)\n- `yarGen` for automated rule generation (`git clone https:\u002F\u002Fgithub.com\u002FNeo23x0\u002FyarGen`)\n- Sample malware corpus or suspicious files for scanning (from malware zoos, VT, or incident artifacts)\n- Optional: `pefile` for PE header analysis, `malduck` for memory carving\n- Threat intel YARA rule sets (e.g., YARA-Rules community repository, Florian Roth signature-base)\n\n## Workflow\n\n### Step 1: Install YARA and Python Bindings\n\n```bash\n# Linux\nsudo apt update && sudo apt install -y yara\n\n# Python bindings\npip install yara-python\n\n# Verify installation\nyara --version\npython3 -c \"import yara; print(yara.YARA_VERSION)\"\n```\n\n### Step 2: Write a Basic YARA Rule\n\nCreate rules that match on strings, hex patterns, and file metadata:\n\n```yara\n\u002F\u002F File: rules\u002Femotet_loader.yar\nrule Emotet_Loader_2026 {\n    meta:\n        author = \"Threat Intel Team\"\n        description = \"Detects Emotet first-stage loader DLL\"\n        date = \"2026-01-20\"\n        reference = \"https:\u002F\u002Fattack.mitre.org\u002Fsoftware\u002FS0367\u002F\"\n        mitre_attack = \"T1059.001, T1055.001\"\n        severity = \"critical\"\n\n    strings:\n        \u002F\u002F Emotet export function name patterns\n        $export1 = \"DllRegisterServer\" ascii\n        $export2 = \"RunDLL\" ascii nocase\n\n        \u002F\u002F Obfuscated string decryption routine\n        $decrypt_loop = { 8B 45 ?? 33 45 ?? 89 45 ?? 8B 4D ?? 03 4D ?? }\n\n        \u002F\u002F PowerShell download cradle in embedded script\n        $ps_cradle = \u002Fpowershell[^\\n]{0,50}-e(nc|ncodedcommand)\u002Fi\n\n        \u002F\u002F Known C2 URI patterns\n        $uri1 = \"\u002Fwp-content\u002Fuploads\u002F\" ascii\n        $uri2 = \"\u002Fwp-admin\u002Fcss\u002F\" ascii\n        $uri3 = \"\u002Fwp-includes\u002F\" ascii\n\n        \u002F\u002F PE characteristics\n        $mz = \"MZ\" at 0\n\n    condition:\n        $mz and\n        filesize \u003C 2MB and\n        (\n            ($export1 and $decrypt_loop) or\n            ($ps_cradle and any of ($uri*)) or\n            (2 of ($uri*) and $decrypt_loop)\n        )\n}\n```\n\n### Step 3: Write Advanced Rules with Modules\n\nUse YARA modules for PE header inspection and math-based entropy checks:\n\n```yara\nimport \"pe\"\nimport \"math\"\n\nrule Suspicious_Packed_Executable {\n    meta:\n        author = \"Threat Hunting Team\"\n        description = \"Detects PE files with high entropy sections indicating packing or encryption\"\n        severity = \"medium\"\n\n    condition:\n        pe.is_pe and\n        pe.number_of_sections > 0 and\n        for any section in pe.sections : (\n            math.entropy(section.offset, section.size) > 7.2 and\n            section.size > 1024\n        ) and\n        pe.imports(\"kernel32.dll\", \"VirtualAlloc\") and\n        pe.imports(\"kernel32.dll\", \"VirtualProtect\")\n}\n\nrule Suspicious_UPX_Modified {\n    meta:\n        description = \"Detects UPX-packed binaries with tampered section names\"\n        severity = \"medium\"\n\n    strings:\n        $upx_magic = { 55 50 58 21 }  \u002F\u002F UPX!\n\n    condition:\n        pe.is_pe and\n        $upx_magic and\n        not (\n            pe.sections[0].name == \"UPX0\" and\n            pe.sections[1].name == \"UPX1\"\n        )\n}\n```\n\n### Step 4: Scan Files and Directories with yara-python\n\n```python\nimport yara\nimport os\nimport json\nfrom datetime import datetime\nfrom pathlib import Path\n\ndef compile_rules(rule_paths):\n    \"\"\"Compile YARA rules from one or more .yar files.\"\"\"\n    rule_files = {}\n    for i, path in enumerate(rule_paths):\n        namespace = Path(path).stem\n        rule_files[namespace] = path\n    return yara.compile(filepaths=rule_files)\n\ndef scan_directory(rules, target_dir, recursive=True):\n    \"\"\"Scan a directory for matches and return structured results.\"\"\"\n    results = []\n    scan_count = 0\n    error_count = 0\n\n    for root, dirs, files in os.walk(target_dir):\n        for filename in files:\n            filepath = os.path.join(root, filename)\n            scan_count += 1\n            try:\n                matches = rules.match(filepath, timeout=60)\n                if matches:\n                    for match in matches:\n                        result = {\n                            \"file\": filepath,\n                            \"rule\": match.rule,\n                            \"namespace\": match.namespace,\n                            \"tags\": match.tags,\n                            \"meta\": match.meta,\n                            \"strings\": [],\n                            \"scan_time\": datetime.utcnow().isoformat()\n                        }\n                        for offset, identifier, data in match.strings:\n                            result[\"strings\"].append({\n                                \"offset\": hex(offset),\n                                \"identifier\": identifier,\n                                \"data\": data.hex() if isinstance(data, bytes) else data\n                            })\n                        results.append(result)\n                        print(f\"  MATCH: {match.rule} -> {filepath}\")\n            except yara.TimeoutError:\n                error_count += 1\n                print(f\"  TIMEOUT scanning {filepath}\")\n            except yara.Error as e:\n                error_count += 1\n\n        if not recursive:\n            break\n\n    print(f\"\\nScan complete: {scan_count} files scanned, \"\n          f\"{len(results)} matches, {error_count} errors\")\n    return results\n\n# Compile and scan\nrules = compile_rules([\n    \"rules\u002Femotet_loader.yar\",\n    \"rules\u002Fsuspicious_packed.yar\"\n])\n\nmatches = scan_directory(rules, \"\u002Fmnt\u002Fevidence\u002Fcollected_samples\u002F\")\n\n# Export results\nwith open(\"yara_scan_results.json\", \"w\") as f:\n    json.dump(matches, f, indent=2)\n```\n\n### Step 5: Scan Process Memory Dumps\n\nHunt for in-memory indicators that only exist in running processes:\n\n```python\nimport yara\n\ndef scan_memory_dump(rules, dump_path):\n    \"\"\"Scan a process memory dump for YARA matches.\"\"\"\n    matches = rules.match(dump_path, timeout=120)\n\n    for match in matches:\n        print(f\"Rule: {match.rule}\")\n        print(f\"  Severity: {match.meta.get('severity', 'unknown')}\")\n        for offset, identifier, data in match.strings:\n            # Show context around the match\n            print(f\"  String {identifier} at offset {hex(offset)}\")\n            if len(data) \u003C= 64:\n                print(f\"    Data: {data.hex()}\")\n\n    return matches\n\n# Rules targeting in-memory artifacts\nmemory_rules = yara.compile(source=\"\"\"\nrule Cobalt_Strike_Beacon_Memory {\n    meta:\n        description = \"Detects Cobalt Strike beacon in process memory\"\n        severity = \"critical\"\n    strings:\n        $config_start = { 2E 2F 2E 2F 2E 2C }\n        $sleep_mask = { 48 8B 44 24 ?? 48 89 44 24 ?? 48 8B 44 24 }\n        $named_pipe = \"\\\\\\\\\\\\\\\\.\\\\\\\\pipe\\\\\\\\msagent_\" ascii\n        $watermark = { 00 00 00 00 00 00 ?? ?? 00 00 }\n    condition:\n        2 of them\n}\n\"\"\")\n\nscan_memory_dump(memory_rules, \"\u002Fmnt\u002Fevidence\u002Flsass_dump.dmp\")\n```\n\n### Step 6: Generate Rules Automatically with yarGen\n\nUse yarGen to create rules from malware samples by extracting unique strings:\n\n```bash\n# Clone and set up yarGen\ngit clone https:\u002F\u002Fgithub.com\u002FNeo23x0\u002FyarGen.git\ncd yarGen\npip install -r requirements.txt\n\n# Download the string databases (run once)\npython3 yarGen.py --update\n\n# Generate rules from a directory of malware samples\npython3 yarGen.py \\\n    -m \u002Fmnt\u002Fevidence\u002Fmalware_samples\u002F \\\n    -o generated_rules.yar \\\n    --excludegood \\\n    -p \"AutoGen\" \\\n    -a \"Threat Hunting Team\" \\\n    --score 50\n\n# Generate rules for a single sample with maximum detail\npython3 yarGen.py \\\n    -m \u002Fmnt\u002Fevidence\u002Fmalware_samples\u002Fsuspicious.exe \\\n    -o single_sample_rule.yar \\\n    --opcodes \\\n    --debug\n```\n\n### Step 7: Integrate Community Rule Sets\n\nDownload and combine rules from public threat intelligence repositories:\n\n```bash\n# Clone Florian Roth's signature-base (large community rule set)\ngit clone https:\u002F\u002Fgithub.com\u002FNeo23x0\u002Fsignature-base.git\n\n# Clone YARA-Rules community repository\ngit clone https:\u002F\u002Fgithub.com\u002FYara-Rules\u002Frules.git yara-community-rules\n\n# Clone ReversingLabs YARA rules\ngit clone https:\u002F\u002Fgithub.com\u002Freversinglabs\u002Freversinglabs-yara-rules.git\n```\n\n```python\nimport yara\nfrom pathlib import Path\n\ndef load_rule_directory(rule_dir, extensions=(\".yar\", \".yara\")):\n    \"\"\"Load all YARA rules from a directory tree.\"\"\"\n    rule_files = {}\n    for ext in extensions:\n        for rule_file in Path(rule_dir).rglob(f\"*{ext}\"):\n            namespace = rule_file.stem\n            # Avoid namespace collisions\n            if namespace in rule_files:\n                namespace = f\"{rule_file.parent.name}_{namespace}\"\n            rule_files[namespace] = str(rule_file)\n\n    print(f\"Loading {len(rule_files)} rule files from {rule_dir}\")\n    try:\n        compiled = yara.compile(filepaths=rule_files)\n        return compiled\n    except yara.SyntaxError as e:\n        print(f\"Syntax error in rules: {e}\")\n        # Fall back to loading rules one by one, skipping broken ones\n        valid_rules = {}\n        for ns, path in rule_files.items():\n            try:\n                yara.compile(filepath=path)\n                valid_rules[ns] = path\n            except yara.SyntaxError:\n                print(f\"  Skipping broken rule: {path}\")\n        return yara.compile(filepaths=valid_rules)\n\n# Load and scan with community rules\ncommunity_rules = load_rule_directory(\"signature-base\u002Fyara\u002F\")\nmatches = community_rules.match(\"\u002Fmnt\u002Fevidence\u002Fsuspicious_file.exe\", timeout=120)\n\nfor m in matches:\n    print(f\"Matched: {m.rule} (namespace: {m.namespace})\")\n```\n\n### Step 8: Build a Continuous Hunting Pipeline\n\nAutomate scanning of new files as they arrive using filesystem monitoring:\n\n```python\nimport yara\nimport time\nimport json\nimport hashlib\nfrom pathlib import Path\nfrom watchdog.observers import Observer\nfrom watchdog.events import FileSystemEventHandler\n\nclass YaraHuntingHandler(FileSystemEventHandler):\n    def __init__(self, rules, alert_file=\"yara_alerts.jsonl\"):\n        self.rules = rules\n        self.alert_file = alert_file\n        self.scanned_hashes = set()\n\n    def on_created(self, event):\n        if event.is_directory:\n            return\n        self._scan_file(event.src_path)\n\n    def _scan_file(self, filepath):\n        # Deduplicate by file hash\n        try:\n            file_hash = hashlib.sha256(Path(filepath).read_bytes()).hexdigest()\n        except (PermissionError, FileNotFoundError):\n            return\n\n        if file_hash in self.scanned_hashes:\n            return\n        self.scanned_hashes.add(file_hash)\n\n        matches = self.rules.match(filepath, timeout=60)\n        if matches:\n            alert = {\n                \"timestamp\": time.strftime(\"%Y-%m-%dT%H:%M:%SZ\", time.gmtime()),\n                \"file\": filepath,\n                \"sha256\": file_hash,\n                \"matches\": [\n                    {\"rule\": m.rule, \"severity\": m.meta.get(\"severity\", \"unknown\")}\n                    for m in matches\n                ]\n            }\n            with open(self.alert_file, \"a\") as f:\n                f.write(json.dumps(alert) + \"\\n\")\n            print(f\"ALERT: {filepath} matched {len(matches)} rules\")\n\n# Set up continuous monitoring\nrules = yara.compile(filepaths={\"hunting\": \"rules\u002Fall_hunting_rules.yar\"})\nhandler = YaraHuntingHandler(rules)\nobserver = Observer()\nobserver.schedule(handler, path=\"\u002Fmnt\u002Fquarantine\u002F\", recursive=True)\nobserver.start()\nprint(\"YARA hunting pipeline active. Monitoring \u002Fmnt\u002Fquarantine\u002F ...\")\n```\n\n## Verification\n\n- Compile all custom rules without syntax errors: `yara -w rules\u002F*.yar \u002Fdev\u002Fnull`\n- Confirm rules match known-good malware samples from your test corpus (true positive validation)\n- Verify rules do NOT match a goodware corpus of common system files (false positive testing)\n- Test scanning performance: single file scan should complete within timeout threshold\n- Validate yarGen output rules compile and produce meaningful matches against the input samples\n- Check that community rule sets load without critical syntax errors after filtering\n- Confirm the continuous hunting pipeline generates alerts in JSONL format when test files are dropped\n- Cross-reference YARA matches against VirusTotal or sandbox results to validate detection accuracy\n",{"name":5,"tags":49,"author":50,"domain":41,"license":15,"version":51,"nist_csf":52,"subdomain":36,"description":57,"mitre_attack":58,"d3fend_techniques":64},[26,28,36,29],"mahipal","1.0",[53,54,55,56],"DE.CM-01","DE.AE-02","DE.AE-07","ID.RA-05","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.\n",[59,60,61,62,63],"T1046","T1057","T1082","T1083","T1005",[65,66,67,68,69],"Executable Denylisting","Execution Isolation","File Metadata Consistency Validation","Content Format Conversion","File Content Analysis","main","54a798831d2266a3ca61ce68a7acb80b81160d57","skills\u002Fperforming-threat-hunting-with-yara-rules",4414,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills","https:\u002F\u002Fmahipal.engineer\u002FAnthropic-Cybersecurity-Skills\u002F","https:\u002F\u002Fgithub.com\u002Fmukul975","Mahipal.engineer","🔐 Cybersecurity | 💻 Dev | 📷 Street Photographer\r\n🎓 MSc | 📚 Research & AI Security","2026-08-31 12:32:44",{"source":8,"skillName":5,"commands":81,"prompt":91,"zipAvailable":92},[82,85,88],{"tool":83,"command":84},"npx","npx skills add mukul975\u002FAnthropic-Cybersecurity-Skills --skill performing-threat-hunting-with-yara-rules",{"tool":86,"command":87},"bunx","bunx skills add mukul975\u002FAnthropic-Cybersecurity-Skills --skill performing-threat-hunting-with-yara-rules",{"tool":89,"command":90},"pnpm","pnpm dlx skills add mukul975\u002FAnthropic-Cybersecurity-Skills --skill performing-threat-hunting-with-yara-rules","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fperforming-threat-hunting-with-yara-rules\u002FSKILL.md",true,[94,99,103,109,113,117,123,127,131],{"path":95,"resourceType":95,"resourceTypeDesc":96,"sizeBytes":97,"sourceHtmlUrl":98},"LICENSE","许可证",11255,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fperforming-threat-hunting-with-yara-rules\u002FLICENSE",{"path":100,"resourceType":95,"resourceTypeDesc":96,"sizeBytes":101,"sourceHtmlUrl":102},"LICENSE.txt",11357,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftravisvn-awesome-claude-skills\u002Fanthropics-skills\u002Fskills\u002Fskill-creator\u002FLICENSE.txt",{"path":104,"resourceType":105,"resourceTypeDesc":106,"sizeBytes":107,"sourceHtmlUrl":108},"references\u002Fapi-reference.md","REFERENCE","参考文档",2176,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fperforming-threat-hunting-with-yara-rules\u002Freferences\u002Fapi-reference.md",{"path":110,"resourceType":105,"resourceTypeDesc":106,"sizeBytes":111,"sourceHtmlUrl":112},"references\u002Foutput-patterns.md",1813,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftravisvn-awesome-claude-skills\u002Fanthropics-skills\u002Fskills\u002Fskill-creator\u002Freferences\u002Foutput-patterns.md",{"path":114,"resourceType":105,"resourceTypeDesc":106,"sizeBytes":115,"sourceHtmlUrl":116},"references\u002Fworkflows.md",818,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftravisvn-awesome-claude-skills\u002Fanthropics-skills\u002Fskills\u002Fskill-creator\u002Freferences\u002Fworkflows.md",{"path":118,"resourceType":119,"resourceTypeDesc":120,"sizeBytes":121,"sourceHtmlUrl":122},"scripts\u002Fagent.py","SCRIPT","脚本",5743,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fperforming-threat-hunting-with-yara-rules\u002Fscripts\u002Fagent.py",{"path":124,"resourceType":119,"resourceTypeDesc":120,"sizeBytes":125,"sourceHtmlUrl":126},"scripts\u002Finit_skill.py",10863,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftravisvn-awesome-claude-skills\u002Fanthropics-skills\u002Fskills\u002Fskill-creator\u002Fscripts\u002Finit_skill.py",{"path":128,"resourceType":119,"resourceTypeDesc":120,"sizeBytes":129,"sourceHtmlUrl":130},"scripts\u002Fpackage_skill.py",3288,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftravisvn-awesome-claude-skills\u002Fanthropics-skills\u002Fskills\u002Fskill-creator\u002Fscripts\u002Fpackage_skill.py",{"path":132,"resourceType":119,"resourceTypeDesc":120,"sizeBytes":133,"sourceHtmlUrl":134},"scripts\u002Fquick_validate.py",3523,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftravisvn-awesome-claude-skills\u002Fanthropics-skills\u002Fskills\u002Fskill-creator\u002Fscripts\u002Fquick_validate.py",[136,163,187,213,239,266],{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":143,"publishedAt":44},"01M6AGDM3HJXTKXX15ZZ0ZVCJ3","verifying-build-provenance-with-slsa-sigstore","Verifies artifact signatures and SLSA provenance using Sigstore's cosign (verify, verify-attestation, verify-blob-attestation) and slsa-verifier (verify-artifact), enforcing keyless OIDC builder identity and source repo against SLSA Build levels. Use in CI\u002FCD before deploying artifacts, when consuming third-party attestations, establishing a SLSA Build L3 pipeline, or confirming provenance during incident response or admission control.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fverifying-build-provenance-with-slsa-sigstore\u002FSKILL.md",[142],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[144,145,146,147,148,41,149,150,151,152,153,154,155,156,157,158,159,160,161,162],"sigstore","provenance","slsa","verifying build provenance with slsa sigstore","security","incident response","identity","pr","code","artifacts","ci","supply-chain","pipeline","supply-chain-security","t1195","attestation","code-signing","cosign","keyless",{"skillNo":164,"name":165,"nameZh":6,"description":166,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":167,"categories":168,"keywords":170,"publishedAt":44},"01M6AGDGBPWYVZ2F11GFKJ4HZ9","validating-tpm-measured-boot-attestation","Verifies TPM 2.0 measured-boot integrity and remote attestation with tpm2-tools -- reading PCRs (tpm2_pcrread), replaying the boot event log, generating and checking signed quotes (tpm2_quote\u002Ftpm2_checkquote), and sealing secrets to a PCR policy. Use to confirm a system booted trusted firmware\u002Fkernel for Zero Trust device posture, detect boot-chain tampering via PCR drift, or build a golden-value baseline for fleet attestation.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fvalidating-tpm-measured-boot-attestation\u002FSKILL.md",[169],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[171,159,172,173,148,174,41,151,175,176,177,178,179,180,181,182,183,184,185,186],"boot","TPM","validating tpm measured boot attestation","policy","verification","ZeRO","firmware","Tools","measured-boot","PCR","integrity","secrets","remote-attestation","tpm2-tools","integrity-verification","trusted-computing",{"skillNo":188,"name":189,"nameZh":6,"description":190,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":191,"categories":192,"keywords":197,"publishedAt":44},"01M6AGDCW0Y4FXZ3362GT1941M","validating-backup-integrity-for-recovery","Validates backup integrity through cryptographic hash verification, automated restore testing, corruption detection, and recoverability checks to confirm backups are reliable for disaster recovery and ransomware response. Use before relying on backups for recovery, when building post-backup validation pipelines, auditing backup infrastructure for compliance, or checking immutable\u002Fair-gapped backups for silent corruption or tampering.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fvalidating-backup-integrity-for-recovery\u002FSKILL.md",[193,196],{"categoryNo":194,"categoryName":195,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量",{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[181,198,199,200,201,41,202,40,175,203,204,205,206,207,33,208,209,210,211,212],"backup","recovery","validating backup integrity for recovery","testing","infrastructure","compliance","hash-verification","incident-response","ransomware","cryptocurrency","t1078","t1490","immutable","disaster-recovery","restore-testing",{"skillNo":214,"name":215,"nameZh":6,"description":216,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":217,"categories":218,"keywords":220,"publishedAt":44},"01M6AGD9GBG2KZ336AE763J3WH","triaging-windows-with-kape","Runs KAPE (Kroll Artifact Parser and Extractor) to collect targeted forensic artifacts (registry hives, $MFT, event logs, prefetch, browser data) via Targets and parse them with Modules wrapping Eric Zimmerman's EZ Tools (PECmd, MFTECmd, RECmd). Use during early incident containment\u002Ftriage when full disk imaging is impractical but a defensible, parseable Windows artifact set is needed quickly, including at-scale remote collection.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftriaging-windows-with-kape\u002FSKILL.md",[219],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[221,222,223,41,224,225,226,227,228,229,230,231,232,233,234,235,178,236,237,238],"windows","kape","triaging windows with kape","registry","browser","logs","windows-forensics","dfir","mft","mftecmd","data","prefetch","eric-zimmerman","digital-forensics","SET","collection","pecmd","artifact-collection",{"skillNo":240,"name":241,"nameZh":6,"description":242,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":243,"categories":244,"keywords":246,"publishedAt":44},"01M6AGD5PW5J4EVZM958WD74ZQ","triaging-vulnerabilities-with-ssvc-framework","Triages and prioritizes vulnerabilities with CISA's Stakeholder-Specific Vulnerability Categorization (SSVC) decision tree, weighing exploitation status (via the CISA KEV catalog and FIRST EPSS API), technical impact, automatability, and mission prevalence to output Track\u002FTrack*\u002FAttend\u002FAct decisions. Use when prioritizing vulnerability scan results (OpenVAS, Nessus, Qualys) for remediation planning beyond raw CVSS scores.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftriaging-vulnerabilities-with-ssvc-framework\u002FSKILL.md",[245],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[247,248,249,41,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265],"vulnerabilities","framework","triaging vulnerabilities with ssvc framework","status","planning","CISA","vulnerability-management","risk-management","nessus","qualys","openvas","cvss","remediation","risk","vulnerability","api","prioritization","ssvc","decision-tree",{"skillNo":267,"name":268,"nameZh":6,"description":269,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":270,"categories":271,"keywords":273,"publishedAt":44},"01M6AGD24TTQQM4CXG69E3B9TJ","triaging-security-incident","Performs initial triage of security incidents using the NIST SP 800-61r3 and SANS PICERL frameworks, classifying incident type, assigning priority by business impact, and routing to the appropriate response team. Use when a SIEM\u002FEDR alert needs human classification, concurrent alerts must be prioritized, or a user report or threat-intel IOC match requires initial incident categorization.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftriaging-security-incident\u002FSKILL.md",[272],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[148,274,41,275,38,276,277,278,279,280,281,208,32,209,30,282,283,284,285,286],"triaging security incident","siem","ioc","soc","NIST-800-61","NIST","severity","edr","classification","severity-classification","incident-triage","SANS-PICERL","SOC-operations"]