Skip to content

Commit

Permalink
core: bake fetch into search and list positional parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeviousStoat authored Mar 28, 2021
1 parent 3ad41ce commit 4c1ea3e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ optional arguments:
-b BASEDIR, --base-dir BASEDIR
wordlists base directory [default: /usr/share/wordlists]
-f INDEX [INDEX ...], --fetch INDEX [INDEX ...]
fetch the wordlists at the given indexes in the search results, see
fetch options for additional options
fetch options:
-d, --decompress decompress and remove archive
-w WORKERS, --workers WORKERS
download workers [default: 10]
-u USERAGENT, --useragent USERAGENT
parser user agent [default: wordlistctl/v0.9.0]
```

### List Options
Expand All @@ -98,6 +110,18 @@ optional arguments:
fuzzing
misc
-f INDEX [INDEX ...], --fetch INDEX [INDEX ...]
fetch the wordlists at the given indexes in the list, see
fetch options for additional options
fetch options:
-d, --decompress decompress and remove archive
-w WORKERS, --workers WORKERS
download workers [default: 10]
-u USERAGENT, --useragent USERAGENT
parser user agent [default: wordlistctl/v0.9.0]
```

## Get Involved
Expand Down
59 changes: 50 additions & 9 deletions wordlistctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
WORDLIST_PATH: str = "/usr/share/wordlists"
REPOSITORY: dict = {}
RETRY_COUNT: int = 5
SEARCH_RESULTS: list = []


def error(string: str) -> None:
Expand Down Expand Up @@ -200,9 +201,13 @@ def fetch_func(parser: argparse.ArgumentParser) -> None:

def search_func(parser: argparse.ArgumentParser) -> None:
global REPOSITORY
global SEARCH_RESULTS

SEARCH_RESULTS = []

count: int = 0
search_term: str = parser.search_term
search_results: list = []
try:
if parser.local:
for root, _, files in os.walk(parser.basedir):
Expand All @@ -216,8 +221,9 @@ def search_func(parser: argparse.ArgumentParser) -> None:
for wordlist in REPOSITORY:
if wordlist.__contains__(search_term):
size = REPOSITORY[wordlist]["size"]
print(f" > {wordlist} ({size})")
print(f" {count} > {wordlist} ({size})")
count += 1
SEARCH_RESULTS.append(wordlist)

if count == 0:
error("no wordlists found")
Expand All @@ -227,21 +233,36 @@ def search_func(parser: argparse.ArgumentParser) -> None:

def lst_func(parser: argparse.ArgumentParser) -> None:
global REPOSITORY
global SEARCH_RESULTS

SEARCH_RESULTS = []

success("available wordlists:")

print()

count: int = 0
for wordlist in REPOSITORY:
if parser.group is not None:
if REPOSITORY[wordlist]["group"] not in parser.group:
continue
size: str = REPOSITORY[wordlist]["size"]
print(f" > {wordlist} ({size})")
print(f" {count} > {wordlist} ({size})")
SEARCH_RESULTS.append(wordlist)
count += 1

print()


def add_fetch_options(parser: argparse.ArgumentParser) -> None:
parser.add_argument("-d", "--decompress", action="store_true",
help="decompress and remove archive")
parser.add_argument("-w", "--workers", type=int, default=10,
help="download workers [default: %(default)s]")
parser.add_argument("-u", "--useragent", default=f"{__project__}/{__version__}",
help="parser user agent [default: %(default)s]")


def main() -> int:
banner()

Expand All @@ -252,7 +273,7 @@ def main() -> int:
parser.add_argument("-v", "--version", action="version",
version=f"{__project__} {__version__}")

subparsers = parser.add_subparsers()
subparsers = parser.add_subparsers(dest="command")

fetch = subparsers.add_parser("fetch", help="fetch wordlists")
fetch.add_argument("-l", "--wordlist", nargs='+', dest="wordlist",
Expand All @@ -261,15 +282,11 @@ def main() -> int:
choices=["usernames", "passwords",
"discovery", "fuzzing", "misc"],
help="wordlist group to fetch")
fetch.add_argument("-d", "--decompress", action="store_true",
help="decompress and remove archive")
fetch.add_argument("-w", "--workers", type=int, default=10,
help="download workers [default: %(default)s]")
fetch.add_argument("-u", "--useragent", default=f"{__project__}/{__version__}",
help="fetch user agent [default: %(default)s]")
fetch.add_argument("-b", "--base-dir", default=f"{WORDLIST_PATH}", dest="basedir",
help="wordlists base directory [default: %(default)s]")

add_fetch_options(fetch)

fetch.set_defaults(func=fetch_func)

search = subparsers.add_parser("search", help="search wordlists")
Expand All @@ -278,13 +295,27 @@ def main() -> int:
help="search local archives")
search.add_argument("-b", "--base-dir", default=f"{WORDLIST_PATH}", dest="basedir",
help="wordlists base directory [default: %(default)s]")
search.add_argument("-f", "--fetch", type=int, nargs='+', dest="indexes", metavar="INDEX",
help=("fetch the wordlists at the given indexes in the search "
"results, see fetch options for additional options"))

search_fetch = search.add_argument_group("fetch options")
add_fetch_options(search_fetch)

search.set_defaults(func=search_func)

lst = subparsers.add_parser("list", help="list wordlists")
lst.add_argument("-g", "--group",
choices=["usernames", "passwords",
"discovery", "fuzzing", "misc"],
help="group")
lst.add_argument("-f", "--fetch", type=int, nargs='+', dest="indexes", metavar="INDEX",
help=("fetch the wordlists at the given indexes in the list, "
"see fetch options for additiional options"))

lst_fetch = lst.add_argument_group("fetch options")
add_fetch_options(lst_fetch)

lst.set_defaults(func=lst_func)

results = parser.parse_args()
Expand All @@ -295,6 +326,16 @@ def main() -> int:

try:
results.func(results)
if results.command != "fetch" and results.indexes is not None:
setattr(results, "wordlist", [])
# group argument added so `fetch_func` does not complain
setattr(results, "group", None)
for i in results.indexes:
try:
results.wordlist.append(SEARCH_RESULTS[i])
except IndexError:
error(f"no wordlist with index: {i}")
fetch_func(results)
except Exception as ex:
error(f"Error while parsing arguments: {ex}")

Expand Down

0 comments on commit 4c1ea3e

Please sign in to comment.