Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISP WarningLists - Handling IP address lookup in CIDR IP ranges #200

Merged
merged 1 commit into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions analyzers/MISPWarningLists/mispwarninglists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import json
import requests
import ipaddress

from cortexutils.analyzer import Analyzer
from cortexutils.extractor import Extractor
Expand Down Expand Up @@ -63,14 +64,30 @@ def lastremotecommit():

def run(self):
results = []
data = self.data
if self.data_type == 'ip':
try:
data = ipaddress.ip_address(self.data)
except ValueError:
return self.error("{} is said to be an IP address but it isn't".format(self.data))
for list in self.warninglists:
if self.data_type not in list.get('dataTypes'):
continue

if self.data in list.get('values', []):
results.append({
"name": list.get('name')
})
if self.data_type == 'ip':
for net in list.get('values', []):
try:
if data in ipaddress.ip_network(net):
results.append({"name": list.get('name')})
break
except ValueError:
# Ignoring if net is not a valid IP network since we want to compare ip addresses
pass
else:
if data in list.get('values', []):
results.append({
"name": list.get('name')
})

self.report({
"results": results,
Expand Down
1 change: 1 addition & 0 deletions analyzers/MISPWarningLists/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cortexutils
requests
ipaddress