Skip to content

Commit

Permalink
Unprotect.it support
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnim committed Mar 30, 2023
1 parent 5938162 commit c09cf4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
21 changes: 18 additions & 3 deletions commands/attackmatrix/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

def process(command, channel, username, params):
messages = []
querytypes = ('search', 'mitre', 'actoroverlap', 'ttpoverlap', 'findactor')
querytypes = ('search', 'mitre', 'actoroverlap', 'ttpoverlap', 'findactor', 'matrices', 'config')
querytype = params[0].strip()
stripchars = '`\n\r\'\"'
regex = re.compile('[%s]' % stripchars)
categories = ('Actors', 'Techniques', 'Malwares', 'Tools', 'Mitigations', 'Tactics', 'Data Sources', 'Case Studies', 'Campaigns', 'Matrices')
categories = ('Actors', 'Techniques', 'Malwares', 'Tools', 'Mitigations', 'Tactics', 'Data Sources', 'Case Studies', 'Campaigns', 'Detection Rules', 'Code Snippets', 'Matrices')
tableheaders = collections.OrderedDict({
'type': 'Type',
'name': 'Name',
Expand All @@ -43,12 +43,27 @@ def process(command, channel, username, params):
else:
try:
keywords = params[1:]
if len(' '.join(keywords))<4:
if len(' '.join(keywords))<4 and not querytype in ('matrices', 'config'):
messages.append({'text': 'Please specify at least one reasonably-sized keyword to query the AttackMatrix `'+querytype+'`.'})
else:
headers={
'Content-Type': settings.CONTENTTYPE,
}
if querytype in ('matrices', 'config'):
APIENDPOINT = settings.APIURL['attackmatrix']['url']+'/explore/'
with requests.get(APIENDPOINT, headers=headers) as response:
json_response = response.json()
if len(json_response):
table = 'ATT&CK Matrix API endpoint currently has ' + str(len(json_response['Metadata']['matrices'])) + ' databases loaded:'
table += '\n\n'
table += '| **Matrix Name** | **Description** |\n'
table += '|:- |:- |\n'
for matrix in json_response['Metadata']['matrices']:
name = json_response['Metadata']['matrices'][matrix]['Metadata']['name'][0]
description = json_response['Metadata']['matrices'][matrix]['Metadata']['description'][0]
table += '| '+name+' | '+description+' |\n'
table += '\n\n'
messages.append({'text': table})
if querytype == 'search':
searchterms = '&params='.join([urllib.parse.quote(_) for _ in keywords])
APIENDPOINT = settings.APIURL['attackmatrix']['url']+'/search?params='+searchterms
Expand Down
10 changes: 10 additions & 0 deletions commands/attackmatrix/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@
'the resulting list of matching actors with the matching certainty. Particularly useful with the '
'lists of MITRE IDs, such as the `easy pivoting` one from the VirusTotal module output.',
},
'matrices': {
'args': None,
'desc': 'Display all ATT&CK Matrices and other databases that have been loaded into the '
'configured AttackMatrix API endpoint: ' + APIURL['attackmatrix']['url'] + '.',
},
'config': {
'args': None,
'desc': 'Display all ATT&CK Matrices and other databases that have been loaded into the '
'configured AttackMatrix API endpoint: ' + APIURL['attackmatrix']['url'] + '.',
},
}

0 comments on commit c09cf4a

Please sign in to comment.