ninoseki/ioc-extractor

GitHub: ninoseki/ioc-extractor

一个用于从文本中提取威胁指标(IoC)的 Node.js 库和命令行工具,支持 IP、域名、哈希、URL、CVE 及加密货币地址等多种类型,并具备混淆还原功能。

Stars: 61 | Forks: 12

# IoC extractor [![npm version](https://badge.fury.io/js/ioc-extractor.svg)](https://badge.fury.io/js/ioc-extractor) ![Node.js CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/8eb4bfe850154121.svg) [![CodeFactor](https://www.codefactor.io/repository/github/ninoseki/ioc-extractor/badge)](https://www.codefactor.io/repository/github/ninoseki/ioc-extractor) [![Coverage Status](https://coveralls.io/repos/github/ninoseki/ioc-extractor/badge.svg)](https://coveralls.io/github/ninoseki/ioc-extractor) [![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://ninoseki.github.io/ioc-extractor/) IoC extractor 是一个用于从文本块中提取常见 [IoC (Indicator of Compromise)](https://en.wikipedia.org/wiki/Indicator_of_compromise) 的 npm 包。 **注意**:该包深受 [cacador](https://github.com/sroberts/cacador) 的影响。 ## 安装 ``` npm install -g ioc-extractor # 或者如果你想在你的 JS/TS 项目中将 ioc-extractor 作为库使用 npm install ioc-extractor ``` ## 用法 ### 作为 CLI 使用 ``` $ ioc-extractor --help Usage: ioc-extractor [options] Options: --no-strict Disable strict option --no-refang Disable refang option --no-sort Disable sort option -p, --punycode Enable punycode option -o, --only Show only specific IoC types -h, --help display help for command ``` ``` $ echo "1.1.1.1 8.8.8.8 example.com" | ioc-extractor | jq { "asns": [], "btcs": [], "cves": [], "domains": [ "example.com" ], "emails": [], "eths": [], "gaPubIDs": [], "gaTrackIDs": [], "ipv4s": [ "1.1.1.1", "8.8.8.8" ], "ipv6s": [], "macAddresses": [], "md5s": [], "sha1s": [], "sha256s": [], "sha512s": [], "ssdeeps": [], "urls": [], "xmrs": [] } $ echo "1.1.1.1 8.8.8.8" | ioc-extractor --only ipv4s | jq { "ipv4s": [ "1.1.1.1", "8.8.8.8" ] } ``` ### 作为库使用 ``` import { extractIOC } from 'ioc-extractor' const input = '1.1.1[.]1 google(.)com f6f8179ac71eaabff12b8c024342109b' const ioc = extractIOC(input) console.log(ioc.md5s) // => ['f6f8179ac71eaabff12b8c024342109b'] console.log(ioc.ipv4s) // => ['1.1.1.1'] console.log(ioc.domains) // => ['google.com'] ``` `extractIOC` 接受以下选项: - [punycode](#punycode) - [refang](#refang) - [sort](#sort) - [strict](#strict) 如果你想提取特定类型的 IoC,可以使用按 IoC 类型分类的提取函数。 ``` import { refang, extractDomains, extractIPv4s, extractMD5s } from 'ioc-extractor' const input = '1.1.1[.]1 google(.)com f6f8179ac71eaabff12b8c024342109b' const refanged = refang(input) // => 1.1.1.1 google.com f6f8179ac71eaabff12b8c024342109b const ipv4s = extractIPv4s(refanged) // => ['1.1.1.1'] const domains = extractDomains(refanged) // => ['google.com'] const md5s = extractMD5s(refanged) // => ['f6f8179ac71eaabff12b8c024342109b'] ``` 网络相关的提取函数(例如 `extractDomains`)可以接受以下选项: - [sort](#sort) - [strict](#strict) 有关更多详细信息,请参阅 [文档](https://ninoseki.github.io/ioc-extractor/)。 或者,如果你想一次提取特定 IoC 类型的列表,可以使用 `partialExtractIOC`。 ``` import { partialExtractIOC } from 'ioc-extractor' const input = '1.1.1[.]1 google(.)com f6f8179ac71eaabff12b8c024342109b' const ioc = partialExtractIOC(input, ['ipv4s', 'domains']) console.log(ioc) // => {"ipv4s":["1.1.1.1"],"domains":["google.com"]} ``` ## IoC 类型 该包支持以下 IoC: - **哈希**: MD5, SHA1, SHA256, SHA512, SSDEEP - **网络**: domain, email, IPv4, IPv6, URL, ASN - **硬件**: MAC address - **工具**: CVE (CVE ID) - **加密货币**: BTC (BTC address), ETH (ETH address), XMR (XMR address) - **跟踪器**: GA track ID (Google Analytics tracking ID), GA pub ID (Google Adsense Publisher ID) ## 还原 技巧 对于 **网络** IoC,支持以下还原 技巧: | 技巧 | 已混淆 | 已还原 | | ------------------------------------ | -------------------------------------- | ------------------------------- | | 空格中的 `.` | `1.1.1 . 1` | `1.1.1.1` | | 括号、圆括号等中的 `.` | `1.1.1[.]1` | `1.1.1.1` | | 括号、圆括号等中的 `dot` | `example[dot]com` | `example.com` | | `.` 前的反斜杠 | `example\.com` | `example.com` | | 括号、圆括号等中的 `/` | `http://example.com[/]path` | `http://example.com/path` | | 括号、圆括号等中的 `://` | `http[://]example.com` | `http://example.com` | | 括号、圆括号等中的 `:` | `http[:]//example.com` | `http://example.com` | | 括号、圆括号等中的 `@` | `test[@]example.com` | `test@example.com` | | 括号、圆括号等中的 `at` | `test[at]example.com` | `test@example.com` | | `hxxp` | `hxxps://example.com` | `https://example.com` | | 部分 | `1.1.1[.1` | `1.1.1.1` | | 任意组合 | `hxxps[:]//test\.example[.)com[/]path` | `https://test.example.com/path` | ## 选项 ### `strict` 是否进行严格的 [TLD](https://en.wikipedia.org/wiki/Top-level_domain) 匹配。默认为 `true`。 ### `refang` 是否进行还原。默认为 `false`。 ### `punycode` 是否进行 [Punycode](https://en.wikipedia.org/wiki/Punycode) 转换。默认为 `false`。 ### `sort` 是否对值进行排序。默认为 `true`。 ## 替代方案 - [cmu-sei/cyobstract](https://github.com/cmu-sei/cyobstract) - [fhightower/ioc-finder](https://github.com/fhightower/ioc-finder) - [InQuest/python-iocextract](https://github.com/InQuest/python-iocextract) - [sroberts/cacador](https://github.com/sroberts/cacador)
标签:CVE, ESC4, GNU通用公共许可证, IoC 提取, IP 地址提取, JavaScript 库, MITM代理, Node.js, npm 包, OSINT, TypeScript, URL 提取, 哈希值提取, 域名提取, 威胁情报, 安全插件, 开发者工具, 数字取证, 数字签名, 文本分析, 暗色界面, 电子邮件提取, 网络安全, 自动化攻击, 自动化脚本, 隐私保护