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

add UnshortenLink analyzer #247

Merged
merged 4 commits into from
May 29, 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
11 changes: 11 additions & 0 deletions analyzers/UnshortenLink/UnshortenLink.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "UnshortenLink",
"version": "1.0",
"author": "Rémi Pointel (CERT-BDF)",
"url": "https://github.com/TheHive-Project/Cortex-Analyzers",
"license": "AGPL-V3",
"description": "Use UnshortenLink to find the correct URL.",
"dataTypeList": ["url"],
"baseConfig": "UnshortenLink",
"command": "UnshortenLink/unshortenlink.py"
}
2 changes: 2 additions & 0 deletions analyzers/UnshortenLink/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
cortexutils
45 changes: 45 additions & 0 deletions analyzers/UnshortenLink/unshortenlink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
# encoding: utf-8

import requests
from cortexutils.analyzer import Analyzer


class UnshortenlinkAnalyzer(Analyzer):
def __init__(self):
Analyzer.__init__(self)
self.url = self.getParam('url', None)
self.proxies = self.getParam('config.proxy', None)

def artifacts(self, raw):
if raw['found']:
return [{'type': 'url', 'value': raw['url']}]
else:
return []

def run(self):
Analyzer.run(self)

url = self.getData()

if self.proxies:
proxies = self.proxies
else:
proxies = {}

result = {'found': False, 'url': None}
try:
response = requests.get(url, proxies=proxies,
allow_redirects=False)

if (response.status_code == 301) or (response.status_code == 302):
result['url'] = response.headers['Location']
result['found'] = True
except Exception as e:
self.unexpectedError("Service unavailable: %s" % e)

self.report(result)


if __name__ == '__main__':
UnshortenlinkAnalyzer().run()
19 changes: 19 additions & 0 deletions thehive-templates/UnshortenLink_1_0/long.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="panel panel-info" ng-if="success">
<div class="panel-heading">
Unshorten Link for <strong>{{artifact.data | fang}}</strong>
</div>
<div class="panel-body">
<span>found:{{content.found}}</span>
<div ng-if="content.found">
<span>url:{{content.url | fang}}</span>
</div>
</div>
</div>
<div class="panel panel-danger" ng-if="!success">
<div class="panel-heading">
<strong>{{artifact.data | fang}}</strong>
</div>
<div class="panel-body">
{{content.errorMessage}}
</div>
</div>