mcpField
B
building-threat-feed-aggregation-with-misp

building-threat-feed-aggregation-with-misp

github.com/mukul975安全35.2k146 次安装8 周前更新
代码仓库

关于 building-threat-feed-aggregation-with-misp

面向安全团队的 MISP 威胁情报聚合与共享部署指南,涵盖 Docker 部署、Feed 同步、指标关联及 SIEM 导出。内容还涉及实例间共享和 STIX/TAXII 集成。

主要功能

  1. 01通过 Docker 部署 MISP
  2. 02配置并同步威胁情报 Feed
  3. 03搜索和关联威胁指标
  4. 04导出到 Splunk 和 Elasticsearch
  5. 05通过推送与拉取同步 MISP 实例

适用场景

  1. 01汇集 OSINT 和其他 Feed 中的指标
  2. 02关联事件中的威胁指标
  3. 03将 IOC 导入 SIEM
  4. 04在 MISP 社区间共享情报

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill building-threat-feed-aggregation-with-misp

安装后在 Claude Code 中输入/building-threat-feed-aggregation-with-misp确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

使用 MISP 构建威胁情报源聚合

概述

MISP 是领先的开源威胁情报平台,用于收集、存储、分发和共享网络安全指标及威胁情报。它汇聚来自 OSINT 来源、商业提供商和共享社区的威胁情报源,整合到统一平台中,具备自动关联、STIX/TAXII 导出,以及与 SIEM 和安全工具的直接集成能力。本技能涵盖通过 Docker 部署 MISP、配置来自 abuse.ch、AlienVault OTX 和 CIRCL 等来源的威胁情报源、设置自动威胁情报源同步,以及与 Splunk、Elasticsearch 和 SOAR 平台的集成。

适用场景

  • 在环境中部署或配置使用 MISP 构建威胁情报源聚合的能力时
  • 建立符合合规要求的安全控制措施时
  • 为该领域构建或改进安全架构时
  • 执行需要此实现的安全评估时

前置条件

  • 用于部署的 Docker 和 Docker Compose
  • Python 3.9+ 及用于 API 交互的 pymisp 库
  • 用于生产部署的 8GB+ 内存 Linux 服务器
  • 了解 IOC 类型和威胁情报生命周期
  • 对外部威胁情报源 URL 的网络访问权限

核心概念

MISP 架构

MISP 将威胁情报存储为 Events(事件),其中包含按类型和类别组织的 Attributes(属性,即 IOC)。事件可以包含 Tags(标签,如 MITRE ATT&CK、TLP 标记、行业标签)、Galaxies( galaxies,如威胁行为者画像、恶意软件家族、攻击模式)和 Objects(对象,即相关属性的结构化分组)。事件在实例内自动关联。

威胁情报源类型

MISP 支持三种威胁情报源格式:MISP 格式(原生 JSON 事件)、CSV(逗号分隔的 IOC)和 freetext(非结构化文本,自动提取 IOC)。威胁情报源可以是远程的(从 URL 获取)或本地的(上传的文件)。MISP 内置 80+ 默认 OSINT 威胁情报源,包括 abuse.ch URLhaus、Botvrij、CIRCL OSINT 和恶意流量分析。

共享与同步

MISP 实例可以通过 push/pull 机制与其他 MISP 实例同步。共享组控制分发范围(仅本组织、本社区、已连接社区、所有社区)。TAXII 服务器模块支持与 STIX/TAXII 消费者集成。

工作流

步骤 1:使用 Docker 部署 MISP
# docker-compose.yml for MISP deployment
version: '3.8'
services:
  misp:
    image: coolacid/misp-docker:core-latest
    container_name: misp
    restart: unless-stopped
    ports:
      - "443:443"
      - "80:80"
    environment:
      - MYSQL_HOST=misp-db
      - MYSQL_DATABASE=misp
      - MYSQL_USER=misp
      - MYSQL_PASSWORD=misp_db_password_change_me
      - [email protected]
      - MISP_ADMIN_PASSPHRASE=admin_password_change_me
      - MISP_BASEURL=https://misp.organization.com
      - POSTFIX_RELAY_HOST=smtp.organization.com
      - TIMEZONE=UTC
    volumes:
      - misp-data:/var/www/MISP/app/files
      - misp-config:/var/www/MISP/app/Config
    depends_on:
      - misp-db
      - misp-redis

  misp-db:
    image: mysql:8.0
    container_name: misp-db
    restart: unless-stopped
    environment:
      - MYSQL_DATABASE=misp
      - MYSQL_USER=misp
      - MYSQL_PASSWORD=misp_db_password_change_me
      - MYSQL_ROOT_PASSWORD=root_password_change_me
    volumes:
      - misp-db-data:/var/lib/mysql

  misp-redis:
    image: redis:7
    container_name: misp-redis
    restart: unless-stopped

