2019-04-02 15:30:11 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import requests
|
|
|
|
from urllib.parse import urljoin
|
2019-10-17 16:32:26 +02:00
|
|
|
from base64 import b64encode
|
2019-07-24 09:35:55 +02:00
|
|
|
import json
|
2019-10-18 09:43:53 +02:00
|
|
|
import os
|
2019-04-02 15:30:11 +02:00
|
|
|
|
2021-04-19 08:07:22 +02:00
|
|
|
LiveCI = True
|
2019-04-02 15:30:11 +02:00
|
|
|
|
|
|
|
class TestExpansions(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.maxDiff = None
|
|
|
|
self.headers = {'Content-Type': 'application/json'}
|
|
|
|
self.url = "http://127.0.0.1:6666/"
|
2019-10-18 09:43:53 +02:00
|
|
|
self.dirname = os.path.dirname(os.path.realpath(__file__))
|
2019-10-04 17:46:25 +02:00
|
|
|
self.sigma_rule = "title: Antivirus Web Shell Detection\r\ndescription: Detects a highly relevant Antivirus alert that reports a web shell\r\ndate: 2018/09/09\r\nmodified: 2019/10/04\r\nauthor: Florian Roth\r\nreferences:\r\n - https://www.nextron-systems.com/2018/09/08/antivirus-event-analysis-cheat-sheet-v1-4/\r\ntags:\r\n - attack.persistence\r\n - attack.t1100\r\nlogsource:\r\n product: antivirus\r\ndetection:\r\n selection:\r\n Signature: \r\n - \"PHP/Backdoor*\"\r\n - \"JSP/Backdoor*\"\r\n - \"ASP/Backdoor*\"\r\n - \"Backdoor.PHP*\"\r\n - \"Backdoor.JSP*\"\r\n - \"Backdoor.ASP*\"\r\n - \"*Webshell*\"\r\n condition: selection\r\nfields:\r\n - FileName\r\n - User\r\nfalsepositives:\r\n - Unlikely\r\nlevel: critical"
|
2019-10-29 21:35:45 +01:00
|
|
|
try:
|
|
|
|
with open(f'{self.dirname}/expansion_configs.json', 'rb') as f:
|
|
|
|
self.configs = json.loads(f.read().decode())
|
|
|
|
except FileNotFoundError:
|
|
|
|
self.configs = {}
|
2019-04-02 15:30:11 +02:00
|
|
|
|
|
|
|
def misp_modules_post(self, query):
|
|
|
|
return requests.post(urljoin(self.url, "query"), json=query)
|
|
|
|
|
2019-10-27 21:19:43 +01:00
|
|
|
@staticmethod
|
2019-10-31 17:16:08 +01:00
|
|
|
def get_attribute(response):
|
2019-10-27 21:19:43 +01:00
|
|
|
data = response.json()
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
print(json.dumps(data, indent=2))
|
|
|
|
return data
|
|
|
|
return data['results']['Attribute'][0]['type']
|
|
|
|
|
2019-10-27 21:16:31 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_data(response):
|
2019-10-15 16:04:03 +02:00
|
|
|
data = response.json()
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
print(json.dumps(data, indent=2))
|
|
|
|
return data
|
|
|
|
return data['results'][0]['data']
|
|
|
|
|
2019-10-27 21:16:31 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_errors(response):
|
2019-10-08 15:50:15 +02:00
|
|
|
data = response.json()
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
print(json.dumps(data, indent=2))
|
|
|
|
return data
|
|
|
|
return data['error']
|
|
|
|
|
2019-10-27 21:19:43 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_object(response):
|
|
|
|
data = response.json()
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
print(json.dumps(data, indent=2))
|
|
|
|
return data
|
|
|
|
return data['results']['Object'][0]['name']
|
|
|
|
|
2019-10-27 21:16:31 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_values(response):
|
2019-07-24 09:35:55 +02:00
|
|
|
data = response.json()
|
2019-07-24 09:49:05 +02:00
|
|
|
if not isinstance(data, dict):
|
2019-07-24 09:57:52 +02:00
|
|
|
print(json.dumps(data, indent=2))
|
2019-07-24 09:49:05 +02:00
|
|
|
return data
|
2021-12-24 16:03:06 +01:00
|
|
|
if 'results' not in data:
|
|
|
|
return data
|
2019-10-29 21:15:22 +01:00
|
|
|
for result in data['results']:
|
|
|
|
values = result['values']
|
|
|
|
if values:
|
|
|
|
return values[0] if isinstance(values, list) else values
|
2019-07-24 09:35:55 +02:00
|
|
|
return data['results'][0]['values']
|
2019-04-02 15:30:11 +02:00
|
|
|
|
2019-10-29 21:35:45 +01:00
|
|
|
def test_apiosintds(self):
|
|
|
|
query = {'module': 'apiosintds', 'ip-dst': '185.255.79.90'}
|
|
|
|
response = self.misp_modules_post(query)
|
2019-10-31 17:16:27 +01:00
|
|
|
try:
|
|
|
|
self.assertTrue(self.get_values(response).startswith('185.255.79.90 IS listed by OSINT.digitalside.it.'))
|
|
|
|
except AssertionError:
|
|
|
|
self.assertTrue(self.get_values(response).startswith('185.255.79.90 IS NOT listed by OSINT.digitalside.it.'))
|
2019-10-29 21:35:45 +01:00
|
|
|
|
2019-12-18 23:04:36 +01:00
|
|
|
def test_apivoid(self):
|
|
|
|
module_name = "apivoid"
|
|
|
|
query = {"module": module_name,
|
|
|
|
"attribute": {"type": "domain",
|
|
|
|
"value": "circl.lu",
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"},
|
|
|
|
"config": {}}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_object(response), 'dns-record')
|
|
|
|
except Exception:
|
|
|
|
self.assertTrue(self.get_errors(response).startswith('You do not have enough APIVoid credits'))
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'An API key for APIVoid is required.')
|
|
|
|
|
2019-10-04 16:46:57 +02:00
|
|
|
def test_bgpranking(self):
|
2020-09-08 16:24:41 +02:00
|
|
|
query = {
|
|
|
|
"module": "bgpranking",
|
|
|
|
"attribute": {
|
|
|
|
"type": "AS",
|
|
|
|
"value": "13335",
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"
|
|
|
|
}
|
|
|
|
}
|
2019-10-04 16:46:57 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2020-09-08 16:24:41 +02:00
|
|
|
self.assertEqual(self.get_object(response), 'asn')
|
2019-10-04 16:46:57 +02:00
|
|
|
|
2019-10-04 16:07:19 +02:00
|
|
|
def test_btc_steroids(self):
|
2021-06-11 11:19:57 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
|
|
|
|
2019-10-04 16:07:19 +02:00
|
|
|
query = {"module": "btc_steroids", "btc": "1ES14c7qLb5CYhLMUekctxLgc1FV2Ti9DA"}
|
2019-10-04 23:16:28 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-12-17 16:32:29 +01:00
|
|
|
try:
|
2020-05-01 04:45:47 +02:00
|
|
|
self.assertTrue(self.get_values(response).startswith('\n\nAddress:\t1ES14c7qLb5CYhLMUekctxLgc1FV2Ti9DA\nBalance:\t0.0002126800 BTC (+0.0007482500 BTC / -0.0005355700 BTC)'))
|
|
|
|
|
2019-12-17 16:32:29 +01:00
|
|
|
except Exception:
|
2021-04-16 16:47:20 +02:00
|
|
|
self.assertTrue(self.get_values(response).startswith('Not a valid BTC address'))
|
2019-10-04 16:07:19 +02:00
|
|
|
|
|
|
|
def test_btc_scam_check(self):
|
|
|
|
query = {"module": "btc_scam_check", "btc": "1ES14c7qLb5CYhLMUekctxLgc1FV2Ti9DA"}
|
2019-10-04 23:16:28 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-11-26 17:49:01 +01:00
|
|
|
self.assertEqual(self.get_values(response), '1es14c7qlb5cyhlmuekctxlgc1fv2ti9da fraudolent bitcoin address')
|
2019-10-04 16:07:19 +02:00
|
|
|
|
2019-12-17 15:19:29 +01:00
|
|
|
def test_circl_passivedns(self):
|
|
|
|
module_name = "circl_passivedns"
|
|
|
|
query = {"module": module_name,
|
|
|
|
"attribute": {"type": "domain",
|
|
|
|
"value": "circl.lu",
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"},
|
|
|
|
"config": {}}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_object(response), 'passive-dns')
|
|
|
|
except Exception:
|
|
|
|
self.assertTrue(self.get_errors(response).startswith('There is an authentication error'))
|
|
|
|
else:
|
2019-12-17 15:47:22 +01:00
|
|
|
response = self.misp_modules_post(query)
|
2019-12-17 16:46:26 +01:00
|
|
|
self.assertTrue(self.get_errors(response).startswith('CIRCL Passive DNS authentication is missing.'))
|
2019-12-17 15:19:29 +01:00
|
|
|
|
|
|
|
def test_circl_passivessl(self):
|
|
|
|
module_name = "circl_passivessl"
|
|
|
|
query = {"module": module_name,
|
2019-12-18 14:54:56 +01:00
|
|
|
"attribute": {"type": "ip-dst",
|
2021-04-12 11:11:01 +02:00
|
|
|
"value": "185.194.93.14",
|
2019-12-18 14:54:56 +01:00
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"},
|
2019-12-17 15:19:29 +01:00
|
|
|
"config": {}}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_object(response), 'x509')
|
|
|
|
except Exception:
|
|
|
|
self.assertTrue(self.get_errors(response).startswith('There is an authentication error'))
|
|
|
|
else:
|
2019-12-17 15:47:22 +01:00
|
|
|
response = self.misp_modules_post(query)
|
2019-12-17 16:46:26 +01:00
|
|
|
self.assertTrue(self.get_errors(response).startswith('CIRCL Passive SSL authentication is missing.'))
|
2019-12-17 15:19:29 +01:00
|
|
|
|
2019-10-04 16:07:19 +02:00
|
|
|
def test_countrycode(self):
|
|
|
|
query = {"module": "countrycode", "domain": "www.circl.lu"}
|
2019-10-04 23:16:28 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-10-08 15:50:15 +02:00
|
|
|
try:
|
2019-10-29 21:15:22 +01:00
|
|
|
self.assertEqual(self.get_values(response), 'Luxembourg')
|
2019-10-08 15:50:15 +02:00
|
|
|
except Exception:
|
|
|
|
results = ('http://www.geognos.com/api/en/countries/info/all.json not reachable', 'Unknown',
|
|
|
|
'Not able to get the countrycode references from http://www.geognos.com/api/en/countries/info/all.json')
|
|
|
|
self.assertIn(self.get_values(response), results)
|
2019-10-04 16:07:19 +02:00
|
|
|
|
2019-04-02 15:30:11 +02:00
|
|
|
def test_cve(self):
|
2019-10-29 21:36:07 +01:00
|
|
|
query = {"module": "cve", "vulnerability": "CVE-2010-4444", "config": {"custom_API": "https://cve.circl.lu/api/cve/"}}
|
2019-04-02 15:30:11 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-10-29 21:15:22 +01:00
|
|
|
self.assertTrue(self.get_values(response).startswith("Unspecified vulnerability in Oracle Sun Java System Access Manager"))
|
2019-04-02 15:30:11 +02:00
|
|
|
|
2019-10-27 21:19:43 +01:00
|
|
|
def test_cve_advanced(self):
|
|
|
|
query = {"module": "cve_advanced",
|
|
|
|
"attribute": {"type": "vulnerability",
|
2019-10-29 21:36:07 +01:00
|
|
|
"value": "CVE-2010-4444",
|
2019-10-27 21:19:43 +01:00
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"},
|
|
|
|
"config": {}}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_object(response), 'vulnerability')
|
|
|
|
except Exception:
|
|
|
|
print(self.get_errors(response))
|
|
|
|
|
2019-10-04 16:07:19 +02:00
|
|
|
def test_dbl_spamhaus(self):
|
2019-10-04 23:16:28 +02:00
|
|
|
query = {"module": "dbl_spamhaus", "domain": "totalmateria.net"}
|
2019-10-04 16:07:19 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-10-08 15:50:15 +02:00
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_values(response), 'totalmateria.net - spam domain')
|
|
|
|
except Exception:
|
|
|
|
try:
|
|
|
|
self.assertTrue(self.get_values(response).startswith('None of DNS query names exist:'))
|
|
|
|
except Exception:
|
|
|
|
self.assertEqual(self.get_errors(response), 'Not able to reach dbl.spamhaus.org or something went wrong')
|
2019-10-04 16:07:19 +02:00
|
|
|
|
2019-04-02 15:30:11 +02:00
|
|
|
def test_dns(self):
|
|
|
|
query = {"module": "dns", "hostname": "www.circl.lu", "config": {"nameserver": "8.8.8.8"}}
|
|
|
|
response = self.misp_modules_post(query)
|
2021-04-12 14:26:38 +02:00
|
|
|
self.assertEqual(self.get_values(response), '185.194.93.14')
|
2019-04-02 15:30:11 +02:00
|
|
|
|
2019-10-17 16:32:26 +02:00
|
|
|
def test_docx(self):
|
|
|
|
filename = 'test.docx'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "docx_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), '\nThis is an basic test docx file. ')
|
|
|
|
|
2019-10-29 21:35:45 +01:00
|
|
|
def test_farsight_passivedns(self):
|
|
|
|
module_name = 'farsight_passivedns'
|
|
|
|
if module_name in self.configs:
|
|
|
|
query_types = ('domain', 'ip-src')
|
|
|
|
query_values = ('google.com', '8.8.8.8')
|
|
|
|
results = ('mail.casadostemperos.com.br', 'outmail.wphf.at')
|
|
|
|
for query_type, query_value, result in zip(query_types, query_values, results):
|
|
|
|
query = {"module": module_name, query_type: query_value, 'config': self.configs[module_name]}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertIn(result, self.get_values(response))
|
|
|
|
except Exception:
|
2020-11-05 15:56:01 +01:00
|
|
|
self.assertTrue(self.get_errors(response).startswith('Something went wrong'))
|
2019-10-29 21:35:45 +01:00
|
|
|
else:
|
|
|
|
query = {"module": module_name, "ip-src": "8.8.8.8"}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Farsight DNSDB apikey is missing')
|
|
|
|
|
2019-04-02 15:30:11 +02:00
|
|
|
def test_haveibeenpwned(self):
|
2021-04-14 19:57:33 +02:00
|
|
|
module_name = 'hibp'
|
2019-04-02 15:30:11 +02:00
|
|
|
query = {"module": "hibp", "email-src": "info@circl.lu"}
|
|
|
|
response = self.misp_modules_post(query)
|
2021-04-14 19:57:33 +02:00
|
|
|
if module_name in self.configs:
|
|
|
|
to_check = self.get_values(response)
|
|
|
|
if to_check == "haveibeenpwned.com API not accessible (HTTP 401)":
|
|
|
|
self.skipTest(f"haveibeenpwned blocks travis IPs: {response}")
|
|
|
|
self.assertEqual(to_check, 'OK (Not Found)', response)
|
|
|
|
else:
|
|
|
|
self.assertEqual(self.get_errors(response), 'Have I Been Pwned authentication is incomplete (no API key)')
|
2019-04-02 15:30:11 +02:00
|
|
|
|
|
|
|
def test_greynoise(self):
|
2020-07-27 17:21:52 +02:00
|
|
|
module_name = 'greynoise'
|
|
|
|
query = {"module": module_name, "ip-dst": "1.1.1.1"}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_values(response), 'This IP is commonly spoofed in Internet-scan activity')
|
|
|
|
except Exception:
|
|
|
|
self.assertIn(
|
2021-12-24 14:59:13 +01:00
|
|
|
self.get_errors(response),
|
2020-07-27 17:21:52 +02:00
|
|
|
(
|
|
|
|
"Unauthorized. Please check your API key.",
|
|
|
|
"Too many requests. You've hit the rate-limit."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Missing Greynoise API key.')
|
2019-04-02 15:30:11 +02:00
|
|
|
|
2021-12-24 16:17:37 +01:00
|
|
|
@unittest.skip("Service doesn't work")
|
2019-04-02 15:30:11 +02:00
|
|
|
def test_ipasn(self):
|
2020-01-10 15:37:54 +01:00
|
|
|
query = {"module": "ipasn",
|
|
|
|
"attribute": {"type": "ip-src",
|
|
|
|
"value": "149.13.33.14",
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"}}
|
2019-04-02 15:30:11 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2020-01-10 15:12:52 +01:00
|
|
|
self.assertEqual(self.get_object(response), 'asn')
|
2019-04-02 15:30:11 +02:00
|
|
|
|
2019-10-29 21:35:45 +01:00
|
|
|
def test_macaddess_io(self):
|
|
|
|
module_name = 'macaddress_io'
|
|
|
|
query = {"module": module_name, "mac-address": "44:38:39:ff:ef:57"}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query["config"] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response)['Valid MAC address'], 'True')
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Authorization required')
|
|
|
|
|
2019-10-04 16:46:57 +02:00
|
|
|
def test_macvendors(self):
|
|
|
|
query = {"module": "macvendors", "mac-address": "FC-A1-3E-2A-1C-33"}
|
2019-04-02 15:30:11 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-10-04 16:46:57 +02:00
|
|
|
self.assertEqual(self.get_values(response), 'Samsung Electronics Co.,Ltd')
|
|
|
|
|
2019-10-17 16:32:26 +02:00
|
|
|
def test_ocr(self):
|
|
|
|
filename = 'misp-logo.png'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "ocr_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2020-11-05 15:56:01 +01:00
|
|
|
self.assertEqual(self.get_values(response).strip('\n'), 'Threat Sharing')
|
2019-10-17 16:32:26 +02:00
|
|
|
|
|
|
|
def test_ods(self):
|
|
|
|
filename = 'test.ods'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "ods_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2021-12-24 16:31:10 +01:00
|
|
|
self.assertEqual(self.get_values(response), '\n column.0\n0 ods test')
|
2019-10-17 16:32:26 +02:00
|
|
|
|
|
|
|
def test_odt(self):
|
|
|
|
filename = 'test.odt'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "odt_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), 'odt test')
|
|
|
|
|
2019-10-29 21:35:45 +01:00
|
|
|
def test_onyphe(self):
|
|
|
|
module_name = "onyphe"
|
2021-05-14 13:45:36 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
2019-10-29 21:35:45 +01:00
|
|
|
query = {"module": module_name, "ip-src": "8.8.8.8"}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query["config"] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertTrue(self.get_values(response).startswith('https://pastebin.com/raw/'))
|
|
|
|
except Exception:
|
|
|
|
self.assertEqual(self.get_errors(response), 'no more credits')
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Onyphe authentication is missing')
|
|
|
|
|
|
|
|
def test_onyphe_full(self):
|
|
|
|
module_name = "onyphe_full"
|
2021-05-14 13:45:36 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
2019-10-29 21:35:45 +01:00
|
|
|
query = {"module": module_name, "ip-src": "8.8.8.8"}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query["config"] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_values(response), '37.7510,-97.8220')
|
|
|
|
except Exception:
|
|
|
|
self.assertTrue(self.get_errors(response).startswith('Error '))
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Onyphe authentication is missing')
|
|
|
|
|
2021-12-24 16:17:37 +01:00
|
|
|
@unittest.skip("Unreliable results")
|
2019-10-15 16:04:03 +02:00
|
|
|
def test_otx(self):
|
|
|
|
query_types = ('domain', 'ip-src', 'md5')
|
|
|
|
query_values = ('circl.lu', '8.8.8.8', '616eff3e9a7575ae73821b4668d2801c')
|
2019-12-10 11:28:01 +01:00
|
|
|
results = (('149.13.33.14', '149.13.33.17', '6f9814ba70e68c3bce16d253e8d8f86e04a21a2b4172a0f7631040096ba2c47a'),
|
2019-10-29 21:15:22 +01:00
|
|
|
'ffc2595aefa80b61621023252b5f0ccb22b6e31d7f1640913cd8ff74ddbd8b41',
|
2019-10-15 16:04:03 +02:00
|
|
|
'8.8.8.8')
|
|
|
|
for query_type, query_value, result in zip(query_types, query_values, results):
|
|
|
|
query = {"module": "otx", query_type: query_value, "config": {"apikey": "1"}}
|
|
|
|
response = self.misp_modules_post(query)
|
2019-10-17 12:46:29 +02:00
|
|
|
try:
|
2019-10-29 21:15:22 +01:00
|
|
|
self.assertIn(self.get_values(response), result)
|
2019-10-17 12:46:29 +02:00
|
|
|
except KeyError:
|
|
|
|
# Empty results, which in this case comes from a connection error
|
|
|
|
continue
|
2019-10-15 16:04:03 +02:00
|
|
|
|
2019-10-30 16:29:18 +01:00
|
|
|
def test_passivetotal(self):
|
|
|
|
module_name = "passivetotal"
|
2021-04-14 14:51:28 +02:00
|
|
|
query = {"module": module_name, "ip-src": "185.194.93.14", "config": {}}
|
2019-10-30 16:29:18 +01:00
|
|
|
if module_name in self.configs:
|
|
|
|
query["config"] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
2021-04-16 22:17:52 +02:00
|
|
|
self.assertIn('www.circl.lu', response.json()['results'][0]['values'])
|
2019-10-30 16:29:18 +01:00
|
|
|
except Exception:
|
2019-10-31 17:16:27 +01:00
|
|
|
self.assertIn(self.get_errors(response), ('We hit an error, time to bail!', 'API quota exceeded.'))
|
2019-10-30 16:29:18 +01:00
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Configuration is missing from the request.')
|
|
|
|
|
2019-10-17 16:32:26 +02:00
|
|
|
def test_pdf(self):
|
|
|
|
filename = 'test.pdf'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "pdf_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), 'Pdf test')
|
|
|
|
|
|
|
|
def test_pptx(self):
|
|
|
|
filename = 'test.pptx'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "pptx_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), '\npptx test\n')
|
|
|
|
|
2019-10-31 11:46:11 +01:00
|
|
|
def test_qrcode(self):
|
|
|
|
filename = 'qrcode.jpeg'
|
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
|
|
|
encoded = b64encode(f.read()).decode()
|
|
|
|
query = {"module": "qrcode", "attachment": filename, "data": encoded}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), '1GXZ6v7FZzYBEnoRaG77SJxhu7QkvQmFuh')
|
|
|
|
|
2020-02-25 15:26:52 +01:00
|
|
|
def test_ransomcoindb(self):
|
|
|
|
query = {"module": "ransomcoindb",
|
|
|
|
"attributes": {"type": "btc",
|
|
|
|
"value": "1ES14c7qLb5CYhLMUekctxLgc1FV2Ti9DA",
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"}}
|
|
|
|
if 'ransomcoindb' not in self.configs:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), "Ransomcoindb API key is missing")
|
|
|
|
|
2019-10-04 16:46:57 +02:00
|
|
|
def test_rbl(self):
|
2021-04-19 08:30:39 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
2019-10-04 16:46:57 +02:00
|
|
|
query = {"module": "rbl", "ip-src": "8.8.8.8"}
|
2019-10-04 17:46:25 +02:00
|
|
|
response = self.misp_modules_post(query)
|
2019-10-08 15:50:15 +02:00
|
|
|
try:
|
2021-04-16 22:17:52 +02:00
|
|
|
self.assertTrue(self.get_values(response).startswith('8.8.8.8.bl.spamcannibal.org'))
|
2019-10-08 15:50:15 +02:00
|
|
|
except Exception:
|
|
|
|
self.assertEqual(self.get_errors(response), "No data found by querying known RBLs")
|
2019-10-04 16:46:57 +02:00
|
|
|
|
|
|
|
def test_reversedns(self):
|
|
|
|
query = {"module": "reversedns", "ip-src": "8.8.8.8"}
|
|
|
|
response = self.misp_modules_post(query)
|
2019-10-29 21:15:22 +01:00
|
|
|
self.assertEqual(self.get_values(response), 'dns.google.')
|
2019-10-04 17:46:25 +02:00
|
|
|
|
2019-10-30 16:29:18 +01:00
|
|
|
def test_securitytrails(self):
|
|
|
|
module_name = "securitytrails"
|
|
|
|
query_types = ('ip-src', 'domain')
|
|
|
|
query_values = ('149.13.33.14', 'circl.lu')
|
2019-10-31 17:16:27 +01:00
|
|
|
results = ('circl.lu', 'ns4.eurodns.com')
|
2019-10-30 16:29:18 +01:00
|
|
|
if module_name in self.configs:
|
|
|
|
for query_type, query_value, result in zip(query_types, query_values, results):
|
|
|
|
query = {"module": module_name, query_type: query_value, "config": self.configs[module_name]}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_values(response), result)
|
|
|
|
except Exception:
|
2019-10-31 17:16:27 +01:00
|
|
|
self.assertTrue(self.get_errors(response).startswith("You've exceeded the usage limits for your account."))
|
2019-10-30 16:29:18 +01:00
|
|
|
else:
|
|
|
|
query = {"module": module_name, query_values[0]: query_types[0]}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'SecurityTrails authentication is missing')
|
|
|
|
|
|
|
|
def test_shodan(self):
|
|
|
|
module_name = "shodan"
|
2021-04-15 16:08:56 +02:00
|
|
|
query = {
|
|
|
|
"module": module_name,
|
|
|
|
"attribute": {
|
|
|
|
"uuid": "a21aae0c-7426-4762-9b79-854314d69059",
|
|
|
|
"type": "ip-src",
|
|
|
|
"value": "149.13.33.14"
|
|
|
|
}
|
|
|
|
}
|
2019-10-30 16:29:18 +01:00
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
2021-04-16 22:17:52 +02:00
|
|
|
self.assertEqual(self.get_object(response), 'ip-api-address')
|
2019-10-30 16:29:18 +01:00
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Shodan authentication is missing')
|
|
|
|
|
2019-10-04 17:46:25 +02:00
|
|
|
def test_sigma_queries(self):
|
|
|
|
query = {"module": "sigma_queries", "sigma": self.sigma_rule}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertTrue(self.get_values(response)['kibana'].startswith('[\n {\n "_id": "Antivirus-Web-Shell-Detection"'))
|
|
|
|
|
|
|
|
def test_sigma_syntax(self):
|
|
|
|
query = {"module": "sigma_syntax_validator", "sigma": self.sigma_rule}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertTrue(self.get_values(response).startswith('Syntax valid:'))
|
2019-10-07 17:14:27 +02:00
|
|
|
|
2019-10-15 16:04:03 +02:00
|
|
|
def test_sourcecache(self):
|
|
|
|
input_value = "https://www.misp-project.org/feeds/"
|
|
|
|
query = {"module": "sourcecache", "link": input_value}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), input_value)
|
|
|
|
self.assertTrue(self.get_data(response).startswith('PCFET0NUWVBFIEhUTUw+CjwhLS0KCUFyY2FuYSBieSBIVE1MN'))
|
|
|
|
|
2019-10-07 17:14:27 +02:00
|
|
|
def test_stix2_pattern_validator(self):
|
|
|
|
query = {"module": "stix2_pattern_syntax_validator", "stix2-pattern": "[ipv4-addr:value = '8.8.8.8']"}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), 'Syntax valid')
|
2019-10-15 16:04:03 +02:00
|
|
|
def test_threatcrowd(self):
|
2021-04-19 08:07:22 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
2019-10-15 16:04:03 +02:00
|
|
|
query_types = ('domain', 'ip-src', 'md5', 'whois-registrant-email')
|
2021-04-18 18:11:37 +02:00
|
|
|
query_values = ('circl.lu', '149.13.33.14', '616eff3e9a7575ae73821b4668d2801c', 'hostmaster@eurodns.com')
|
2021-04-15 10:33:36 +02:00
|
|
|
results = ('149.13.33.4', 'cve.circl.lu', 'devilreturns.com', 'navabi.lu')
|
2019-10-15 16:04:03 +02:00
|
|
|
for query_type, query_value, result in zip(query_types, query_values, results):
|
|
|
|
query = {"module": "threatcrowd", query_type: query_value}
|
|
|
|
response = self.misp_modules_post(query)
|
2019-10-29 21:15:22 +01:00
|
|
|
self.assertTrue(self.get_values(response), result)
|
2019-10-15 16:04:03 +02:00
|
|
|
|
2019-10-16 22:00:36 +02:00
|
|
|
def test_threatminer(self):
|
2021-04-19 08:07:22 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
2019-10-16 22:00:36 +02:00
|
|
|
query_types = ('domain', 'ip-src', 'md5')
|
|
|
|
query_values = ('circl.lu', '149.13.33.4', 'b538dbc6160ef54f755a540e06dc27cd980fc4a12005e90b3627febb44a1a90f')
|
2019-10-17 10:41:11 +02:00
|
|
|
results = ('149.13.33.14', 'f6ecb9d5c21defb1f622364a30cb8274f817a1a2', 'http://www.circl.lu/')
|
2019-10-16 22:00:36 +02:00
|
|
|
for query_type, query_value, result in zip(query_types, query_values, results):
|
|
|
|
query = {"module": "threatminer", query_type: query_value}
|
|
|
|
response = self.misp_modules_post(query)
|
2019-10-29 21:15:22 +01:00
|
|
|
self.assertTrue(self.get_values(response), result)
|
2019-10-16 22:00:36 +02:00
|
|
|
|
2019-10-30 16:29:18 +01:00
|
|
|
def test_urlhaus(self):
|
|
|
|
query_types = ('domain', 'ip-src', 'sha256', 'url')
|
|
|
|
query_values = ('www.bestwpdesign.com', '79.118.195.239',
|
|
|
|
'a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3',
|
|
|
|
'http://79.118.195.239:1924/.i')
|
|
|
|
results = ('url', 'url', 'virustotal-report', 'virustotal-report')
|
|
|
|
for query_type, query_value, result in zip(query_types[:2], query_values[:2], results[:2]):
|
|
|
|
query = {"module": "urlhaus",
|
|
|
|
"attribute": {"type": query_type,
|
|
|
|
"value": query_value,
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"}}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_attribute(response), result)
|
|
|
|
for query_type, query_value, result in zip(query_types[2:], query_values[2:], results[2:]):
|
|
|
|
query = {"module": "urlhaus",
|
|
|
|
"attribute": {"type": query_type,
|
|
|
|
"value": query_value,
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"}}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_object(response), result)
|
|
|
|
|
|
|
|
def test_urlscan(self):
|
|
|
|
module_name = "urlscan"
|
|
|
|
query = {"module": module_name, "url": "https://circl.lu/team"}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), 'circl.lu')
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), 'Urlscan apikey is missing')
|
|
|
|
|
|
|
|
def test_virustotal_public(self):
|
|
|
|
module_name = "virustotal_public"
|
2021-04-15 16:08:56 +02:00
|
|
|
attributes = (
|
|
|
|
{
|
|
|
|
"uuid": "ffea0594-355a-42fe-9b98-fad28fd248b3",
|
|
|
|
"type": "domain",
|
|
|
|
"value": "circl.lu"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "1f3f0f2d-5143-4b05-a0f1-8ac82f51a979",
|
|
|
|
"type": "ip-src",
|
|
|
|
"value": "149.13.33.14"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "b4be6652-f4ff-4515-ae63-3f016df37e8f",
|
|
|
|
"type": "sha256",
|
|
|
|
"value": "a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "6cead544-b683-48cb-b19b-a2561ffa1f51",
|
|
|
|
"type": "url",
|
|
|
|
"value": "http://194.169.88.56:49151/.i"
|
|
|
|
}
|
|
|
|
)
|
2019-10-30 16:29:18 +01:00
|
|
|
results = ('whois', 'asn', 'file', 'virustotal-report')
|
|
|
|
if module_name in self.configs:
|
2021-04-15 16:08:56 +02:00
|
|
|
for attribute, result in zip(attributes, results):
|
2019-10-30 16:29:18 +01:00
|
|
|
query = {"module": module_name,
|
2021-04-15 16:08:56 +02:00
|
|
|
"attribute": attribute,
|
2019-10-30 16:29:18 +01:00
|
|
|
"config": self.configs[module_name]}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_object(response), result)
|
|
|
|
except Exception:
|
|
|
|
self.assertEqual(self.get_errors(response), "VirusTotal request rate limit exceeded.")
|
|
|
|
else:
|
2021-04-15 16:39:28 +02:00
|
|
|
query = {
|
|
|
|
"module": module_name,
|
|
|
|
"attribute": attributes[0]
|
|
|
|
}
|
2019-10-30 16:29:18 +01:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), "A VirusTotal api key is required for this module.")
|
|
|
|
|
|
|
|
def test_virustotal(self):
|
|
|
|
module_name = "virustotal"
|
2021-04-15 16:08:56 +02:00
|
|
|
attributes = (
|
|
|
|
{
|
|
|
|
"uuid": "ffea0594-355a-42fe-9b98-fad28fd248b3",
|
|
|
|
"type": "domain",
|
|
|
|
"value": "circl.lu"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "1f3f0f2d-5143-4b05-a0f1-8ac82f51a979",
|
|
|
|
"type": "ip-src",
|
|
|
|
"value": "149.13.33.14"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "b4be6652-f4ff-4515-ae63-3f016df37e8f",
|
|
|
|
"type": "sha256",
|
|
|
|
"value": "a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"uuid": "6cead544-b683-48cb-b19b-a2561ffa1f51",
|
|
|
|
"type": "url",
|
|
|
|
"value": "http://194.169.88.56:49151/.i"
|
|
|
|
}
|
|
|
|
)
|
2019-10-31 11:46:58 +01:00
|
|
|
results = ('domain-ip', 'asn', 'virustotal-report', 'virustotal-report')
|
2019-10-30 16:29:18 +01:00
|
|
|
if module_name in self.configs:
|
2021-04-15 16:08:56 +02:00
|
|
|
for attribute, result in zip(attributes, results):
|
2019-10-30 16:29:18 +01:00
|
|
|
query = {"module": module_name,
|
2021-04-15 16:08:56 +02:00
|
|
|
"attribute": attribute,
|
2019-10-30 16:29:18 +01:00
|
|
|
"config": self.configs[module_name]}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_object(response), result)
|
|
|
|
except Exception:
|
|
|
|
self.assertEqual(self.get_errors(response), "VirusTotal request rate limit exceeded.")
|
|
|
|
else:
|
2021-04-15 16:39:28 +02:00
|
|
|
query = {
|
|
|
|
"module": module_name,
|
|
|
|
"attribute": attributes[0]
|
|
|
|
}
|
2019-10-30 16:29:18 +01:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), "A VirusTotal api key is required for this module.")
|
|
|
|
|
2019-10-31 11:47:47 +01:00
|
|
|
def test_vulners(self):
|
|
|
|
module_name = "vulners"
|
|
|
|
query = {"module": module_name, "vulnerability": "CVE-2010-3333"}
|
|
|
|
if module_name in self.configs:
|
|
|
|
query['config'] = self.configs[module_name]
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertTrue(self.get_values(response).endswith('"RTF Stack Buffer Overflow Vulnerability."'))
|
|
|
|
else:
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), "A Vulners api key is required for this module.")
|
|
|
|
|
2019-10-07 17:14:27 +02:00
|
|
|
def test_wikidata(self):
|
|
|
|
query = {"module": "wiki", "text": "Google"}
|
|
|
|
response = self.misp_modules_post(query)
|
2019-10-08 15:50:15 +02:00
|
|
|
try:
|
|
|
|
self.assertEqual(self.get_values(response), 'http://www.wikidata.org/entity/Q95')
|
2019-10-15 14:41:38 +02:00
|
|
|
except KeyError:
|
|
|
|
self.assertEqual(self.get_errors(response), 'Something went wrong, look in the server logs for details')
|
2019-10-08 15:50:15 +02:00
|
|
|
except Exception:
|
|
|
|
self.assertEqual(self.get_values(response), 'No additional data found on Wikidata')
|
2019-10-07 17:14:27 +02:00
|
|
|
|
2019-11-05 17:13:34 +01:00
|
|
|
def test_xforceexchange(self):
|
|
|
|
module_name = "xforceexchange"
|
|
|
|
query_types = ('domain', 'ip-src', 'md5', 'url', 'vulnerability')
|
|
|
|
query_values = ('mediaget.com', '61.255.239.86', '474b9ccf5ab9d72ca8a333889bbb34f0',
|
|
|
|
'mediaget.com', 'CVE-2014-2601')
|
|
|
|
results = ('domain-ip', 'domain-ip', 'url', 'domain-ip', 'vulnerability')
|
|
|
|
if module_name in self.configs:
|
|
|
|
for query_type, query_value, result in zip(query_types, query_values, results):
|
|
|
|
query = {"module": module_name,
|
|
|
|
"attribute": {"type": query_type,
|
|
|
|
"value": query_value,
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"},
|
|
|
|
"config": self.configs[module_name]}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_object(response), result)
|
|
|
|
else:
|
|
|
|
query = {"module": module_name,
|
|
|
|
"attribute": {"type": query_types[0],
|
|
|
|
"value": query_values[0],
|
|
|
|
"uuid": "ea89a33b-4ab7-4515-9f02-922a0bee333d"}}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_errors(response), "An API authentication is required (key and password).")
|
|
|
|
|
2019-10-17 16:32:26 +02:00
|
|
|
def test_xlsx(self):
|
2021-04-19 08:07:22 +02:00
|
|
|
if LiveCI:
|
|
|
|
return True
|
2019-10-17 16:32:26 +02:00
|
|
|
filename = 'test.xlsx'
|
2019-10-18 09:43:53 +02:00
|
|
|
with open(f'{self.dirname}/test_files/{filename}', 'rb') as f:
|
2019-10-17 16:32:26 +02:00
|
|
|
encoded = b64encode(f.read()).decode()
|
2019-10-18 11:09:10 +02:00
|
|
|
query = {"module": "xlsx_enrich", "attachment": filename, "data": encoded}
|
2019-10-17 16:32:26 +02:00
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), ' header\n0 xlsx test')
|
|
|
|
|
2019-10-07 17:14:27 +02:00
|
|
|
def test_yara_query(self):
|
|
|
|
query = {"module": "yara_query", "md5": "b2a5abfeef9e36964281a31e17b57c97"}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), 'import "hash"\r\nrule MD5 {\r\n\tcondition:\r\n\t\thash.md5(0, filesize) == "b2a5abfeef9e36964281a31e17b57c97"\r\n}')
|
|
|
|
|
|
|
|
def test_yara_validator(self):
|
|
|
|
query = {"module": "yara_syntax_validator", "yara": 'import "hash"\r\nrule MD5 {\r\n\tcondition:\r\n\t\thash.md5(0, filesize) == "b2a5abfeef9e36964281a31e17b57c97"\r\n}'}
|
|
|
|
response = self.misp_modules_post(query)
|
|
|
|
self.assertEqual(self.get_values(response), 'Syntax valid')
|