Skip to main content

A tool for extracting Indicators of Compromise from security reports

Project description

IOCParser

IOCParser

Extract Indicators of Compromise from security reports with ease

PyPI Version Python Versions License CI Status Coverage

GitHub Stars GitHub Issues Buy Me a Coffee


Overview

IOCParser is a powerful Python tool for extracting Indicators of Compromise (IOCs) from security reports. It supports HTML, PDF, and plain text formats, making it ideal for threat intelligence analysts, security researchers, and incident responders.

Key Features

Feature Description
Multi-format Support Parse PDF, HTML, and plain text files
URL Analysis Extract IOCs directly from web URLs
MISP Integration Filter false positives using MISP warning lists
Defanging Automatic defanging of domains and IPs
Library Mode Use as CLI tool or Python library
JSON/Text/STIX Output Flexible output formats
Persistence Optional SQLite/MariaDB storage

Supported IOC Types

Hashes          MD5, SHA1, SHA256, SHA512
Network         Domains, IPs, URLs, Emails
Cryptocurrency  Bitcoin addresses
Vulnerabilities CVEs
Windows         Registry keys, Filepaths, Filenames
Detection       YARA rules

Installation

From PyPI (Recommended)

pip install iocparser-tool

From Source

git clone https://github.com/seifreed/iocparser.git
cd iocparser
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -e .

Quick Start

# Initialize MISP warning lists (first time only)
iocparser --init

# Analyze files
iocparser -f report.pdf
iocparser -f report.html
iocparser -u https://example.com/report.html

Usage

Command Line Interface

# Basic analysis
iocparser -f report.pdf

# Save output to file
iocparser -f report.pdf -o results.json

# JSON format output
iocparser -f report.pdf --json

# Analyze from URL
iocparser -u https://example.com/report.html

# Force specific file type
iocparser -f report -t pdf

Available Options

Option Description
-f, --file Input file path
-u, --url URL to analyze
-o, --output Output file path
-t, --type Force file type (pdf, html, text)
--json Output in JSON format
--stix Output in STIX 2.1 format
--no-defang Disable IOC defanging
--no-check-warnings Skip MISP warning list check
--force-update Force update MISP lists
--init Initialize MISP warning lists
--persist/--no-persist Enable/disable persistence
--db-uri Database URI for persistence
--config Path to config file (INI)

Python Library

Basic Usage

from iocparser import extract_iocs_from_file, extract_iocs_from_text

# From file
normal_iocs, warning_iocs = extract_iocs_from_file('report.pdf')

# From text
text = "Malware contacts evil.com at 192.168.1.1"
normal_iocs, warning_iocs = extract_iocs_from_text(text)

# Print results
for ioc_type, iocs in normal_iocs.items():
    print(f"{ioc_type}: {iocs}")

Advanced Usage

from iocparser import IOCExtractor, PDFParser, MISPWarningLists

# Extract text from PDF
parser = PDFParser("report.pdf")
text = parser.extract_text()

# Extract IOCs
extractor = IOCExtractor(defang=True)
iocs = extractor.extract_all(text)

# Filter with MISP warning lists
warning_lists = MISPWarningLists()
normal, warnings = warning_lists.separate_iocs_by_warnings(iocs)

Individual Extractors

extractor = IOCExtractor(defang=True)

# Extract specific types
hashes_md5 = extractor.extract_md5(text)
hashes_sha256 = extractor.extract_sha256(text)
domains = extractor.extract_domains(text)
ips = extractor.extract_ips(text)
urls = extractor.extract_urls(text)
emails = extractor.extract_emails(text)
cves = extractor.extract_cves(text)
yara = extractor.extract_yara_rules(text)
registry = extractor.extract_registry(text)

Examples

Process Multiple Reports

from iocparser import extract_iocs_from_file
from pathlib import Path

reports_dir = Path("reports")
for report in reports_dir.glob("*.pdf"):
    normal, warnings = extract_iocs_from_file(report)
    total = sum(len(v) for v in normal.values())
    print(f"{report.name}: {total} IOCs found")

Export to JSON

iocparser -f apt_report.pdf --json -o iocs.json

Export to STIX 2.1

iocparser -f apt_report.pdf --stix -o iocs.stix.json

Persistence (SQLite/MariaDB)

# SQLite
iocparser -u https://example.com/report.html --persist --db-uri "sqlite:///iocparser.db"

# MariaDB
iocparser -u https://example.com/report.html --persist --db-uri "mysql+pymysql://user:pass@host:3306/iocparser"

Config + Environment

Supports .env, environment variables, and INI config files.

Environment variables

export IOCPARSER_PERSIST=1
export IOCPARSER_DB_URI="sqlite:///iocparser.db"

INI config (iocparser.ini or ~/.config/iocparser/config.ini)

[database]
persist=true
uri=sqlite:///iocparser.db

Analyze Threat Intelligence Feed

iocparser -u https://securelist.com/report.html --json

Requirements


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support the Project

If you find IOCParser useful, consider supporting its development:

Buy Me A Coffee

License

This project is licensed under the MIT License - see the LICENSE file for details.

Attribution Required:


Made with dedication for the threat intelligence community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iocparser_tool-5.0.0.tar.gz (19.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iocparser_tool-5.0.0-py3-none-any.whl (19.2 MB view details)

Uploaded Python 3

File details

Details for the file iocparser_tool-5.0.0.tar.gz.

File metadata

  • Download URL: iocparser_tool-5.0.0.tar.gz
  • Upload date:
  • Size: 19.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.12

File hashes

Hashes for iocparser_tool-5.0.0.tar.gz
Algorithm Hash digest
SHA256 a7d614509ae41cf3a4eefaf6a608512505c8240e7f71c0577c7d6535f59b9ace
MD5 da2188778c8ab741f11bd5a71c8f6ee0
BLAKE2b-256 70ab243a46b118e5758583f678cf06d76d5609490d9fc7f369a687c9d283a91d

See more details on using hashes here.

File details

Details for the file iocparser_tool-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: iocparser_tool-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.12

File hashes

Hashes for iocparser_tool-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1b4bdcedb1f976f3ea8bdfb32bfd7d0c174b84bbd19f71b6bc5388f780d482
MD5 a9d65f32895374a06591aa35d77849b3
BLAKE2b-256 1f6235e93ae6afe8fab9de1cf6b1449fd9b3e3e3cc1be3466bb187ae9a6b5f70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page