volumes:
  misp-data:
  misp-config:
  misp-db-data:
步骤 2:通过 PyMISP API 配置威胁情报源
from pymisp import PyMISP, MISPFeed
import json

class MISPFeedManager:
    def __init__(self, misp_url, misp_key, verify_ssl=False):
        self.misp = PyMISP(misp_url, misp_key, verify_ssl)
        print(f"[+] Connected to MISP: {misp_url}")

    def list_feeds(self):
        """List all configured feeds."""
        feeds = self.misp.feeds()
        enabled = [f for f in feeds if f.get("Feed", {}).get("enabled")]
        disabled = [f for f in feeds if not f.get("Feed", {}).get("enabled")]
        print(f"[+] Feeds: {len(enabled)} enabled, {len(disabled)} disabled")
        return feeds

    def enable_default_feeds(self):
        """Enable recommended default OSINT feeds."""
        recommended_feeds = [
            "CIRCL OSINT Feed",
            "Botvrij.eu - Indicators of Compromise",
            "abuse.ch URLhaus Host file",
            "abuse.ch Feodo Tracker",
            "abuse.ch SSL Blacklist",
            "malwaredomainlist",
            "CyberCure - IP Feed",
        ]

        feeds = self.misp.feeds()
        enabled_count = 0
        for feed in feeds:
            feed_data = feed.get("Feed", {})
            if feed_data.get("name") in recommended_feeds:
                if not feed_data.get("enabled"):
                    self.misp.enable_feed(feed_data["id"])
                    self.misp.enable_feed_cache(feed_data["id"])
                    enabled_count += 1
                    print(f"  [+] Enabled: {feed_data['name']}")

        print(f"[+] Enabled {enabled_count} feeds")

    def add_custom_feed(self, name, url, provider, feed_format="csv",
                        input_source="network", enabled=True):
        """Add a custom threat intelligence feed."""
        feed = MISPFeed()
        feed.name = name
        feed.provider = provider
        feed.url = url
        feed.source_format = feed_format
        feed.input_source = input_source
        feed.enabled = enabled
        feed.caching_enabled = True
        feed.publish = False
        feed.distribution = "3"  # All communities

        result = self.misp.add_feed(feed)
        if "Feed" in result:
            feed_id = result["Feed"]["id"]
            print(f"[+] Added feed: {name} (ID: {feed_id})")
            return feed_id
        else:
            print(f"[-] Error adding feed: {result}")
            return None

    def fetch_all_feeds(self):
        """Trigger fetch for all enabled feeds."""
        feeds = self.misp.feeds()
        for feed in feeds:
            feed_data = feed.get("Feed", {})
            if feed_data.get("enabled"):
                self.misp.fetch_feed(feed_data["id"])
                print(f"  [*] Fetching: {feed_data['name']}")
        print("[+] Feed fetch triggered for all enabled feeds")

