172 lines
6.6 KiB
Python
172 lines
6.6 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright 2012 The Plaso Project Authors.
|
|
# Please see the AUTHORS file for details on individual authors.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""Tests for the MRUList Windows Registry plugin."""
|
|
|
|
import unittest
|
|
|
|
# pylint: disable=unused-import
|
|
from plaso.formatters import winreg as winreg_formatter
|
|
from plaso.lib import timelib_test
|
|
from plaso.parsers.winreg_plugins import mrulist
|
|
from plaso.parsers.winreg_plugins import test_lib
|
|
from plaso.winreg import test_lib as winreg_test_lib
|
|
|
|
|
|
class TestMRUListStringPlugin(test_lib.RegistryPluginTestCase):
|
|
"""Tests for the string MRUList plugin."""
|
|
|
|
def setUp(self):
|
|
"""Sets up the needed objects used throughout the test."""
|
|
self._plugin = mrulist.MRUListStringPlugin()
|
|
|
|
def testProcess(self):
|
|
"""Tests the Process function."""
|
|
key_path = u'\\Microsoft\\Some Windows\\InterestingApp\\MRU'
|
|
values = []
|
|
|
|
values.append(winreg_test_lib.TestRegValue(
|
|
'MRUList', 'acb'.encode('utf_16_le'),
|
|
winreg_test_lib.TestRegValue.REG_SZ, offset=123))
|
|
values.append(winreg_test_lib.TestRegValue(
|
|
'a', 'Some random text here'.encode('utf_16_le'),
|
|
winreg_test_lib.TestRegValue.REG_SZ, offset=1892))
|
|
values.append(winreg_test_lib.TestRegValue(
|
|
'b', 'c:/evil.exe'.encode('utf_16_le'),
|
|
winreg_test_lib.TestRegValue.REG_BINARY, offset=612))
|
|
values.append(winreg_test_lib.TestRegValue(
|
|
'c', 'C:/looks_legit.exe'.encode('utf_16_le'),
|
|
winreg_test_lib.TestRegValue.REG_SZ, offset=1001))
|
|
|
|
timestamp = timelib_test.CopyStringToTimestamp('2012-08-28 09:23:49.002031')
|
|
winreg_key = winreg_test_lib.TestRegKey(
|
|
key_path, timestamp, values, 1456)
|
|
|
|
event_queue_consumer = self._ParseKeyWithPlugin(self._plugin, winreg_key)
|
|
event_objects = self._GetEventObjectsFromQueue(event_queue_consumer)
|
|
|
|
self.assertEquals(len(event_objects), 1)
|
|
|
|
event_object = event_objects[0]
|
|
|
|
# This should just be the plugin name, as we're invoking it directly,
|
|
# and not through the parser.
|
|
self.assertEquals(event_object.parser, self._plugin.plugin_name)
|
|
|
|
expected_timestamp = timelib_test.CopyStringToTimestamp(
|
|
'2012-08-28 09:23:49.002031')
|
|
self.assertEquals(event_object.timestamp, expected_timestamp)
|
|
|
|
expected_msg = (
|
|
u'[{0:s}] '
|
|
u'Index: 1 [MRU Value a]: Some random text here '
|
|
u'Index: 2 [MRU Value c]: C:/looks_legit.exe '
|
|
u'Index: 3 [MRU Value b]: c:/evil.exe').format(key_path)
|
|
|
|
expected_msg_short = (
|
|
u'[{0:s}] Index: 1 [MRU Value a]: Some ran...').format(key_path)
|
|
|
|
self._TestGetMessageStrings(event_object, expected_msg, expected_msg_short)
|
|
|
|
|
|
class TestMRUListShellItemListPlugin(test_lib.RegistryPluginTestCase):
|
|
"""Tests for the shell item list MRUList plugin."""
|
|
|
|
def setUp(self):
|
|
"""Sets up the needed objects used throughout the test."""
|
|
self._plugin = mrulist.MRUListShellItemListPlugin()
|
|
|
|
def testProcess(self):
|
|
"""Tests the Process function."""
|
|
key_path = (
|
|
u'\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\'
|
|
u'DesktopStreamMRU')
|
|
values = []
|
|
|
|
data = ''.join(map(chr, [
|
|
0x14, 0x00, 0x1f, 0x00, 0xe0, 0x4f, 0xd0, 0x20, 0xea, 0x3a, 0x69, 0x10,
|
|
0xa2, 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, 0x9d, 0x19, 0x00, 0x23, 0x43,
|
|
0x3a, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0xee, 0x15, 0x00, 0x31,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x3e, 0x7a, 0x60, 0x10, 0x80, 0x57,
|
|
0x69, 0x6e, 0x6e, 0x74, 0x00, 0x00, 0x18, 0x00, 0x31, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x2e, 0x3e, 0xe4, 0x62, 0x10, 0x00, 0x50, 0x72, 0x6f, 0x66,
|
|
0x69, 0x6c, 0x65, 0x73, 0x00, 0x00, 0x25, 0x00, 0x31, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x2e, 0x3e, 0xe4, 0x62, 0x10, 0x00, 0x41, 0x64, 0x6d, 0x69,
|
|
0x6e, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x00, 0x41, 0x44,
|
|
0x4d, 0x49, 0x4e, 0x49, 0x7e, 0x31, 0x00, 0x17, 0x00, 0x31, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x2e, 0x3e, 0xe4, 0x62, 0x10, 0x00, 0x44, 0x65, 0x73,
|
|
0x6b, 0x74, 0x6f, 0x70, 0x00, 0x00, 0x00, 0x00]))
|
|
|
|
values.append(winreg_test_lib.TestRegValue(
|
|
'MRUList', 'a'.encode('utf_16_le'),
|
|
winreg_test_lib.TestRegValue.REG_SZ, offset=123))
|
|
values.append(winreg_test_lib.TestRegValue(
|
|
'a', data, winreg_test_lib.TestRegValue.REG_BINARY, offset=612))
|
|
|
|
timestamp = timelib_test.CopyStringToTimestamp('2012-08-28 09:23:49.002031')
|
|
winreg_key = winreg_test_lib.TestRegKey(
|
|
key_path, timestamp, values, 1456)
|
|
|
|
event_queue_consumer = self._ParseKeyWithPlugin(self._plugin, winreg_key)
|
|
event_objects = self._GetEventObjectsFromQueue(event_queue_consumer)
|
|
|
|
self.assertEquals(len(event_objects), 5)
|
|
|
|
# A MRUList event object.
|
|
event_object = event_objects[4]
|
|
|
|
# This should just be the plugin name, as we're invoking it directly,
|
|
# and not through the parser.
|
|
self.assertEquals(event_object.parser, self._plugin.plugin_name)
|
|
|
|
expected_timestamp = timelib_test.CopyStringToTimestamp(
|
|
'2012-08-28 09:23:49.002031')
|
|
self.assertEquals(event_object.timestamp, expected_timestamp)
|
|
|
|
expected_msg = (
|
|
u'[{0:s}] '
|
|
u'Index: 1 [MRU Value a]: Shell item list: '
|
|
u'[My Computer, C:\\, Winnt, Profiles, Administrator, Desktop]').format(
|
|
key_path)
|
|
|
|
expected_msg_short = u'[{0:s}] Index:...'.format(key_path)
|
|
|
|
self._TestGetMessageStrings(event_object, expected_msg, expected_msg_short)
|
|
|
|
# A shell item event object.
|
|
event_object = event_objects[0]
|
|
|
|
expected_timestamp = timelib_test.CopyStringToTimestamp(
|
|
'2011-01-14 12:03:52')
|
|
self.assertEquals(event_object.timestamp, expected_timestamp)
|
|
|
|
expected_msg = (
|
|
u'Name: Winnt '
|
|
u'Origin: {0:s}').format(key_path)
|
|
|
|
expected_msg_short = (
|
|
u'Name: Winnt '
|
|
u'Origin: \\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\'
|
|
u'Deskt...')
|
|
|
|
self._TestGetMessageStrings(event_object, expected_msg, expected_msg_short)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|