def __init__(self): GrepPlugin.__init__(self) # Internal variables self._reported = DiskList(table_prefix='path_disclosure') # Compile all regular expressions and store information to avoid # multiple queries to the same function self._common_directories = get_common_directories() self._compiled_regexes = {} self._compile_regex()
def __init__(self): GrepPlugin.__init__(self) # Internal variables self._already_added = DiskList() # Compile all regular expressions and store information to avoid # multiple queries to the same function self._common_directories = get_common_directories() self._compiled_regexes = {} self._compile_regex()
def setup(self): """ :return: None, the result is saved in self._path_disc_regex_list """ if self._signature_re is not None: return all_signatures = [] for path_disclosure_string in get_common_directories(): regex_string = '(%s.*?)[^A-Za-z0-9\._\-\\/\+~]' regex_string = regex_string % path_disclosure_string all_signatures.append(regex_string) self._signature_re = MultiRE(all_signatures, hint_len=1)
def setup(self): """ :return: None, the result is saved in self._path_disc_regex_list """ if self._signature_re is not None: return all_signatures = [] for path_disclosure_string in get_common_directories(): regex_string = '(%s.*?)[^A-Za-z0-9\._\-\\/\+~]' regex_string = regex_string % path_disclosure_string all_signatures.append(regex_string) self._signature_re = multi_re(all_signatures, hint_len=1)
def extract_files_from_file(filename, file_content): """ :param filename: The filename to request to the remote end and parse :param file_content: The content of the file to analyze :return: A list of files referenced in "filename" """ # Compile regular_expressions = [] for common_dirs in get_common_directories(): regex_string = '(' + common_dirs + \ '.*?)[:| |\0|\'|"|<|\n|\r|\t]' regex = re.compile(regex_string, re.IGNORECASE) regular_expressions.append(regex) # And use result = [] for regex in regular_expressions: result.extend(regex.findall(file_content)) # uniq result = list(set(result)) return result
def test_linux(self): self.assertIn('/etc/', get_common_directories('linux'))
def test_windows(self): self.assertIn('C:\\\\', get_common_directories('windows'))