def test_find(self): policy = Policy.parse(cStringIO.StringIO(self._TEST_POLICY), "json") self.assertTrue(policy) symbol_mapping_cache = self.MockSymbolMappingCache() symbol_mapping_cache.add(FUNCTION_SYMBOLS, 0x1212, "v8::create") symbol_mapping_cache.add(FUNCTION_SYMBOLS, 0x1381, "WebKit::create") bucket1 = Bucket([0x1212, 0x013], "malloc", 0x29492, "_Z") bucket1.symbolize(symbol_mapping_cache) bucket2 = Bucket([0x18242, 0x1381], "malloc", 0x9492, "_Z") bucket2.symbolize(symbol_mapping_cache) bucket3 = Bucket([0x18242, 0x181], "malloc", 0x949, "_Z") bucket3.symbolize(symbol_mapping_cache) self.assertEqual("malloc-v8", policy.find_malloc(bucket1)) self.assertEqual("malloc-WebKit", policy.find_malloc(bucket2)) self.assertEqual("malloc-catch-all", policy.find_malloc(bucket3))
def test_find(self): policy = Policy.parse(cStringIO.StringIO(self._TEST_POLICY), 'json') self.assertTrue(policy) symbol_mapping_cache = self.MockSymbolMappingCache() symbol_mapping_cache.add(FUNCTION_SYMBOLS, 0x1212, 'v8::create') symbol_mapping_cache.add(FUNCTION_SYMBOLS, 0x1381, 'WebKit::create') bucket1 = Bucket([0x1212, 0x013], 'malloc', 0x29492, '_Z') bucket1.symbolize(symbol_mapping_cache) bucket2 = Bucket([0x18242, 0x1381], 'malloc', 0x9492, '_Z') bucket2.symbolize(symbol_mapping_cache) bucket3 = Bucket([0x18242, 0x181], 'malloc', 0x949, '_Z') bucket3.symbolize(symbol_mapping_cache) self.assertEqual('malloc-v8', policy.find_malloc(bucket1)) self.assertEqual('malloc-WebKit', policy.find_malloc(bucket2)) self.assertEqual('malloc-catch-all', policy.find_malloc(bucket3))
def read(self): try: users_fd = open(self.users_file, "r") policies_fd = open(self.policies_file, "r") except IOError as e: self.log(e, "E") return False for line in users_fd.readlines(): if line.strip().encode() == b"": continue # empty line l = line.strip().encode().split(b"#")[0].strip().split(b":") # TODO: move this check somewhere else if len(l) > 2: self.log("More than one ':' while parsing users file?", "E") return False if b"group" in l[0][0:5]: self.key_manager.add_group(l[0].split(b" ")[1]) for u in l[1].strip().split(b" "): self.key_manager.add_group_member(u, l[0].split(b" ")[1]) else: self.key_manager.add_user(l[0].strip(), l[1].strip()) users_fd.close() cnt = 0 for line in policies_fd.readlines(): if line.strip().encode() == b"": continue # empty line cnt += 1 tokens = line.strip().encode().split(b"#")[0].split(b" ") policy = Policy() policy.parameters = [] prev_token = None for token in tokens: if prev_token == b'-u': policy.user = token elif prev_token == b'-g': policy.group = token elif prev_token == b'-p': policy.parameters.append(token) prev_token = token policy.script = tokens[-1] if not self.policy_manager.add_policy(policy): self.log( " File %s line %d" % (cfg["path_to_policies"], cnt), "E") return False policies_fd.close() return True
def test_load(self): policy = Policy.parse(cStringIO.StringIO(self._TEST_POLICY), "json") self.assertTrue(policy) self.assertEqual("POLICY_DEEP_3", policy.version)
def test_load(self): policy = Policy.parse(cStringIO.StringIO(self._TEST_POLICY), 'json') self.assertTrue(policy) self.assertEqual('POLICY_DEEP_3', policy.version)