Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact definitions filter helper #1883

Merged

Conversation

jnettesheim
Copy link
Contributor

One line description of pull request

Issue 1313, plaso engine updates to add forensic artifact filtering capabilities.

Description:

Per discussion in #1732 adding plaso engine changes in separate PR.

Related issue (if applicable): fixes #

Notes:

All contributions to Plaso undergo code
review
. This makes sure
that the code has appropriate test coverage and conforms to the Plaso style
guide
.

One of the maintainers will examine your code, and may request changes.

Checklist:

  • Local tests pass
  • Tests on TravisCI pass
  • Codacy passes (or flags issues that you think are acceptable)
  • Coveralls indicates test coverage is sufficient

If new dependencies are required:

  • l2tdevtools has been updated

@joachimmetz joachimmetz self-requested a review May 15, 2018 03:34
Copy link
Member

@joachimmetz joachimmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests, there are a couple of complex functions added where I would like to see tests to better understand them.

Besides that various style nits.

from dfwinreg import registry_searcher

from plaso.engine import path_helper

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • white line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

from plaso.engine import path_helper

class ArtifactDefinitionsFilterHelper(object):
"""Helper to create filters based on artifact defintions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defintions => definitions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

class ArtifactDefinitionsFilterHelper(object):
"""Helper to create filters based on artifact defintions.

Builds extraction and parsing filters from forensic artifact definitions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are "parsing filters" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

https://github.com/ForensicArtifacts/artifacts/blob/master/docs/Artifacts%20definition%20format%20and%20style%20guide.asciidoc
"""

ARTIFACT_FILTERS = 'ARTIFACT_FILTERS'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are only used by this class please prefix with an underscore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed several of these and added underscore to one only used in this class.

self._knowledge_base = knowledge_base

def BuildFindSpecs(self, environment_variables=None):
"""Build find specification from a forensic artifact definitions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build => Builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -133,3 +147,26 @@ def GetRelativePathForPathSpec(cls, path_spec, mount_path=None):
location = location[len(mount_path):]

return location

@classmethod
def ExpandUserHomeDirPath(cls, path, user_accounts):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows calls this profile directory not home directory, also don's use abbreviations such as Dir. This is more clear for an international audience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be for any operating system. Removed abbreviation.


@shared_test_lib.skipUnlessHasTestFile(['artifacts'])
@shared_test_lib.skipUnlessHasTestFile(['SYSTEM'])
def testBuildRegistryFindSpecs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testBuildRegistryFindSpecs => testBuildFindSpecsWithRegistry or testBuildFindSpecsOnRegistry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@shared_test_lib.skipUnlessHasTestFile(['artifacts'])
@shared_test_lib.skipUnlessHasTestFile(['SYSTEM'])
def testBuildRegistryFindSpecs(self):
"""Tests the BuildFindSpecs function for registry artifacts."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for => on
registry => Registry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@shared_test_lib.skipUnlessHasTestFile(['System.evtx'])
@shared_test_lib.skipUnlessHasTestFile(['testdir', 'filter_1.txt'])
@shared_test_lib.skipUnlessHasTestFile(['testdir', 'filter_3.txt'])
def testBuildFileFindSpecs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testBuildFileFindSpecs => testBuildFindSpecsWithFileSystem or testBuildFindSpecsOnFileSystem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# Three key paths found
self.assertEqual(len(key_paths), 3)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for BuildFindSpecsFromFileArtifact, _CheckKeyCompatibility, _ExpandRecursiveGlobs, _BuildRecursivePaths. The last 2 methods I have a hard time understanding from the code directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@codecov
Copy link

codecov bot commented May 27, 2018

Codecov Report

Merging #1883 into master will increase coverage by 0.01%.
The diff coverage is 88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1883      +/-   ##
==========================================
+ Coverage   84.03%   84.05%   +0.01%     
==========================================
  Files         435      436       +1     
  Lines       30998    31174     +176     
==========================================
+ Hits        26049    26202     +153     
- Misses       4949     4972      +23
Impacted Files Coverage Δ
plaso/engine/path_helper.py 98.11% <100%> (+1.62%) ⬆️
plaso/engine/artifact_filters.py 80% <80%> (ø)
plaso/storage/interface.py 77.35% <0%> (-0.42%) ⬇️
plaso/parsers/trendmicroav.py 86.52% <0%> (-0.08%) ⬇️
plaso/formatters/trendmicroav.py 96.87% <0%> (+1.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46d484b...10c448a. Read the comment docs.

@jnettesheim
Copy link
Contributor Author

jnettesheim commented May 28, 2018

@joachimmetz - PTAL.

@joachimmetz
Copy link
Member

@jnettesheim I'm having a look this weekend.

dynamically populate environment variables in key.
user_accounts (list[str]): identified user accounts stored in the
knowledge base.
find_specs (dict[artifacts.artifact_types]): Dictionary containing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_specs (dict[artifacts.artifact_types]): Dictionary containing ... I had a brief look at this but this arg looks weird to me. Find specs are a dfVFS class, but type information says artifacts.artifact_types ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning a list of dfvfs.FindSpect will simplify the interface.

@joachimmetz
Copy link
Member

@jnettesheim I've started looking at this. I've made some minor changes, mainly nits about docstrings and style formatting. I'll continue as soon as time permits

Copy link
Member

@joachimmetz joachimmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more comments and changes


from __future__ import unicode_literals

import logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use from plaso.engine import logger instead of logging

"""
find_specs = {}

artifact_definitions = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this loop can be merged with the next loop and remove the need for the artifact_definitions list

dynamically populate environment variables in key.
user_accounts (list[str]): identified user accounts stored in the
knowledge base.
find_specs (dict[artifacts.artifact_types]): Dictionary containing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning a list of dfvfs.FindSpect will simplify the interface.

'\\Windows\\Test\\*\\*\\*\\*\\*\\*\\*\\*',
'\\Windows\\Test\\*\\*\\*\\*\\*\\*\\*\\*\\*',
'\\Windows\\Test\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*']
self.assertItemsEqual(paths, check_paths)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not portable to python 3
Instance of 'PathHelperTest' has no 'assertItemsEqual' member (no-member)

@@ -3,6 +3,9 @@

from __future__ import unicode_literals

import logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user engine.logger instead

@@ -42,9 +49,19 @@ def ExpandWindowsPath(cls, path, environment_variables):
not path_segment.endswith('%')):
continue

lookup_key = path_segment.upper()[1:-1]
check_for_drive_letter = False
if path_segment.upper().startswith('%%ENVIRON_'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store upper case path in a variable seeing you're reusing it

_, _, new_path = new_path.rpartition(':')
user_paths.append(new_path)
else:
user_paths = [path]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive letter is not stripped here

path_segments = ['Users', 'testuser2', 'Documents', 'WindowsPowerShell',
'profile\\.ps1']
self.assertEqual(
find_specs[artifact_types.TYPE_INDICATOR_FILE][2]._location_segments,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing file_specs is a dict this test will be flaky

@joachimmetz
Copy link
Member

Yes pending completion of CI tests, then I'll merge

@joachimmetz joachimmetz merged commit 12454e4 into log2timeline:master Jun 9, 2018
@jnettesheim jnettesheim deleted the artifact-definitions-filter-helper branch June 9, 2018 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants