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

Analyzer for DNS Lookingglass #941

Merged
merged 7 commits into from
Feb 26, 2021
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
32 changes: 32 additions & 0 deletions analyzers/DNSLookingglass/DNSLookingglass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "DNS_Lookingglass",
"version": "1.0",
"author": "Dennis Perto, Conscia",
"url": "https://github.com/xme/thehive/Cortex-Analyzers",
"license": "AGPL-V3",
"description": "Query the SANS ISC Global DNS Lookingglass API to check a domain name for resolved IP addresses.",
"dataTypeList": ["domain", "fqdn"],
"command": "DNSLookingglass/DNSLookingglass_lookup.py",
"baseConfig": "DNSLookingglass.json",
"config": {
"service": "query"
},
"registration_required": false,
"subscription_required": false,
"free_subscription": false,
"service_homepage": "https://isc.sans.edu/",
"service_logo": {
"path": "assets/dshield.png",
"caption": "logo"
},
"screenshots": [
{
"path": "assets/DNS_Lookingglass_long.png",
"caption": "DNS Lookingglass: Long report template"
},
{
"path": "assets/DNS_Lookingglass_artifacts.png",
"caption": "DNS Lookingglass: artifacts"
}
]
}
86 changes: 86 additions & 0 deletions analyzers/DNSLookingglass/DNSLookingglass_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python3
# encoding: utf-8
import json
import requests
import iocextract
from cortexutils.analyzer import Analyzer

class DNSLookingglassAnalyzer(Analyzer):
def __init__(self):
Analyzer.__init__(self)

def lookingglass_checkdomain(self, data):
url = 'https://isc.sans.edu/api/dnslookup/%s?json' % data
r = requests.get(url)

return json.loads(r.text)

def artifacts(self, raw):
artifacts = []
ipv4s = list(iocextract.extract_ipv4s(str(raw)))
ipv6s = list(iocextract.extract_ipv6s(str(raw)))

if ipv4s:
ipv4s = list(dict.fromkeys(ipv4s))
for i in ipv4s:
artifacts.append(self.build_artifact('ip',str(i)))

if ipv6s:
ipv6s = list(dict.fromkeys(ipv6s))
for j in ipv6s:
artifacts.append(self.build_artifact('ip',str(j)))

return artifacts

def summary(self, raw):
taxonomies = []
level = "info"
namespace = "Lookingglass"
predicate = "ERR"
value = "-"

value = "{} hit(s)".format(raw['count'])
predicate = raw['hits']

taxonomies.append(self.build_taxonomy(level, namespace, predicate, value))

return {"taxonomies": taxonomies}

def get_hits(self, hits):
if hits == 0:
return("NXDOMAIN")
elif hits >= 1:
return("DomainExist")
else:
return("Error")

def run(self):
if self.data_type in ['domain', 'fqdn']:
data = self.get_param('data', None, 'Domain is missing')
r = self.lookingglass_checkdomain(data)

results = dict()
results['results'] = list()

if len(r) != 0:
for hit in r:
result = dict()
try:
result['answer'] = hit['answer']
result['status'] = hit['status']
result['country'] = hit['country']
results['results'].append(result)
except KeyError:
pass

results['hits'] = self.get_hits(int(len(results['results'])))
results['count'] = int(len(results['results']))

self.report(results)
else:
self.error('No domain found')
else:
self.error('Invalid data type')

if __name__ == '__main__':
DNSLookingglassAnalyzer().run()
6 changes: 6 additions & 0 deletions analyzers/DNSLookingglass/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#### DNS Lookingglass Analyzer
Lookup domain names from different locations using the ISC SANS [DNS Lookingglass](https://www.dshield.org/tools/dnslookup.html) API service.


##### Requirements
There is no requirements to use this analyzer.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added analyzers/DNSLookingglass/assets/dshield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions analyzers/DNSLookingglass/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cortexutils
requests
iocextract
1 change: 1 addition & 0 deletions analyzers/Splunk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
splunk-sdk
cortexutils
39 changes: 39 additions & 0 deletions thehive-templates/DNS_Lookingglass_1_0/long.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="panel panel-info" ng-if="success">
<div class="panel panel-info" ng-if="content.results">
<div class="panel-heading">
<strong>Results</strong> (from {{content.count}} locations)
</div>
<div class="panel-body" style="display:block;height:750px;overflow:auto;">
<table class="table table-hover table-striped">
<thead>
<th>Lookup from country</th>
<th>Lookup status</th>
<th>Lookup answer</th>
</thead>
<tbody>
<tr ng-repeat="hit in content.results track by $index">
<td>
{{hit.country.toString()}}
</td>
<td style="overflow:auto">
{{hit.status.toString()}}
</td>
<td style="overflow:auto">
{{hit.answer.toString()}}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

<!-- General error -->
<div class="panel panel-danger" ng-if="!success">
<div class="panel-heading">
<strong>{{(artifact.data || artifact.attachment.name) | fang}}</strong>
</div>
<div class="panel-body">
{{content.errorMessage}}
</div>
</div>
3 changes: 3 additions & 0 deletions thehive-templates/DNS_Lookingglass_1_0/short.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="label" ng-repeat="t in content.taxonomies" ng-class="{'info': 'label-info', 'safe': 'label-success', 'suspicious': 'label-warning', 'malicious':'label-danger'}[t.level]">
{{t.namespace}}:{{t.predicate}}="{{t.value}}"
</span>