WordListGenerator (version 0.1.0)
index
WordListGenerator.py

This package builds custom WordLists (for BruteForce).
 
>>> from io import BytesIO, StringIO
>>> wordlist = WordList(
...     {
...         "%(123)": PatternEnumerator("123", "123", False, None),
...         "%(aAbBc)": PatternEnumerator("aAbBc", "A[a-c]B", False, None),
...         "%(words)": PatternEnumerator("words", "(word1|word2)", False, None),
...         "%(file)": PatternEnumerator("file", None, True, "test.txt"),
...     },
...     max_words=5
... )
>>> wordlist.output = StringIO()
>>> wordlist.output.close = lambda: None
>>> wordlist.patterns["%(123)"].build_chars()
>>> wordlist.patterns["%(aAbBc)"].build_chars()
>>> wordlist.patterns["%(words)"].build_chars()
>>> wordlist.patterns["%(file)"].build_chars()
>>> wordlist.run("A%(aAbBc)B%(file)C%(num)%(words)D")
>>> len(wordlist.output.getvalue().split())
5
>>> 
 
~# python3.11 WordListGenerator.py -e "a=[1-3]" -p 'ABC%(a){2}'
ABC22
ABC23
ABC21
ABC32
ABC33
ABC31
ABC12
ABC13
ABC11
~# python3.11 WordListGenerator.py -w "b=test.txt" -e "123" -p '%(b)%(123)'
abcc13
abcc11
abcc12
abcc33
abcc31
abcc32
abcc23
abcc21
abcc22
abcb13
abcb11
abcb12
abcb33
abcb31
abcb32
~# python3.11 WordListGenerator.py -w "b=test.txt" -e "a=123" -t 0.0004 -p '%(b)%(a)'
abcc11
abcc12
abcc13
abcc31
abcc32
abcc33
abcc21
abcc22
abcc23
abcb11
abcb12
abcb13
abcb31
abcb32
abcb33
~# python3.11 WordListGenerator.py -w "b=test.txt" -e "a=123" -m 5 -p '%(b)%(a)'
abcc13
abcc12
abcc11
abcc33
abcc32
~# python3.11 WordListGenerator.py -w "b=test.txt" -e "123" -m 5 -p '%(b)%(123)' -E ascii -f "abc.txt"
~# python3.11 WordListGenerator.py -e "123" -p 'ABC%(123)' -E ascii -d ","
ABC3,ABC1,ABC2,
~#
 
Tests:
~# python3 -m doctest -v WordListGenerator.py
40 tests in 16 items.
40 passed and 0 failed.
Test passed.

 
Modules
       
posixpath

 
Classes
       
builtins.object
PatternEnumerator
WordList

 
class PatternEnumerator(builtins.object)
    PatternEnumerator(name: str, chars: str, is_file: bool, filename: str) -> None
 
This class is a strings generator.
 
  Methods defined here:
__eq__(self, other)
Return self==value.
__init__(self, name: str, chars: str, is_file: bool, filename: str) -> None
Initialize self.  See help(type(self)) for accurate signature.
__repr__(self)
Return repr(self).
build_chars(self)
This function builds string from pattern.
 
>>> p = PatternEnumerator("1", "a[1-3]B", False, None)
>>> p.build_chars()
>>> len(p.chars)
5
>>> p = PatternEnumerator("1", "B[3-1]a", False, None)
>>> p.build_chars()
>>> len(p.chars)
5
>>> p = PatternEnumerator("1", None, True, "filename.txt")
>>> p.build_chars()
>>> p.chars
get_values(self, encoding: str = 'utf-8', delimiter: str = '\n')
This generator returns values from pattern.
 
>>> p = PatternEnumerator("1", {'1', '2'}, False, None)
>>> print(*sorted(p.get_values()))
1 2
>>> p = PatternEnumerator("file", None, True, "test.txt")
>>> list_ = list(p.get_values()); print(list_[0])
abcc1
>>> len(list_)
5
>>>
get_word_from_file(self, file: _io.TextIOWrapper, delimiter: str = '\n')
This function returns word from custom WordList.
 
>>> from io import BytesIO
>>> a = TextIOWrapper(BytesIO(b'abc\n123\ntest'))
>>> p = PatternEnumerator("1", None, True, "filename.txt")
>>> w=True
>>> while w: print(w:=p.get_word_from_file(a))
abc
123
test
<BLANKLINE>
>>>

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'chars': <class 'str'>, 'filename': <class 'str'>, 'is_file': <class 'bool'>, 'name': <class 'str'>}
__dataclass_fields__ = {'chars': Field(name='chars',type=<class 'str'>,default=<d...appingproxy({}),kw_only=False,_field_type=_FIELD), 'filename': Field(name='filename',type=<class 'str'>,default...appingproxy({}),kw_only=False,_field_type=_FIELD), 'is_file': Field(name='is_file',type=<class 'bool'>,default...appingproxy({}),kw_only=False,_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default=<da...appingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
__match_args__ = ('name', 'chars', 'is_file', 'filename')

 
class WordList(builtins.object)
    WordList(patterns: dict, filename: str = None, delimiter: str = '\n', max_words: int = None, max_time: float = None, encoding: str = 'utf-8')
 
This class build custom WordList.
 
>>> w = WordList({"%(1)": PatternEnumerator("1", {"1"}, False, None)})
>>> w.run('AB%(1)')
AB1
>>>
 
  Methods defined here:
__init__(self, patterns: dict, filename: str = None, delimiter: str = '\n', max_words: int = None, max_time: float = None, encoding: str = 'utf-8')
Initialize self.  See help(type(self)) for accurate signature.
launch_pattern_loop(self, string: str, pattern: str) -> None
This function replaces PatternEnumerator
and generates strings from pattern.
 
>>> w = WordList({"%(1)": PatternEnumerator("1", ["1", "2"], False, None)})
>>> for word in w.visit_pattern('AB%(1)'): print(word)
AB1
AB2
>>>
run(self, string: str) -> None
This function create wordlist.
 
>>> w = WordList({"%(1)": PatternEnumerator("1", ["1", "2"], False, None)}, max_words=1)
>>> w.run('AB%(1)')
AB1
>>> w = WordList({"%(1)": PatternEnumerator("1", ["1", "2"], False, None)}, max_time=0)
>>> w.run('AB%(1)')
AB1
>>> w.run('AB%(1){2}')
AB11
>>>
visit_pattern(self, string: str) -> ~StringOrNone
This function find first pattern in a string.
 
>>> w = WordList({"%(1)": PatternEnumerator("1", ["1", "2"], False, None)})
>>> for word in w.visit_pattern('AB%(1)'): print(word)
AB1
AB2
>>>

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Data
        __all__ = ['PatternEnumerator', 'WordList']
__author_email__ = 'mauricelambert434@gmail.com'
__copyright__ = '\nWordListGenerator Copyright (C) 2021, 2022 Ma...ome to redistribute it\nunder certain conditions.\n'
__description__ = 'This package builds custom WordLists (for BruteForce).'
__maintainer__ = 'Maurice Lambert'
__maintainer_email__ = 'mauricelambert434@gmail.com'
__url__ = 'https://github.com/mauricelambert/WordListGenerator'

 
Author
        Maurice Lambert