Exemple #1
0
class Dictionary(object):

    def __init__(self, path, extensions, lowercase=False, forcedExtensions=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        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

            # Classic dirsearch wordlist processing (with %EXT% keyword)
            if '%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 + "/")

            # Append line unmodified.
            else:
                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)
class FuzzerDictionary(object):

    def __init__(self, path, extensions, lowercase=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._path = path
        self.lowercase = lowercase
        self.dictionaryFile = File(self.path)
        self.generate(lowercase=self.lowercase)


    @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

    def generate(self, lowercase=False):
        self.entries = []
        for line in self.dictionaryFile.getLines():
            # Skip comments
            entry = line
            if line.startswith("#"): continue

            for extension in self._extensions:
                entry = line + extension
                self.entries.append(urllib.parse.quote(entry))

        if lowercase == True:
            self.entries = list(oset([entry.lower() for entry in self.entries]))

    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)
class Dictionary(object):
    def __init__(self,
                 path,
                 extensions,
                 lowercase=False,
                 forcedExtensions=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        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

            # Classic dirsearch wordlist processing (with %EXT% keyword)
            if '%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 + "/")

            # Append line unmodified.
            else:
                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)
Exemple #4
0
class Dictionary(object):

    def __init__(self, path, extensions, lowercase=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._path = path
        self.lowercase = lowercase
        self.dictionaryFile = File(self.path)
        self.generate(lowercase=self.lowercase)


    @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=":/~?%&+-=$")

    def generate(self, lowercase=False):
        self.entries = []
        for line in self.dictionaryFile.getLines():
            # Skip comments
            entry = line
            if line.lstrip().startswith("#"): continue
            if '%EXT%' in line:
                for extension in self._extensions:
                    self.entries.append(self.quote(line.replace('%EXT%', extension)))
            else:
                quote = self.quote(line)
                self.entries.append(quote)
        if lowercase == True:
            self.entries = list(oset([entry.lower() for entry in self.entries]))

    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)
Exemple #5
0
class FuzzerDictionary(object):
    def __init__(self, path, extensions, lowercase=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._path = path
        self.lowercase = lowercase
        self.dictionaryFile = File(self.path)
        self.generate(lowercase=self.lowercase)

    @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

    def generate(self, lowercase=False):
        self.entries = []
        for line in self.dictionaryFile.getLines():
            # Skip comments
            entry = line
            if line.startswith("#"): continue
            if '%EXT%' in line:
                for extension in self._extensions:
                    self.entries.append(
                        urllib.parse.quote(line.replace('%EXT%', extension)))
            else:
                self.entries.append(urllib.parse.quote(line))
        if lowercase == True:
            self.entries = list(oset([entry.lower()
                                      for entry in self.entries]))

    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)
Exemple #6
0
class Dictionary(object):
    def __init__(self,
                 path,
                 extensions,
                 lowercase=False,
                 forcedExtensions=False,
                 recursive=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._path = path
        self._forcedExtensions = forcedExtensions
        self.lowercase = lowercase
        self.recursive = recursive
        self.dictionaryFile = File(self.path)
        self.generate(lowercase=self.lowercase)

    @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=":/~?%&+-=$")

    def generate(self, lowercase=False):
        self.entries = []
        for line in self.dictionaryFile.getLines():
            # Skip comments
            entry = line
            if line.lstrip().startswith("#"): continue
            if self.recursive:
                if '%EXT%/' in line: continue
                pattern = re.compile(r'.+?\.(php|asp|aspx|jsp)/')
                if pattern.match(line): continue
            if '%EXT%' in line:
                for extension in self._extensions:
                    self.entries.append(
                        self.quote(line.replace('%EXT%', extension)))
            else:
                if self._forcedExtensions:
                    for extension in self._extensions:
                        self.entries.append(self.quote(line) + '.' + extension)
                quote = self.quote(line)
                self.entries.append(quote)
        if lowercase == True:
            self.entries = list(oset([entry.lower()
                                      for entry in self.entries]))

    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)
