-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored ips_plugins/interface.py, added IPS parser plugin for stac…
…ks files.
- Loading branch information
1 parent
72ddaf1
commit cf67c35
Showing
10 changed files
with
14,107 additions
and
80 deletions.
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
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,87 @@ | ||
# -*- coding: utf-8 -*- | ||
"""IPS file parser plugin for Apple stacks report.""" | ||
|
||
from plaso.containers import events | ||
from plaso.parsers import ips_parser | ||
from plaso.parsers.ips_plugins import interface | ||
|
||
|
||
class AppleStacksIPSEvent(events.EventData): | ||
"""Apple stacks crash report. | ||
Attributes: | ||
bug_type (str): type of bug. | ||
crash_reporter_key (str): Key of the crash reporter. | ||
device_model (str): model of the device. | ||
event_time (dfdatetime.DateTimeValues): date and time of the crash report. | ||
kernel_version (str): kernel version. | ||
incident_identifier (str): uuid for crash. | ||
process_list (str): list of process names running at the time of the crash. | ||
os_version (str): version of the operating system. | ||
reason (str): reason for the crash. | ||
""" | ||
|
||
DATA_TYPE = 'apple:ips_stacks' | ||
|
||
def __init__(self): | ||
"""Initializes event data.""" | ||
super(AppleStacksIPSEvent, self).__init__(data_type=self.DATA_TYPE) | ||
self.bug_type = None | ||
self.crash_reporter_key = None | ||
self.device_model = None | ||
self.event_time = None | ||
self.kernel_version = None | ||
self.incident_identifier = None | ||
self.process_list = None | ||
self.os_version = None | ||
self.reason = None | ||
|
||
|
||
class AppleStacksIPSPlugin(interface.IPSPlugin): | ||
"""Parses Apple stacks crash IPS file.""" | ||
|
||
NAME = 'apple_stacks_ips' | ||
DATA_FORMAT = 'IPS stacks crash log' | ||
|
||
REQUIRED_HEADER_KEYS = ['bug_type', 'incident_id', 'os_version', 'timestamp'] | ||
REQUIRED_CONTENT_KEYS = [ | ||
'build', 'crashReporterKey', 'kernel', 'product', 'reason'] | ||
|
||
# pylint: disable=unused-argument | ||
def Process(self, parser_mediator, ips_file=None, **unused_kwargs): | ||
"""Extracts information from an IPS log file. | ||
This is the main method that an IPS plugin needs to implement. | ||
Args: | ||
parser_mediator (ParserMediator): parser mediator. | ||
ips_file (Optional[IpsFile]): database. | ||
Raises: | ||
ValueError: If the file value is missing. | ||
""" | ||
if ips_file is None: | ||
raise ValueError('Missing ips_file value') | ||
|
||
event_data = AppleStacksIPSEvent() | ||
event_data.bug_type = ips_file.header.get('bug_type') | ||
event_data.crash_reporter_key = ips_file.content.get('crashReporterKey') | ||
event_data.device_model = ips_file.content.get('product') | ||
event_data.kernel_version = ips_file.content.get('kernel') | ||
event_data.incident_identifier = ips_file.header.get('incident_id') | ||
event_data.os_version = ips_file.header.get('os_version') | ||
event_data.reason = ips_file.content.get('reason') | ||
|
||
process_list = [ | ||
i.get('procname') for i in ips_file.content.get( | ||
'processByPid').values()] | ||
process_list = list(set(process_list)) | ||
process_list.sort() | ||
|
||
event_data.process_list = ', '.join(process_list) | ||
|
||
event_timestamp = ips_file.header.get('timestamp') | ||
event_data.event_time = self._ParseTimestampValue( | ||
parser_mediator, event_timestamp) | ||
|
||
parser_mediator.ProduceEventData(event_data) | ||
|
||
|
||
ips_parser.IPSParser.RegisterPlugin(AppleStacksIPSPlugin) |
Oops, something went wrong.