Skip to main content

Python package for finding and parsing indicators of compromise from text.

Project description

Copyright (c) 2018, Floyd Hightower

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Description: # IOC Finder

[![PyPi](https://img.shields.io/pypi/v/ioc_finder.svg)](https://pypi.python.org/pypi/ioc_finder)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4078c4e3e384431bbe69c35c7f6da7b7)](https://www.codacy.com/app/fhightower/ioc-finder)
[![Build Status](https://travis-ci.org/fhightower/ioc-finder.svg?branch=master)](https://travis-ci.org/fhightower/ioc-finder)
[![codecov](https://codecov.io/gh/fhightower/ioc-finder/branch/master/graph/badge.svg)](https://codecov.io/gh/fhightower/ioc-finder)

Parse [indicators of compromise](https://searchsecurity.techtarget.com/definition/Indicators-of-Compromise-IOC) from text.

## Capabilities

Currently, this package can the following items in a given text:

- IP address (IPv4 and IPv6)
- Email addresses (both standard format (e.g. `test@example.com`) and an email with an IP address as the domain (e.g. `test@[192.168.0.1]`))
- Domain names (support for Unicode domain names (e.g. `ȩxample.com`) is coming soon)
- URLs
- File hashes (md5, sha1, sha256, and sha512)
- Registry Key paths (e.g. `"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows`)
- Autonomous System Numbers (ASNs) (in multiple formats such as `asn1234` and `as 1234`)
- CVEs (e.g. `CVE-2014-1234`)
- CIDR ranges (currently ipv4 ranges; ipv6 ranges coming soon)
- Google Adsense Publisher IDs
- Google Analytics Tracker IDs
- Bitcoin addresses (P2PKH, P2SH, and Bech32)
- Others... if you have any requests, [let me know](https://github.com/fhightower/ioc-finder) (or you can contact me [here](https://hightower.space/contact/) to make private suggestions)!

Also provides some helpful features like:

- Option to parse domain name from a URL
- Option to parse domain name from an email address
- Option to parse IP address from a CIDR range

## Installation

To install this package:

```
pip install ioc-finder
```

## Usage

This package can be used in [python](#Python) or via a [command-line interface](#Command-Line Interface).

### Python

The primary function in this package is the `ioc_finder.find_iocs()` function. A simple usage looks like:

```python
from ioc_finder import find_iocs
text = "This is just an example.com https://example.org/test/bingo.php"
iocs = find_iocs(text)
print('Domains: {}'.format(iocs['domains']))
print('URLs: {}'.format(iocs['urls']))
```

#### Inputs

You must pass some text into the `find_iocs()` function as string (the iocs will be parsed from this text). You can also provide the options detailed below.

##### Options

The `find_iocs` takes the following keywords (all of them default to `True`):

- `parse_domain_from_url` (default=True): Whether or not to parse domain names from URLs (e.g. `example.com` from `https://example.com/test`)
- `parse_domain_from_email_address` (default=True): Whether or not to parse domain names from email addresses (e.g. `example.com` from `foo@example.com`)
- `parse_address_from_cidr` (default=True): Whether or not to parse IP addresses from CIDR ranges (e.g. `0.0.0.1` from `0.0.0.1/24`)

See [test_ioc_finder.py](https://github.com/fhightower/ioc-finder/blob/master/tests/test_ioc_finder.py) for more examples.

#### Output

The `find_iocs()` returns a dictionary in the following structure:

```json
{
"asns": [],
"bitcoin_addresses": [],
"complete_email_address": [],
"cves": [],
"domains": [],
"email_addresses": [],
"google_adsense_publisher_ids": [],
"google_analytics_tracker_ids": [],
"ipv4_cidrs": [],
"ipv4s": [],
"ipv6s": [],
"md5s": [],
"registry_key_paths": [],
"sha1s": [],
"sha256s": [],
"sha512s": [],
"urls": []
}
```

For example, running the example code shown at the start of the [usage](#usage) section above produces the following output:

```json
{
"asns": [],
"bitcoin_addresses": [],
"complete_email_address": [],
"cves": [],
"domains": ["example.org", "example.com"],
"email_addresses": [],
"google_adsense_publisher_ids": [],
"google_analytics_tracker_ids": [],
"ipv4_cidrs": [],
"ipv4s": [],
"ipv6s": [],
"md5s": [],
"registry_key_paths": [],
"sha1s": [],
"sha256s": [],
"sha512s": [],
"urls": ["https://example.org/test/bingo.php"]
}
```

##### Output Details

There are two grammars for email addresses. There is a fairly complete grammar to find email addresses matching the spec (which is very broad). Any of these complete email addresses (e.g. `foo"bar@gmail.com`) will be sent as output to in `complete_email_addresses` key.

Email addresses in the simple form we are familiar with (e.g. `bar@gmail.com`) will be sent as output in the `email_addresses` key.

### Command-Line Interface

The ioc-finder package can be used from a command line like:

```
ioc-finder "This is just an example.com https://example.org/test/bingo.php"
```

This will return:

```json
{
"asns": [],
"bitcoin_addresses": [],
"complete_email_addresses": [],
"cves": [],
"domains": [
"example.com",
"example.org"
],
"email_addresses": [],
"google_adsense_publisher_ids": [],
"google_analytics_tracker_ids": [],
"ipv4_cidrs": [],
"ipv4s": [],
"ipv6s": [],
"md5s": [],
"registry_key_paths": [],
"sha1s": [],
"sha256s": [],
"sha512s": [],
"urls": [
"https://example.org/test/bingo.php"
]
}
```

Here are the usage instructions for the CLI:

```
Usage: ioc-finder [OPTIONS] TEXT

CLI interface for parsing indicators of compromise.

Options:
--no_url_domain_parsing Using this flag will not parse domain names
from URLs
--no_email_addr_domain_parsing Using this flag will not parse domain names
from email addresses
--no_cidr_address_parsing Using this flag will not parse IP addresses
from CIDR ranges
--help Show this message and exit.
```

## Credits

This project uses the [ioc_fanger](https://github.com/ioc-fang/ioc_fanger) package to make sure that all indicators in the text are properly [fanged](https://ioc-fang.hightower.space/).

This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and Floyd Hightower's [python-project-template](https://gitlab.com/fhightower-templates/python-project-template) project template.

Previous iterations of this package were inspired by [https://github.com/mosesschwartz/extract_iocs](https://github.com/mosesschwartz/extract_iocs).

## Similar Projects

There are a number of projects available to find Indicators of Compromise. Your mileage may vary with them. If there are things that another package can do that you would like to see in this package, [let me know](https://github.com/fhightower/ioc-finder/issues) (or [contact me](https://hightower.space/contact/)). Here are a few other ones:

- [https://github.com/InQuest/python-iocextract](https://github.com/InQuest/python-iocextract)
- [https://github.com/sroberts/cacador](https://github.com/sroberts/cacador)
- [https://github.com/armbues/ioc_parser](https://github.com/armbues/ioc_parser)

Keywords: iocs,indicators of compromise,parsing,finding,searching,threat intelligence,malware,threat hunting
Platform: UNKNOWN

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

ioc_finder-1.2.4.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

ioc_finder-1.2.4-py2.py3-none-any.whl (16.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ioc_finder-1.2.4.tar.gz.

File metadata

  • Download URL: ioc_finder-1.2.4.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6

File hashes

Hashes for ioc_finder-1.2.4.tar.gz
Algorithm Hash digest
SHA256 b9ed41d910cdb663993b397951ecfa8e044a67c4b2b5b234b0871e8d35ed39b4
MD5 49db06fe17619ca8997b698238de9375
BLAKE2b-256 b0e7faafa4aa81a56cb5e76fb854ee5da412a146e5ae89e77386bf9b7e280141

See more details on using hashes here.

File details

Details for the file ioc_finder-1.2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: ioc_finder-1.2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.5.6

File hashes

Hashes for ioc_finder-1.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23010b3fd8f9c77b348e598af35d2b237d21602912f17d5f1e3fa8e3ebc73feb
MD5 dcc0d7f41533f6d7c47b64381832f2ed
BLAKE2b-256 723f1d2b79be6870c14bb9adbc2293cc3cc900692c3b52cc5b6110d046bcb766

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