def _get_path_disclosure_strings(self): ''' Return a list of regular expressions to be tested. ''' path_disclosure_strings = [] #path_disclosure_strings.append(r"file:///?[A-Z]\|") path_disclosure_strings.extend( get_common_directories() ) return path_disclosure_strings
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 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 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'))