コード例 #1
0
    def __init__(
        self,
        paths,
        extensions,
        suffixes=[],
        prefixes=[],
        lowercase=False,
        uppercase=False,
        capitalization=False,
        force_extensions=False,
        exclude_extensions=[],
        no_extension=False,
        only_selected=False,
    ):

        self.entries = ()
        self.current_index = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._exclude_extensions = exclude_extensions
        self._prefixes = prefixes
        self._suffixes = suffixes
        self._paths = paths
        self._force_extensions = force_extensions
        self._no_extension = no_extension
        self._only_selected = only_selected
        self.lowercase = lowercase
        self.uppercase = uppercase
        self.capitalization = capitalization
        self.dictionary_files = [File(path) for path in self.paths]
        self.generate()
コード例 #2
0
ファイル: dictionary.py プロジェクト: src-kun/hunting
 def __init__(self,
              path,
              extensions=None,
              lowercase=False,
              forcedExtensions=False):
     self.entries = []
     self.currentIndex = 0
     self.condition = threading.Lock()
     self._extensions = []
     if extensions:
         if isinstance(extensions, str):
             self._extensions.append(extensions)
         elif isinstance(extensions, list):
             self._extensions = extensions
         else:
             raise Exception('TODO: extensions type error!')
     self._path = path
     self._forcedExtensions = forcedExtensions
     self.lowercase = lowercase
     self.dictionaryFile = File(self.path)
     self.generate()
コード例 #3
0
    def access_file(self, path, name):
        with File(path) as file:
            if not file.exists():
                print("The {} does not exist".format(name))
                exit(1)

            if not file.is_valid():
                print("The {} is invalid".format(name))
                exit(1)

            if not file.can_read():
                print("The {} cannot be read".format(name))
                exit(1)

            return file
コード例 #4
0
ファイル: options.py プロジェクト: O2F/dirsearch
def access_file(path, name):
    with File(path) as fd:
        if not fd.exists():
            print(f"The {name} does not exist")
            exit(1)

        if not fd.is_valid():
            print(f"The {name} is invalid")
            exit(1)

        if not fd.can_read():
            print(f"The {name} cannot be read")
            exit(1)

        return fd
コード例 #5
0
ファイル: raw.py プロジェクト: bbhunter/dirsearch
def parse_raw(raw_file):
    with File(raw_file) as content:
        raw_content = content.read()

    head = raw_content.split(NEW_LINE * 2)[0].splitlines(0)
    method, path = head[0].split()[:2]

    try:
        headers = HeadersParser(head[1:])
        host = headers.get("host").strip()
    except KeyError:
        print("Can't find the Host header in the raw request")
        exit(1)
    except Exception:
        print("Invalid headers in the raw request")
        exit(1)

    try:
        body = raw_content.split(NEW_LINE * 2)[1]
    except IndexError:
        body = None

    return [host + path], method, dict(headers), body
コード例 #6
0
ファイル: dictionary.py プロジェクト: src-kun/hunting
class Dictionary(object):
    def __init__(self,
                 path,
                 extensions=None,
                 lowercase=False,
                 forcedExtensions=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = []
        if extensions:
            if isinstance(extensions, str):
                self._extensions.append(extensions)
            elif isinstance(extensions, list):
                self._extensions = extensions
            else:
                raise Exception('TODO: extensions type error!')
        self._path = path
        self._forcedExtensions = forcedExtensions
        self.lowercase = lowercase
        self.dictionaryFile = File(self.path)
        self.generate()

    @property
    def extensions(self):
        return self._extensions

    @extensions.setter
    def extensions(self, value):
        self._extensions = value

    @property
    def path(self):
        return self._path

    @path.setter
    def path(self, path):
        self._path = path

    @classmethod
    def quote(cls, string):
        return urllib.parse.quote(string, safe=":/~?%&+-=$")

    """
    Dictionary.generate() behaviour

    Classic dirsearch wordlist:
      1. If %EXT% keyword is present, append one with each extension REPLACED.
      2. If the special word is no present, append line unmodified.

    Forced extensions wordlist (NEW):
      This type of wordlist processing is a mix between classic processing
      and DirBuster processing.
          1. If %EXT% keyword is present in the line, immediately process as "classic dirsearch" (1).
          2. If the line does not include the special word AND is NOT terminated by a slash,
            append one with each extension APPENDED (line.ext) and ONLYE ONE with a slash.
          3. If the line does not include the special word and IS ALREADY terminated by slash,
            append line unmodified.
    """

    def generate(self):
        result = []
        for line in self.dictionaryFile.getLines():

            # Skip comments
            if line.lstrip().startswith("#"):
                continue

            # No extensions
            if self._extensions is None:
                result.append(self.quote(line))

            # Classic dirsearch wordlist processing (with %EXT% keyword)
            elif '%EXT%' in line or '%ext%' in line:
                for extension in self._extensions:
                    if '%EXT%' in line:
                        newline = line.replace('%EXT%', extension)

                    if '%ext%' in line:
                        newline = line.replace('%ext%', extension)

                    quote = self.quote(newline)
                    result.append(quote)

            # If forced extensions is used and the path is not a directory ... (terminated by /)
            # process line like a forced extension.
            elif self._forcedExtensions and not line.rstrip().endswith("/"):
                quoted = self.quote(line)

                for extension in self._extensions:
                    # Why? check https://github.com/maurosoria/dirsearch/issues/70
                    if extension.strip() == '':
                        result.append(quoted)
                    else:
                        result.append(quoted + '.' + extension)

                if quoted.strip() not in ['']:
                    result.append(quoted + "/")
            else:
                # Append line unmodified.
                result.append(self.quote(line))

        # oset library provides inserted ordered and unique collection.
        if self.lowercase:
            self.entries = list(oset(map(lambda l: l.lower(), result)))

        else:
            self.entries = list(oset(result))

        del (result)

    def regenerate(self):
        self.generate(lowercase=self.lowercase)
        self.reset()

    def nextWithIndex(self, basePath=None):
        self.condition.acquire()

        try:
            result = self.entries[self.currentIndex]

        except IndexError:
            self.condition.release()
            raise StopIteration

        self.currentIndex = self.currentIndex + 1
        currentIndex = self.currentIndex
        self.condition.release()
        return currentIndex, result

    def __next__(self, basePath=None):
        _, path = self.nextWithIndex(basePath)
        return path

    def reset(self):
        self.condition.acquire()
        self.currentIndex = 0
        self.condition.release()

    def __len__(self):
        return len(self.entries)
コード例 #7
0
    def __init__(self, raw_file, scheme):
        with File(raw_file) as raw_content:
            self.raw_content = raw_content.read()

        self.scheme = scheme
        self.parse()