-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#465 add IOC Parser feature for PDF files
- Loading branch information
1 parent
d2ef8d6
commit 76b9b49
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from iocp import Parser | ||
import sys | ||
from io import StringIO | ||
from contextlib import redirect_stdout | ||
|
||
import json | ||
|
||
from .submodule_base import SubmoduleBaseclass | ||
|
||
|
||
class IOCPSubmodule(SubmoduleBaseclass): | ||
def __init__(self): | ||
SubmoduleBaseclass.__init__(self) | ||
self.name = 'IOC Parser' | ||
|
||
def check_file(self, **kwargs): | ||
""" | ||
IOCP submodule will analyze every supported file and deliver IOCs found in it | ||
:return: True | ||
""" | ||
if kwargs.get('filetype') in ['PDF']: | ||
return True | ||
|
||
def module_summary(self): | ||
taxonomies = [] | ||
level = 'info' | ||
namespace = 'FileInfo' | ||
predicate = 'IOC Parser' | ||
value = '' | ||
#pdfid_version = '' | ||
for section in self.results: | ||
if section['submodule_section_header'] == 'IOC Parser Information': | ||
#if section.get('submodule_section_content').get('iocp_result'): | ||
iocp_len = len(section.get('submodule_section_content').get('iocp_result')) | ||
taxonomies.append(self.build_taxonomy(level, namespace, predicate, iocp_len)) | ||
self.summary['taxonomies'] = taxonomies | ||
return self.summary | ||
|
||
def iocparser(self, path): | ||
""" | ||
""" | ||
out = StringIO() | ||
results = {'iocp_result': []} | ||
P = Parser | ||
oformat = 'json' | ||
try: | ||
with redirect_stdout(out): | ||
P.Parser(output_format=oformat).parse(path) | ||
oo = out.getvalue().split('\n') | ||
if oo[-1] == '': | ||
oo.pop() | ||
for i in oo: | ||
j = {} | ||
for k,v in json.loads(i).items(): | ||
if k in ['match','type']: | ||
j.update({k:v}) | ||
if j not in results['iocp_result']: | ||
results['iocp_result'].append(j) | ||
except Exception as e: | ||
return e | ||
return results | ||
|
||
|
||
def analyze_file(self, path): | ||
self.add_result_subsection('IOC Parser Information', self.iocparser(path)) | ||
return self.results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.