Trees | Indices | Help |
|
---|
|
1 import os 2 import mock 3 4 from rekall import testlib 5 from rekall import utils 6 from rekall.plugins.response import common 7 from rekall.plugins.response import files 8 911 """Test file operations.""" 1283 84 85 if __name__ == "__main__": 86 testlib.main() 8714 """Check to ensure the components are created properly.""" 15 glob_plugin = files.IRGlob(session=self.session) 16 path_components = glob_plugin.convert_glob_into_path_components( 17 "/usr/*/ls") 18 self.assertListEqual([str(x) for x in path_components], 19 ["LiteralComponent:usr", 20 "RegexComponent:.*\Z(?ms)", 21 "LiteralComponent:ls"]) 22 23 glob_plugin = files.IRGlob(session=self.session, path_sep="\\") 24 path_components = glob_plugin.convert_glob_into_path_components( 25 "c:\\windows\\**\*.exe") 26 self.assertListEqual([str(x) for x in path_components], 27 ["LiteralComponent:c:", 28 "LiteralComponent:windows", 29 "RecursiveComponent:.*\Z(?ms)", 30 "RegexComponent:.*\\.exe\\Z(?ms)"])3133 self.component_cache = utils.FastStore(50) 34 literal = files.LiteralComponent(session=self.session, 35 cache=self.component_cache, 36 component="passwd") 37 38 path_spec = common.FileSpec("/etc") 39 result = list(literal.filter(path_spec)) 40 self.assertTrue("/etc/passwd" in [unicode(x) for x in result]) 41 42 regex = files.RegexComponent(session=self.session, 43 cache=self.component_cache, 44 component="pass.+") 45 46 result = list(regex.filter(path_spec)) 47 self.assertTrue("/etc/passwd" in [unicode(x) for x in result]) 48 49 recursive = files.RecursiveComponent(session=self.session, 50 cache=self.component_cache, 51 component=".+") 52 53 result = list(recursive.filter(path_spec)) 54 self.assertTrue("/etc/ssh/ssh_config" in [unicode(x) for x in result])55 5961 self._touch(os.path.join(self.temp_directory, "boo.txt")) 62 os.makedirs(os.path.join(self.temp_directory, "foo")) 63 self._touch(os.path.join(self.temp_directory, "foo/boo2.txt")) 64 65 # Drop a symlink to / - if we follow links this will crash. 66 os.symlink("/", os.path.join(self.temp_directory, "link"))6769 self._make_temp_directory() 70 glob_plugin = files.IRGlob(session=self.session, globs=[ 71 self.temp_directory + "/*.txt"]) 72 result = list(glob_plugin.collect()) 73 self.assertTrue("boo.txt" in [os.path.basename(unicode(x["path"].filename)) 74 for x in result]) 75 self.assertEqual(len(result), 1) 76 77 glob_plugin = files.IRGlob(session=self.session, globs=[ 78 self.temp_directory + "/**/*.txt"]) 79 result = list(glob_plugin.collect()) 80 paths = [os.path.basename(unicode(x["path"].filename)) 81 for x in result] 82 self.assertEqual(["boo.txt", "boo2.txt"], paths)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Oct 9 03:29:47 2017 | http://epydoc.sourceforge.net |