-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmispsearch.py
50 lines (40 loc) · 1.45 KB
/
mispsearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
import requests
from json import JSONDecodeError
import json
from datetime import datetime
startTime = datetime.now()
def search_misp_attributes(param_value):
headers = {
'Authorization': 'KEYKEYKEY',
'Accept': 'application/json',
}
json_data = {
'returnFormat': 'json',
"limit": "5",
'value': param_value,
}
try:
response = requests.post('https://misp.local/attributes/restSearch', headers=headers, json=json_data,verify=False,timeout=10)
response.close()
except:
return "Unexecpted Error..."
print(requests.exceptions.RequestException)
sys.exit()
try:
resp_dict = response.json()
search_index = 1
list = []
for x in resp_dict['response']['Attribute']:
param_category = (x['category'])
param_type = (x['type'])
param_comment = (x['comment'])
param_value = (x['value'])
param_info = (x['Event']['info'])
results = ("Search Results:" + str(search_index) + "," + "category:" + param_category + "," + "type:" + param_type + "," + "comment:" + param_comment + "," + "value:" + param_value + "," + "Event Info:" + param_info)
list.insert(search_index, results)
search_index += 1
return list
except JSONDecodeError:
print('Response could not be serialized')
print("Elapsed Time : ", datetime.now() - startTime)