Exemple #7
0
class Dictionary(object):

    def __init__(self, url, path, extensions, lowercase=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._path = path
        self.url = url[0]
        self.lowercase = lowercase
        self.dictionaryFile = File(self.path)
        self.generate(lowercase=self.lowercase)


    @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=":/~?%&+-=$")

    def generate(self, lowercase=False):
        self.entries = []
        target = self.url
        hostuser = target.split('.')
        mainhost = hostuser[len(hostuser)-2]
        subhost = hostuser[len(hostuser)-3]
        #print(mainhost+':'+subhost)
        bak =  ['/'+mainhost+'.rar','/'+mainhost+'.zip','/'+mainhost+mainhost+'.rar','/'+mainhost+'.rar','/'+mainhost+'.tar.gz','/'+mainhost+'.tar','/'+mainhost+'123.zip','/'+mainhost+'123.tar.gz','/'+mainhost+mainhost+'.zip','/'+mainhost+mainhost+'.tar.gz','/'+mainhost+mainhost+'.tar','/'+mainhost+'.bak']
        bak1 =  ['/'+subhost+'.rar','/'+subhost+'.zip','/'+subhost+subhost+'.rar','/'+subhost+'.rar','/'+subhost+'.tar.gz','/'+subhost+'.tar','/'+subhost+'123.zip','/'+subhost+'123.tar.gz','/'+subhost+subhost+'.zip','/'+subhost+subhost+'.tar.gz','/'+subhost+subhost+'.tar','/'+subhost+'.bak']
        baks = bak+bak1
        #print(baks)
        self.entries = self.entries+baks
        for line in self.dictionaryFile.getLines():
            # Skip comments
            entry = line
            if line.lstrip().startswith("#"): continue
            if '%EXT%' in line:
                for extension in self._extensions:
                    self.entries.append(self.quote(line.replace('%EXT%', extension)))
            else:
                quote = self.quote(line)
                self.entries.append(quote)
                #print(self.entries)
        if lowercase == True:
            self.entries = list(oset([entry.lower() for entry in self.entries]))

    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)
Exemple #8
0
class Dictionary(object):
    def __init__(self, url, path, extensions, lowercase=False):
        self.entries = []
        self.currentIndex = 0
        self.condition = threading.Lock()
        self._extensions = extensions
        self._path = path
        self.url = url[0]
        self.lowercase = lowercase
        self.dictionaryFile = File(self.path)
        self.generate(lowercase=self.lowercase)

    @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=":/~?%&+-=$")

    def generate(self, lowercase=False):
        self.entries = []
        target = self.url
        hostuser = target.split('.')
        mainhost = hostuser[len(hostuser) - 2]
        subhost = hostuser[len(hostuser) - 3]
        #print(mainhost+':'+subhost)
        bak = [
            '/' + mainhost + '.rar', '/' + mainhost + '.zip',
            '/' + mainhost + mainhost + '.rar', '/' + mainhost + '.rar',
            '/' + mainhost + '.tar.gz', '/' + mainhost + '.tar',
            '/' + mainhost + '123.zip', '/' + mainhost + '123.tar.gz',
            '/' + mainhost + mainhost + '.zip',
            '/' + mainhost + mainhost + '.tar.gz',
            '/' + mainhost + mainhost + '.tar', '/' + mainhost + '.bak'
        ]
        bak1 = [
            '/' + subhost + '.rar', '/' + subhost + '.zip',
            '/' + subhost + subhost + '.rar', '/' + subhost + '.rar',
            '/' + subhost + '.tar.gz', '/' + subhost + '.tar',
            '/' + subhost + '123.zip', '/' + subhost + '123.tar.gz',
            '/' + subhost + subhost + '.zip',
            '/' + subhost + subhost + '.tar.gz',
            '/' + subhost + subhost + '.tar', '/' + subhost + '.bak'
        ]
        baks = bak + bak1
        #print(baks)
        self.entries = self.entries + baks
        for line in self.dictionaryFile.getLines():
            # Skip comments
            entry = line
            if line.lstrip().startswith("#"): continue
            if '%EXT%' in line:
                for extension in self._extensions:
                    self.entries.append(
                        self.quote(line.replace('%EXT%', extension)))
            else:
                quote = self.quote(line)
                self.entries.append(quote)
                #print(self.entries)
        if lowercase == True:
            self.entries = list(oset([entry.lower()
                                      for entry in self.entries]))

    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)