
Building Attack Pattern Library From Cti Reports
- 188 installs
- 27.3k repo stars
- Updated August 2, 2026
- mukul975/anthropic-cybersecurity-skills
building-attack-pattern-library-from-cti-reports is a Claude Code security skill that extracts adversary techniques from threat intelligence reports into a STIX-based library mapped to MITRE ATT&CK for detection engineer
About
This skill extracts adversary techniques from cyber threat intelligence reports and catalogs them into a structured STIX 2.1 attack pattern library mapped to MITRE ATT&CK. It parses reports from vendors like Mandiant and CrowdStrike, matches behaviors to ATT&CK technique IDs, and generates detection rule templates such as Sigma and YARA. A security engineer uses it for detection engineering and threat-informed defense. It requires Python with the stix2, mitreattack-python, and spaCy libraries.
- Extracts adversary behaviors from CTI reports via NLP
- Maps techniques to MITRE ATT&CK technique IDs
- Builds STIX 2.1 Attack Pattern objects
- Generates Sigma and YARA detection rule templates
Building Attack Pattern Library From Cti Reports by the numbers
- 188 all-time installs (skills.sh)
- +8 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #798 of 2,203 Security skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
building-attack-pattern-library-from-cti-reports capabilities & compatibility
Free skill; requires Python libraries and MITRE ATT&CK STIX data.
- Capabilities
- cti parsing · attack pattern extraction · mitre attack mapping · detection rule generation
- Use cases
- security audit · research · data analysis
- Pricing
- Free
What building-attack-pattern-library-from-cti-reports says it does
Extract and catalog attack patterns from cyber threat intelligence reports
STIX defines Attack Pattern as a Structured Domain Object (SDO) that describes ways threat actors attempt to compromise targets.
Python 3.9+ with `stix2`, `mitreattack-python`, `spacy`, `requests` libraries
npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill building-attack-pattern-library-from-cti-reportsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 188 |
|---|---|
| repo stars | ★ 27.3k |
| Last updated | August 2, 2026 |
| Repository | mukul975/anthropic-cybersecurity-skills ↗ |
How do I turn narrative CTI reports into structured, ATT&CK-mapped attack patterns and detection rules?
Extracting adversary techniques from CTI reports into a STIX library mapped to MITRE ATT&CK for detection engineering.
Who is it for?
Detection engineers and threat-intel analysts turning vendor CTI reports into a searchable ATT&CK-mapped pattern library.
Skip if: Teams without CTI reports to process or without detection-engineering context (Sigma, YARA, ATT&CK).
When should I use this skill?
When establishing threat-informed defense: parsing CTI reports to catalog adversary techniques and generate detection rule templates.
What you get
A searchable STIX 2.1 attack pattern library indexed by tactic, technique, and threat actor, with detection rule templates.
- STIX 2.1 Attack Pattern objects mapped to ATT&CK
- Searchable library indexed by tactic, technique, threat actor
- Sigma/YARA detection rule templates
By the numbers
- 5 MITRE ATT&CK technique references (T1566.001, T1059.001, T1003.001, T1558.003, T1550.002)
- 5 D3FEND techniques referenced
Files
Building Attack Pattern Library from CTI Reports
Overview
Cyber threat intelligence (CTI) reports from vendors like Mandiant, CrowdStrike, Talos, and Microsoft contain detailed descriptions of adversary behaviors that can be extracted, normalized, and cataloged into a structured attack pattern library. This skill covers parsing CTI reports to extract adversary techniques, mapping behaviors to MITRE ATT&CK technique IDs, creating STIX 2.1 Attack Pattern objects, building a searchable library indexed by tactic, technique, and threat actor, and generating detection rule templates from documented patterns.
When to Use
- When deploying or configuring building attack pattern library from cti reports capabilities in your environment
- When establishing security controls aligned to compliance requirements
- When building or improving security architecture for this domain
- When conducting security assessments that require this implementation
Prerequisites
- Python 3.9+ with
stix2,mitreattack-python,spacy,requestslibraries - Collection of CTI reports (PDF, HTML, or text format)
- MITRE ATT&CK STIX data (local or via TAXII)
- Understanding of ATT&CK technique structure and naming conventions
- Familiarity with detection engineering concepts (Sigma, YARA)
Key Concepts
Attack Pattern Extraction
CTI reports describe adversary behaviors in natural language. Extraction involves identifying action verbs and technical terms that map to ATT&CK techniques, recognizing tool names and malware families, identifying infrastructure indicators, and mapping sequences of behaviors to attack chains (kill chain phases).
STIX 2.1 Attack Pattern Objects
STIX defines Attack Pattern as a Structured Domain Object (SDO) that describes ways threat actors attempt to compromise targets. Each pattern links to ATT&CK via external references, includes kill chain phases (tactics), and can be related to Intrusion Sets, Malware, and Tool objects.
Detection Rule Generation
Extracted attack patterns inform detection engineering by providing: specific procedure examples for Sigma rule creation, behavioral sequences for correlation rules, IOC patterns for YARA and Snort rules, and data source requirements for telemetry gaps.
Workflow
Step 1: Parse CTI Reports and Extract Behaviors
import re
import json
from collections import defaultdict
class CTIReportParser:
"""Parse CTI reports to extract adversary behaviors."""
BEHAVIOR_INDICATORS = [
"used", "executed", "deployed", "leveraged", "exploited",
"established", "created", "modified", "downloaded", "uploaded",
"exfiltrated", "injected", "enumerated", "spawned", "dropped",
"persisted", "escalated", "moved laterally", "collected",
"encrypted", "compressed", "encoded", "obfuscated",
]
TOOL_PATTERNS = [
r'\b(Cobalt Strike|Mimikatz|PsExec|BloodHound|Rubeus|Impacket)\b',
r'\b(PowerShell|cmd\.exe|WMI|WMIC|certutil|bitsadmin)\b',
r'\b(Metasploit|Empire|Covenant|Sliver|Brute Ratel)\b',
r'\b(Lazagne|SharpHound|ADFind|Sharphound|Invoke-Obfuscation)\b',
]
TECHNIQUE_KEYWORDS = {
"spearphishing": "T1566",
"phishing attachment": "T1566.001",
"phishing link": "T1566.002",
"powershell": "T1059.001",
"command line": "T1059.003",
"scheduled task": "T1053.005",
"registry run key": "T1547.001",
"process injection": "T1055",
"dll side-loading": "T1574.002",
"credential dumping": "T1003",
"lsass": "T1003.001",
"kerberoasting": "T1558.003",
"pass the hash": "T1550.002",
"remote desktop": "T1021.001",
"smb": "T1021.002",
"winrm": "T1021.006",
"data staging": "T1074",
"exfiltration over c2": "T1041",
"dns tunneling": "T1071.004",
"web shell": "T1505.003",
}
def parse_report(self, text, report_metadata=None):
"""Parse a CTI report and extract behaviors."""
sentences = re.split(r'[.!?]\s+', text)
behaviors = []
for sentence in sentences:
sentence_lower = sentence.lower()
# Check for behavior indicators
for indicator in self.BEHAVIOR_INDICATORS:
if indicator in sentence_lower:
behavior = {
"sentence": sentence.strip(),
"action": indicator,
"tools": self._extract_tools(sentence),
"technique_hints": self._match_techniques(sentence_lower),
}
if behavior["technique_hints"]:
behaviors.append(behavior)
break
print(f"[+] Extracted {len(behaviors)} behavioral indicators from report")
return behaviors
def _extract_tools(self, text):
"""Extract tool/malware names from text."""
tools = set()
for pattern in self.TOOL_PATTERNS:
matches = re.findall(pattern, text, re.IGNORECASE)
tools.update(matches)
return list(tools)
def _match_techniques(self, text):
"""Match text to ATT&CK technique hints."""
matches = []
for keyword, tech_id in self.TECHNIQUE_KEYWORDS.items():
if keyword in text:
matches.append({"keyword": keyword, "technique_id": tech_id})
return matches
parser = CTIReportParser()
sample_report = """
The threat actor used spearphishing attachments with macro-enabled documents to
gain initial access. Once inside, they executed PowerShell scripts to download
additional tooling. The actor leveraged Mimikatz to dump credentials from LSASS
memory. They then used pass the hash techniques for lateral movement via SMB
to multiple systems. Data was staged in a compressed archive and exfiltrated
over the existing C2 channel. The actor established persistence through
scheduled tasks and registry run keys.
"""
behaviors = parser.parse_report(sample_report)Step 2: Map Behaviors to ATT&CK Techniques
from attackcti import attack_client
class ATTACKMapper:
def __init__(self):
self.lift = attack_client()
self.techniques = {}
self._load_techniques()
def _load_techniques(self):
"""Load all ATT&CK techniques for mapping."""
all_techs = self.lift.get_enterprise_techniques()
for tech in all_techs:
tech_id = ""
for ref in tech.get("external_references", []):
if ref.get("source_name") == "mitre-attack":
tech_id = ref.get("external_id", "")
break
if tech_id:
self.techniques[tech_id] = {
"name": tech.get("name", ""),
"description": tech.get("description", "")[:500],
"tactics": [p.get("phase_name") for p in tech.get("kill_chain_phases", [])],
"platforms": tech.get("x_mitre_platforms", []),
"data_sources": tech.get("x_mitre_data_sources", []),
}
print(f"[+] Loaded {len(self.techniques)} ATT&CK techniques")
def map_behaviors(self, behaviors):
"""Map extracted behaviors to ATT&CK techniques."""
mapped = []
for behavior in behaviors:
for hint in behavior.get("technique_hints", []):
tech_id = hint["technique_id"]
if tech_id in self.techniques:
tech_info = self.techniques[tech_id]
mapped.append({
"technique_id": tech_id,
"technique_name": tech_info["name"],
"tactics": tech_info["tactics"],
"source_sentence": behavior["sentence"],
"tools_observed": behavior["tools"],
"keyword_matched": hint["keyword"],
"data_sources": tech_info["data_sources"],
})
print(f"[+] Mapped {len(mapped)} behaviors to ATT&CK techniques")
return mapped
mapper = ATTACKMapper()
mapped_behaviors = mapper.map_behaviors(behaviors)Step 3: Create STIX 2.1 Attack Pattern Library
from stix2 import AttackPattern, Relationship, Bundle, TLP_GREEN
from datetime import datetime
class AttackPatternLibrary:
def __init__(self):
self.patterns = []
self.relationships = []
def add_pattern_from_mapping(self, mapping, report_source="CTI Report"):
"""Create STIX Attack Pattern from mapped behavior."""
pattern = AttackPattern(
name=mapping["technique_name"],
description=f"Observed: {mapping['source_sentence']}\n\n"
f"Tools: {', '.join(mapping['tools_observed']) or 'None identified'}\n"
f"Source: {report_source}",
external_references=[{
"source_name": "mitre-attack",
"external_id": mapping["technique_id"],
"url": f"https://attack.mitre.org/techniques/{mapping['technique_id'].replace('.', '/')}/",
}],
kill_chain_phases=[{
"kill_chain_name": "mitre-attack",
"phase_name": tactic,
} for tactic in mapping["tactics"]],
object_marking_refs=[TLP_GREEN],
)
self.patterns.append(pattern)
return pattern
def build_library(self, mapped_behaviors, report_source="CTI Report"):
"""Build complete attack pattern library from mappings."""
seen_techniques = set()
for mapping in mapped_behaviors:
tech_id = mapping["technique_id"]
if tech_id not in seen_techniques:
self.add_pattern_from_mapping(mapping, report_source)
seen_techniques.add(tech_id)
bundle = Bundle(objects=self.patterns + self.relationships)
print(f"[+] Library: {len(self.patterns)} attack patterns")
return bundle
def export_library(self, output_file="attack_pattern_library.json"):
bundle = Bundle(objects=self.patterns + self.relationships)
with open(output_file, "w") as f:
f.write(bundle.serialize(pretty=True))
print(f"[+] Library exported to {output_file}")
def generate_detection_templates(self, mapped_behaviors):
"""Generate Sigma rule templates from attack patterns."""
templates = []
for mapping in mapped_behaviors:
template = {
"title": f"Detection: {mapping['technique_name']} ({mapping['technique_id']})",
"status": "experimental",
"description": f"Detects {mapping['technique_name']} based on CTI report observation",
"references": [
f"https://attack.mitre.org/techniques/{mapping['technique_id'].replace('.', '/')}/",
],
"tags": [
f"attack.{mapping['tactics'][0]}" if mapping['tactics'] else "attack.unknown",
f"attack.{mapping['technique_id'].lower()}",
],
"data_sources": mapping.get("data_sources", []),
"observed_tools": mapping.get("tools_observed", []),
"source_context": mapping["source_sentence"],
}
templates.append(template)
with open("detection_templates.json", "w") as f:
json.dump(templates, f, indent=2)
print(f"[+] Generated {len(templates)} detection templates")
return templates
library = AttackPatternLibrary()
bundle = library.build_library(mapped_behaviors, "Sample CTI Report")
library.export_library()
templates = library.generate_detection_templates(mapped_behaviors)Validation Criteria
- CTI report parsed and behavioral indicators extracted
- Behaviors mapped to ATT&CK techniques with confidence
- STIX 2.1 Attack Pattern objects created with proper references
- Library searchable by tactic, technique, and threat actor
- Detection templates generated from documented patterns
- Library exportable as STIX bundle for sharing
References
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to the Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by the Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding any notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. Please do not remove or change
the license header comment from a contributed file except when
necessary.
Copyright 2026 mukul975
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
API Reference: Attack Pattern Library from CTI Reports
Technique Extraction Patterns
| Technique | Regex Pattern |
|---|---|
| T1566.001 | spearphish.*attach |
| T1059.001 | powershell, invoke-expression |
| T1053.005 | scheduled task, schtasks |
| T1547.001 | registry run key, CurrentVersion\\Run |
| T1003.001 | lsass, credential dump, mimikatz |
| T1486 | ransomware encrypt |
| T1048 | exfiltration, data theft |
IOC Extraction Regex
| IOC Type | Pattern |
|---|---|
| IPv4 | \b(?:\d{1,3}\.){3}\d{1,3}\b |
| Domain | `[a-zA-Z0-9-]+\.(?:com\ |
| MD5 | [a-fA-F0-9]{32} |
| SHA-256 | [a-fA-F0-9]{64} |
| Defanged URL | hxxps?://[^\s]+ |
| Explicit technique | T\d{4}(?:\.\d{3})? |
STIX Attack Pattern
{
"type": "attack-pattern",
"name": "Spearphishing Attachment",
"external_references": [
{"source_name": "mitre-attack", "external_id": "T1566.001"}
],
"kill_chain_phases": [
{"phase_name": "initial-access"}
]
}Library Output Structure
| Field | Description |
|---|---|
technique_frequency | Count per technique across reports |
technique_report_map | Which reports mention each technique |
total_unique_techniques | Distinct techniques found |
MITRE ATT&CK STIX Data
https://raw.githubusercontent.com/mitre/cti/master/enterprise-attack/enterprise-attack.json#!/usr/bin/env python3
"""Attack Pattern Library Builder Agent - Extracts attack patterns from CTI reports and maps to MITRE ATT&CK."""
import json
import re
import logging
import argparse
from datetime import datetime
from collections import Counter, defaultdict
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
logger = logging.getLogger(__name__)
TECHNIQUE_PATTERNS = {
"T1566.001": [r"spearphish(?:ing)?\s+attach", r"malicious\s+(?:email\s+)?attachment"],
"T1566.002": [r"spearphish(?:ing)?\s+link", r"phishing\s+(?:url|link)"],
"T1059.001": [r"powershell", r"invoke-(?:expression|command|webrequest)"],
"T1059.003": [r"cmd\.exe", r"command\s+(?:prompt|shell|line)"],
"T1053.005": [r"scheduled\s+task", r"schtasks"],
"T1547.001": [r"registry\s+run\s+key", r"autostart", r"CurrentVersion\\\\Run"],
"T1003.001": [r"lsass", r"credential\s+dump", r"mimikatz"],
"T1021.001": [r"remote\s+desktop", r"rdp\s+lateral"],
"T1021.002": [r"smb\s+share", r"admin\s*\$", r"C\s*\$\s+share"],
"T1071.001": [r"http\s+c2", r"web\s+(?:beacon|c2)", r"https?\s+callback"],
"T1486": [r"encrypt(?:ion|ed)\s+(?:file|data)", r"ransomware\s+encrypt"],
"T1048": [r"exfiltrat(?:e|ion)", r"data\s+(?:theft|steal|upload)"],
"T1105": [r"download(?:ed)?\s+(?:payload|malware|tool)", r"ingress\s+tool\s+transfer"],
"T1027": [r"obfuscat(?:e|ion|ed)", r"encoded\s+(?:payload|script)"],
"T1562.001": [r"disable\s+(?:antivirus|defender|security)", r"tamper\s+protection"],
}
def extract_techniques_from_text(text):
"""Extract MITRE ATT&CK techniques from report text."""
text_lower = text.lower()
matched = {}
for tech_id, patterns in TECHNIQUE_PATTERNS.items():
for pattern in patterns:
if re.search(pattern, text_lower):
matched[tech_id] = {"pattern_matched": pattern, "technique_id": tech_id}
break
explicit = re.findall(r"T\d{4}(?:\.\d{3})?", text)
for tid in explicit:
if tid not in matched:
matched[tid] = {"pattern_matched": "explicit_reference", "technique_id": tid}
return matched
def extract_iocs_from_text(text):
"""Extract IOCs from report text."""
iocs = {
"ips": list(set(re.findall(r"\b(?:\d{1,3}\.){3}\d{1,3}\b", text))),
"domains": list(set(re.findall(r"\b(?:[a-zA-Z0-9-]+\.)+(?:com|net|org|io|xyz|top|info|ru|cn)\b", text))),
"hashes_md5": list(set(re.findall(r"\b[a-fA-F0-9]{32}\b", text))),
"hashes_sha256": list(set(re.findall(r"\b[a-fA-F0-9]{64}\b", text))),
"urls": list(set(re.findall(r"hxxps?://[^\s<>\"]+", text))),
}
return iocs
def process_report(report_text, report_name=""):
"""Process a single CTI report to extract attack patterns."""
techniques = extract_techniques_from_text(report_text)
iocs = extract_iocs_from_text(report_text)
return {
"report_name": report_name,
"techniques_found": len(techniques),
"technique_ids": list(techniques.keys()),
"technique_details": techniques,
"ioc_counts": {k: len(v) for k, v in iocs.items()},
"iocs": iocs,
}
def build_pattern_library(processed_reports):
"""Build a consolidated attack pattern library from multiple reports."""
technique_frequency = Counter()
technique_reports = defaultdict(list)
for report in processed_reports:
for tid in report["technique_ids"]:
technique_frequency[tid] += 1
technique_reports[tid].append(report["report_name"])
library = {
"technique_frequency": dict(technique_frequency.most_common()),
"technique_report_map": {t: r for t, r in technique_reports.items()},
"total_unique_techniques": len(technique_frequency),
"total_reports_processed": len(processed_reports),
}
return library
def generate_report(processed_reports, library):
"""Generate attack pattern library report."""
report = {
"timestamp": datetime.utcnow().isoformat(),
"library": library,
"report_details": processed_reports,
}
print(f"PATTERN LIBRARY: {library['total_unique_techniques']} techniques from {library['total_reports_processed']} reports")
return report
def main():
parser = argparse.ArgumentParser(description="Attack Pattern Library Builder Agent")
parser.add_argument("--report-files", nargs="+", required=True, help="CTI report text files")
parser.add_argument("--output", default="pattern_library.json")
args = parser.parse_args()
processed = []
for filepath in args.report_files:
with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
text = f.read()
result = process_report(text, filepath)
processed.append(result)
logger.info("Processed %s: %d techniques", filepath, result["techniques_found"])
library = build_pattern_library(processed)
report = generate_report(processed, library)
with open(args.output, "w") as f:
json.dump(report, f, indent=2)
logger.info("Report saved to %s", args.output)
if __name__ == "__main__":
main()
Related skills
FAQ
What does this skill produce?
STIX 2.1 Attack Pattern objects mapped to MITRE ATT&CK, a library indexed by tactic, technique and threat actor, and detection rule templates.
Which sources can it parse?
CTI reports from vendors like Mandiant, CrowdStrike, Talos, and Microsoft in PDF, HTML, or text format.
What are the dependencies?
Python 3.9+ with stix2, mitreattack-python, spacy, and requests, plus local or TAXII MITRE ATT&CK STIX data.