Skip to content

Commit

Permalink
Adding permutator feature for usernames
Browse files Browse the repository at this point in the history
("", "_", "-", ".") when id_type == username

File : maigret/permutator.py

Arg : --permute

For now, only permute from 2 elements and doesn't return single elements (element1, _element1, element1_,  element2, _element2, ...). 12 permuts for 2 elements.

To return single elements as well, Permute(usernames).gather(method="all"), but not implemented in maigrat.py. 18 permuts for 2 elements. Should we ? With another argument ?
  • Loading branch information
balestek committed Jun 7, 2024
1 parent 46d8d8f commit 0735e66
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions maigret/maigret.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from .types import QueryResultWrapper
from .utils import get_dict_ascii_tree
from .settings import Settings
from .permutator import Permute


def notify_about_errors(search_results: QueryResultWrapper, query_notify):
Expand Down Expand Up @@ -205,6 +206,12 @@ def setup_arguments_parser(settings: Settings):
choices=SUPPORTED_IDS,
help="Specify identifier(s) type (default: username).",
)
parser.add_argument(
"--permute",
action="store_true",
default=False,
help="Permute at least 2 usernames to generate more possible usernames.",
)
parser.add_argument(
"--db",
metavar="DB_FILE",
Expand Down Expand Up @@ -502,6 +509,10 @@ async def main():
for u in args.username
if u and u not in ['-'] and u not in args.ignore_ids_list
}
original_usernames = ""
if args.permute and len(usernames) > 1 and args.id_type == 'username':
original_usernames = " ".join(usernames.keys())
usernames = Permute(usernames).gather(method='strict')

parsing_enabled = not args.disable_extracting
recursive_search_enabled = not args.disable_recursive_search
Expand Down Expand Up @@ -591,6 +602,11 @@ async def main():
query_notify.warning('No usernames to check, exiting.')
sys.exit(0)

if len(usernames) > 1 and args.permute and args.id_type == 'username':
query_notify.warning(
f"{len(usernames)} permutations from {original_usernames} to check..."
)

if not site_data:
query_notify.warning('No sites to check, exiting!')
sys.exit(2)
Expand Down
26 changes: 26 additions & 0 deletions maigret/permutator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# License MIT. by balestek https://github.com/balestek
from itertools import permutations


class Permute:
def __init__(self, elements: dict):
self.separators = ["", "_", "-", "."]
self.elements = elements

def gather(self, method: str = "strict" or "all") -> dict:
permutations_dict = {}
for i in range(1, len(self.elements) + 1):
for subset in permutations(self.elements, i):
if i == 1:
if method == "all":
permutations_dict[subset[0]] = self.elements[subset[0]]
permutations_dict["_" + subset[0]] = self.elements[subset[0]]
permutations_dict[subset[0] + "_"] = self.elements[subset[0]]
else:
for separator in self.separators:
perm = separator.join(subset)
permutations_dict[perm] = self.elements[subset[0]]
if separator == "":
permutations_dict["_" + perm] = self.elements[subset[0]]
permutations_dict[perm + "_"] = self.elements[subset[0]]
return permutations_dict

0 comments on commit 0735e66

Please sign in to comment.