manager = MISPFeedManager(
    "https://misp.organization.com",
    "YOUR_MISP_API_KEY",
)
manager.enable_default_feeds()
manager.add_custom_feed(
    name="Abuse.ch MalwareBazaar Recent",
    url="https://bazaar.abuse.ch/export/csv/recent/",
    provider="abuse.ch",
    feed_format="csv",
)
manager.fetch_all_feeds()
步骤 3:搜索和关联指标
def search_indicators(misp, value=None, type_attribute=None, tags=None, last_days=30):
    """Search MISP for indicators with correlation."""
    from datetime import datetime, timedelta
    date_from = (datetime.now() - timedelta(days=last_days)).strftime("%Y-%m-%d")

    search_params = {
        "date_from": date_from,
        "published": True,
        "enforceWarninglist": True,
    }
    if value:
        search_params["value"] = value
    if type_attribute:
        search_params["type_attribute"] = type_attribute
    if tags:
        search_params["tags"] = tags

    results = misp.search("attributes", **search_params)
    attributes = results.get("Attribute", [])
    print(f"[+] Search returned {len(attributes)} attributes")

    # Group by event for context
    events = {}
    for attr in attributes:
        event_id = attr.get("event_id", "")
        if event_id not in events:
            events[event_id] = {"attributes": [], "tags": set()}
        events[event_id]["attributes"].append({
            "type": attr.get("type", ""),
            "value": attr.get("value", ""),
            "category": attr.get("category", ""),
            "timestamp": attr.get("timestamp", ""),
        })
        for tag in attr.get("Tag", []):
            events[event_id]["tags"].add(tag.get("name", ""))

    return {"attributes": attributes, "events": events}

# Search for specific IOC
misp = manager.misp
results = search_indicators(misp, value="203.0.113.1")
results_by_type = search_indicators(misp, type_attribute="ip-dst", last_days=7)
results_by_tag = search_indicators(misp, tags=["tlp:white", "type:OSINT"])
步骤 4:导出到 SIEM(Splunk / Elasticsearch)
import requests
from datetime import datetime, timedelta

class MISPSIEMExporter:
    def __init__(self, misp_client):
        self.misp = misp_client

    def export_to_splunk(self, splunk_url, hec_token, days=7):
        """Export recent MISP indicators to Splunk via HEC."""
        date_from = (datetime.now() - timedelta(days=days)).strftime("%Y-%m-%d")
        results = self.misp.search("attributes", date_from=date_from,
                                    published=True, enforceWarninglist=True)
        attributes = results.get("Attribute", [])

        headers = {"Authorization": f"Splunk {hec_token}"}
        exported = 0
        for attr in attributes:
            event = {
                "event": {
                    "ioc_type": attr.get("type", ""),
                    "ioc_value": attr.get("value", ""),
                    "category": attr.get("category", ""),
                    "event_id": attr.get("event_id", ""),
                    "timestamp": attr.get("timestamp", ""),
                    "tags": [t.get("name", "") for t in attr.get("Tag", [])],
                },
                "sourcetype": "misp:attribute",
                "source": "misp",
                "index": "threat_intel",
            }
            resp = requests.post(
                f"{splunk_url}/services/collector/event",
                headers=headers, json=event,
                verify=not os.environ.get("SKIP_TLS_VERIFY", "").lower() == "true",  # Set SKIP_TLS_VERIFY=true for self-signed certs in lab environments
            )
            if resp.status_code == 200:
                exported += 1

        print(f"[+] Exported {exported}/{len(attributes)} indicators to Splunk")

    def export_ioc_list(self, output_file, ioc_types=None, days=30):
        """Export flat IOC list for firewall/proxy blocklists."""
        ioc_types = ioc_types or ["ip-dst", "domain", "hostname", "url"]
        date_from = (datetime.now() - timedelta(days=days)).strftime("%Y-%m-%d")

        all_iocs = []
        for ioc_type in ioc_types:
            results = self.misp.search(
                "attributes", type_attribute=ioc_type,
                date_from=date_from, published=True,
                enforceWarninglist=True,
            )
            for attr in results.get("Attribute", []):
                all_iocs.append(attr.get("value", ""))

        unique_iocs = sorted(set(all_iocs))
        with open(output_file, "w") as f:
            for ioc in unique_iocs:
                f.write(f"{ioc}\n")

        print(f"[+] Exported {len(unique_iocs)} unique IOCs to {output_file}")

exporter = MISPSIEMExporter(misp)
exporter.export_ioc_list("blocklist_ips.txt", ioc_types=["ip-dst"], days=7)

验证标准

  • MISP 已部署,可通过 Web 界面和 API 访问
  • 默认 OSINT 威胁情报源已启用并正在获取数据
  • 已添加自定义威胁情报源并正在摄入指标
  • 指标可搜索,并能在事件间进行关联
  • IOC 已成功导出到 SIEM(Splunk/Elasticsearch)
  • 已生成用于防火墙/代理集成的阻止列表

参考资料

评论

支持 Markdown