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()
def __init__( self, paths, extensions, suffixes=None, prefixes=None, lowercase=False, uppercase=False, capitalization=False, forcedExtensions=False, noDotExtensions=False, excludeExtensions=[], noExtension=False, ): self.entries = [] self.currentIndex = 0 self.condition = threading.Lock() self._extensions = extensions self._excludeExtensions = excludeExtensions self._prefixes = prefixes self._suffixes = suffixes self._paths = paths self._forcedExtensions = forcedExtensions self._noDotExtensions = noDotExtensions self._noExtension = noExtension self.lowercase = lowercase self.uppercase = uppercase self.capitalization = capitalization self.dictionaryFiles = [File(path) for path in self.paths] self.generate()
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)
def __init__(self, script_path): self.script_path = script_path self.parseConfig() options = self.parseArguments() if options.url == None: if options.urlList != None: with File(options.urlList) as urlList: if not urlList.exists(): print("The file with URLs does not exist") exit(0)
def __init__(self, paths, directory, filename, extension, extensions=[], lowercase=False, forcedExtensions=False): self.entries = [] self.directory = directory self.filename = filename self.extension = extension self.currentIndex = 0 self.condition = threading.Lock() self._extensions = extensions self._paths = paths self._forcedExtensions = forcedExtensions self.lowercase = lowercase self.dictionaryFiles = [File(path) for path in self.paths] self.generate()
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)
def __init__(self, script_path): self.script_path = script_path self.parseConfig() options = self.parseArguments() if options.url == None: if options.urlList != None: with File(options.urlList) as urlList: if not urlList.exists(): print("The file with URLs does not exist") exit(0) if not urlList.isValid(): print('The wordlist is invalid') exit(0) if not urlList.canRead(): print('The wordlist cannot be read') exit(0) self.urlList = list(urlList.getLines()) elif options.url == None: print('URL target is missing, try using -u <url> ') exit(0) else: self.urlList = [options.url] if options.extensions == None: print( 'No extension specified. You must specify at least one extension' ) exit(0) with File(options.wordlist) as wordlist: if not wordlist.exists(): print('The wordlist file does not exist') exit(0) if not wordlist.isValid(): print('The wordlist is invalid') exit(0) if not wordlist.canRead(): print('The wordlist cannot be read') exit(0) if options.httpProxy is not None: if options.httpProxy.startswith('http://'): self.proxy = options.httpProxy else: self.proxy = 'http://{0}'.format(options.httpProxy) else: self.proxy = None if options.headers is not None: try: self.headers = dict( (key.strip(), value.strip()) for (key, value) in (header.split(':', 1) for header in options.headers)) except Exception as e: print('Invalid headers') exit(0) else: self.headers = {} self.extensions = list( oset([ extension.strip() for extension in options.extensions.split(',') ])) self.useragent = options.useragent self.useRandomAgents = options.useRandomAgents self.cookie = options.cookie if options.threadsCount < 1: print('Threads number must be a number greater than zero') exit(0) self.threadsCount = options.threadsCount if options.excludeStatusCodes is not None: try: self.excludeStatusCodes = list( oset([ int(excludeStatusCode.strip()) if excludeStatusCode else None for excludeStatusCode in options.excludeStatusCodes.split(',') ])) except ValueError: self.excludeStatusCodes = [] else: self.excludeStatusCodes = [] self.wordlist = options.wordlist self.lowercase = options.lowercase self.forceExtensions = options.forceExtensions self.simpleOutputFile = options.simpleOutputFile self.plainTextOutputFile = options.plainTextOutputFile self.jsonOutputFile = options.jsonOutputFile self.delay = options.delay self.timeout = options.timeout self.ip = options.ip self.maxRetries = options.maxRetries self.recursive = options.recursive self.suppressEmpty = options.suppressEmpty if options.scanSubdirs is not None: self.scanSubdirs = list( oset([ subdir.strip() for subdir in options.scanSubdirs.split(',') ])) for i in range(len(self.scanSubdirs)): while self.scanSubdirs[i].startswith("/"): self.scanSubdirs[i] = self.scanSubdirs[i][1:] while self.scanSubdirs[i].endswith("/"): self.scanSubdirs[i] = self.scanSubdirs[i][:-1] self.scanSubdirs = list( oset([subdir + "/" for subdir in self.scanSubdirs])) else: self.scanSubdirs = None if not self.recursive and options.excludeSubdirs is not None: print( '--exclude-subdir argument can only be used with -r|--recursive' ) exit(0) elif options.excludeSubdirs is not None: self.excludeSubdirs = list( oset([ subdir.strip() for subdir in options.excludeSubdirs.split(',') ])) for i in range(len(self.excludeSubdirs)): while self.excludeSubdirs[i].startswith("/"): self.excludeSubdirs[i] = self.excludeSubdirs[i][1:] while self.excludeSubdirs[i].endswith("/"): self.excludeSubdirs[i] = self.excludeSubdirs[i][:-1] self.excludeSubdirs = list(oset(self.excludeSubdirs)) else: self.excludeSubdirs = None self.redirect = options.noFollowRedirects self.requestByHostname = options.requestByHostname
def __init__(self, script_path): self.script_path = script_path self.parseConfig() options = self.parseArguments() self.clean_view = options.clean_view self.full_url = options.full_url if options.url == None: if options.urlList != None: with File(options.urlList) as urlList: if not urlList.exists(): print("The file with URLs does not exist") exit(0) if not urlList.isValid(): print("The file with URLs is invalid") exit(0) if not urlList.canRead(): print("The file with URLs cannot be read") exit(0) self.urlList = list(urlList.getLines()) elif options.url == None: print("URL target is missing, try using -u <url> ") exit(0) else: self.urlList = [options.url] if not options.extensions and not options.defaultExtensions: print('No extension specified. You must specify at least one extension or try using default extension list.') exit(0) if not options.extensions and options.defaultExtensions: options.extensions = self.defaultExtensions # Enable to use multiple dictionaries at once for dictFile in options.wordlist.split(','): with File(dictFile) as wordlist: if not wordlist.exists(): print('The wordlist file does not exist') exit(1) if not wordlist.isValid(): print('The wordlist is invalid') exit(1) if not wordlist.canRead(): print('The wordlist cannot be read') exit(1) if options.proxyList is not None: with File(options.proxyList) as plist: if not plist.exists(): print('The proxylist file does not exist') exit(1) if not plist.isValid(): print('The proxylist is invalid') exit(1) if not plist.canRead(): print('The proxylist cannot be read') exit(1) self.proxylist = open(options.proxyList).read().splitlines() elif options.httpProxy is not None: if options.httpProxy.startswith("http://"): self.proxy = options.httpProxy else: self.proxy = "http://{0}".format(options.httpProxy) else: self.proxy = None if options.headers is not None: try: self.headers = dict( (key.strip(), value.strip()) for (key, value) in ( header.split(":", 1) for header in options.headers ) ) except Exception as e: print("Invalid headers") exit(0) else: self.headers = {} self.extensions = list( oset([extension.strip() for extension in options.extensions.split(",")]) ) self.useragent = options.useragent self.useRandomAgents = options.useRandomAgents self.cookie = options.cookie if options.threadsCount < 1: print('Threads number must be a number greater than zero') exit(1) self.threadsCount = options.threadsCount if options.includeStatusCodes: try: self.includeStatusCodes = list( oset([int(includeStatusCode.strip()) if includeStatusCode else None for includeStatusCode in options.includeStatusCodes.split(',')])) except ValueError: self.includeStatusCodes = [] else: self.includeStatusCodes = [] if options.excludeExtensions: try: self.excludeExtensions = list( oset( [ excludeExtension.strip() if excludeExtension else None for excludeExtension in options.excludeExtensions.split(",") ] ) ) except ValueError: self.excludeExtensions = [] else: self.excludeExtensions = [] if options.excludeStatusCodes: try: self.excludeStatusCodes = list( oset( [ int(excludeStatusCode.strip()) if excludeStatusCode else None for excludeStatusCode in options.excludeStatusCodes.split( "," ) ] ) ) except ValueError: self.excludeStatusCodes = [] else: self.excludeStatusCodes = [] if options.excludeTexts: try: self.excludeTexts = list( oset( [ excludeTexts.strip() if excludeTexts else None for excludeTexts in options.excludeTexts.split(",") ] ) ) except ValueError: self.excludeTexts = [] else: self.excludeTexts = [] if options.excludeRegexps: try: self.excludeRegexps = list( oset( [ excludeRegexps.strip() if excludeRegexps else None for excludeRegexps in options.excludeRegexps.split(",") ] ) ) except ValueError: self.excludeRegexps = [] else: self.excludeRegexps = [] self.suffixes = [] if not options.suffixes else list(oset([suffix.strip() for suffix in options.suffixes.split(',')])) self.wordlist = list(oset([wordlist.strip() for wordlist in options.wordlist.split(',')])) self.lowercase = options.lowercase self.uppercase = options.uppercase self.forceExtensions = options.forceExtensions self.data = options.data self.noDotExtensions = options.noDotExtensions self.simpleOutputFile = options.simpleOutputFile self.plainTextOutputFile = options.plainTextOutputFile self.jsonOutputFile = options.jsonOutputFile self.quietMode = options.quietMode self.delay = options.delay self.timeout = options.timeout self.ip = options.ip self.maxRetries = options.maxRetries self.recursive = options.recursive self.suppressEmpty = options.suppressEmpty self.minimumResponseSize = options.minimumResponseSize self.maximumResponseSize = options.maximumResponseSize if options.scanSubdirs is not None: self.scanSubdirs = list( oset([subdir.strip() for subdir in options.scanSubdirs.split(",")]) ) for i in range(len(self.scanSubdirs)): while self.scanSubdirs[i].startswith("/"): self.scanSubdirs[i] = self.scanSubdirs[i][1:] while self.scanSubdirs[i].endswith("/"): self.scanSubdirs[i] = self.scanSubdirs[i][:-1] self.scanSubdirs = list(oset([subdir + "/" for subdir in self.scanSubdirs])) else: self.scanSubdirs = None if not self.recursive and options.excludeSubdirs is not None: print("--exclude-subdir argument can only be used with -r|--recursive") exit(0) elif options.excludeSubdirs is not None: self.excludeSubdirs = list( oset([subdir.strip() for subdir in options.excludeSubdirs.split(",")]) ) for i in range(len(self.excludeSubdirs)): while self.excludeSubdirs[i].startswith("/"): self.excludeSubdirs[i] = self.excludeSubdirs[i][1:] while self.excludeSubdirs[i].endswith("/"): self.excludeSubdirs[i] = self.excludeSubdirs[i][:-1] self.excludeSubdirs = list(oset(self.excludeSubdirs)) else: self.excludeSubdirs = None if len(set(self.extensions).intersection(self.excludeExtensions)): print("Exclude extensions can not contain any extension that already in the extensions") exit(0) self.redirect = options.noFollowRedirects self.requestByHostname = options.requestByHostname self.httpmethod = options.httpmethod self.recursive_level_max = options.recursive_level_max
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)
def __init__(self, script_path): self.script_path = script_path self.parse_config() options = self.parse_arguments() self.debug = options.debug # Parse Target URL if options.url is None: if options.url_list is not None: with File(options.url_list) as url_list: if not url_list.is_valid(): print("The file with URLs does not exist") exit(0) if not url_list.is_readable(): print('The file with URLs cannot be read') exit(0) self.urlList = list(url_list.get_lines()) elif options.url == None: print('URL target is missing, try using -u <url> ') exit(0) else: self.url_list = [options.url] # Parse connection settings # Proxy if options.http_proxy is not None: if options.http_proxy.startswith('http://'): self.proxy = options.http_proxy else: self.proxy = 'http://{0}'.format(options.http_proxy) else: self.proxy = None # Headers if options.headers is not None: try: self.headers = dict( (key.strip(), value.strip()) for (key, value) in (header.split(':', 1) for header in options.headers)) except Exception as e: print('Invalid headers') exit(1) else: self.headers = {} self.useragent = options.useragent self.use_random_agents = options.use_random_agents self.cookie = options.cookie if options.threads_count < 1: print('Threads number must be a number greater than zero') exit(0) self.threads_count = options.threads_count self.delay = options.delay self.timeout = options.timeout self.max_retries = options.max_retries self.redirect = options.no_follow_redirects if (options.dns_cache and options.ip_addr) or (self.dns_cache and options.dns_cache): print("DNS Cache and IP address cannot be used together.") exit(0) self.dns_cache = options.dns_cache self.ip_addr = options.ip_addr # Parse usernames argument self.usernames = [ username.strip() for username in options.usernames.split(',') ] # Parse Wordlist Settings dict_args = { 'Usernames Wordlist': 'username_wordlist', 'Passwords Wordlist': 'userpass_wordlist', 'UserPass Combo Wordlist': 'userpass_wordlist' } for wordlist_label, wordlist_var in dict_args.items(): if len(getattr(options, wordlist_var)) == 0: setattr(self, wordlist_var, []) try: stripped_values = [ value.strip() for value in getattr(options, wordlist_var) ] setattr(self, wordlist_var, stripped_values) except: print('{0} Unhandled error'.format(wordlist_label)) exit(1) for f in getattr(self, wordlist_var): with File(f) as wordlist: if not wordlist.is_valid(): print('The {0} file does not exist'.format( wordlist_label)) exit(1) if not wordlist.is_readable(): print('The {0} file cannot be read'.format( wordlist_label)) exit(1) self.userpass_wordlist_separator = options.userpass_wordlist_separator
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)
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)
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)
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)
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)