Example #1
0
def _run_essid_digits(compounds_fpath: Path, hashcat_cmd=None, fast=True):
    if not fast:
        assert hashcat_cmd is not None, \
            "Non-fast mode requires running a hashcat command."
    candidates = set()
    wordlist_order = [compounds_fpath]
    if fast:
        wordlist_order.append(WordListDefault.DIGITS_APPEND_SHORT)
    else:
        wordlist_order.append(WordListDefault.DIGITS_APPEND)
    with open(compounds_fpath) as f:
        compounds_count = len(f.readlines())
    if compounds_count > 1000 and hashcat_cmd is not None:
        # reduce IO operations, run the hashcat attack directly
        fast = False
    for reverse in range(2):
        with tempfile.NamedTemporaryFile(mode='w+', errors='ignore') as f:
            hashcat_stdout = HashcatCmdStdout(outfile=f.name)
            hashcat_stdout.add_wordlists(*wordlist_order, options=['-a1'])
            subprocess_call(hashcat_stdout.build())
            if fast:
                candidates.update(f.read().splitlines())
            else:
                _hashcat_cmd_tmp = deepcopy(hashcat_cmd)
                _hashcat_cmd_tmp.add_wordlists(f.name)
                subprocess_call(_hashcat_cmd_tmp.build())
        wordlist_order = wordlist_order[::-1]
    return candidates
Example #2
0
 def _run_essid_digits(self, hcap_fpath_essid: Path, essid_wordlist_path: str):
     wordlist_order = [essid_wordlist_path, WordListDefault.DIGITS_APPEND.path]
     for reverse in range(2):
         with tempfile.NamedTemporaryFile(mode='w') as f:
             hashcat_stdout = HashcatCmdStdout(outfile=f.name)
             hashcat_stdout.add_wordlists(*wordlist_order, options=['-a1'])
             subprocess_call(hashcat_stdout.build())
             hashcat_cmd = self.new_cmd(hcap_file=hcap_fpath_essid)
             hashcat_cmd.add_wordlists(f.name)
             subprocess_call(hashcat_cmd.build())
         wordlist_order = wordlist_order[::-1]
Example #3
0
 def run_names_with_digits(self):
     # excluded from the fast run
     # for each case-changed <name> in (Name, name, NAME) do
     #  - append digits
     #  - prepend digits
     with open(WordListDefault.NAMES_UA_RU_WITH_DIGITS.path, 'w') as f:
         wordlist_order = [WordListDefault.NAMES_UA_RU, WordListDefault.DIGITS_APPEND]
         for left in ['left', 'right']:
             for rule_names in ['', 'T0', 'u']:
                 hashcat_stdout = HashcatCmdStdout(outfile=f.name)
                 hashcat_stdout.add_wordlists(*wordlist_order, options=['-a1', f'--rule-{left}={rule_names}'])
                 subprocess_call(hashcat_stdout.build())
             wordlist_order = wordlist_order[::-1]
     hashcat_cmd = self.new_cmd()
     hashcat_cmd.add_wordlists(WordListDefault.NAMES_UA_RU_WITH_DIGITS)
     subprocess_call(hashcat_cmd.build())
Example #4
0
 def run_names(self):
     with tempfile.NamedTemporaryFile(mode='w') as f:
         hashcat_stdout = HashcatCmdStdout(outfile=f.name)
         hashcat_stdout.add_wordlists(WordListDefault.NAMES_UA_RU)
         hashcat_stdout.add_rule(Rule.ESSID)
         subprocess_call(hashcat_stdout.build())
         hashcat_cmd = self.new_cmd()
         hashcat_cmd.add_wordlists(f.name)
         subprocess_call(hashcat_cmd.build())
Example #5
0
 def _run_essid_rule(self, hcap_fpath: Path, essid_wordlist_path: Path):
     """
     Run ESSID + best64.rule attack.
     """
     with tempfile.NamedTemporaryFile(mode='w') as f:
         hashcat_stdout = HashcatCmdStdout(outfile=f.name)
         hashcat_stdout.add_wordlists(essid_wordlist_path)
         hashcat_stdout.add_rule(Rule.ESSID)
         subprocess_call(hashcat_stdout.build())
         hashcat_cmd = self.new_cmd(hcap_file=hcap_fpath)
         hashcat_cmd.add_wordlists(f.name)
         subprocess_call(hashcat_cmd.build())
Example #6
0
def _collect_essid_rule(essid_wordlist_path: Path):
    """
    Run ESSID + best64.rule attack.
    """
    with tempfile.NamedTemporaryFile(mode='w+', errors='ignore') as f:
        # Ignore UnicodeDecodeError: 'utf-8' codec can't decode byte ...
        hashcat_stdout = HashcatCmdStdout(outfile=f.name)
        hashcat_stdout.add_wordlists(essid_wordlist_path)
        hashcat_stdout.add_rule(Rule.ESSID)
        subprocess_call(hashcat_stdout.build())
        candidates = f.read().splitlines()
    return candidates
Example #7
0
def create_fast_wordlists():
    # note that dumping all combinations in a file is not equivalent to
    # directly adding top1k wordlist and best64 rule because hashcat ignores
    # patterns that are <8 chars _before_ expanding a candidate with the rule.
    if not WordListDefault.TOP1K_RULE_BEST64.path.exists():
        # it should be already created in a docker
        logger.warning(
            f"{WordListDefault.TOP1K_RULE_BEST64.name} does not exist. Creating"
        )
        hashcat_stdout = HashcatCmdStdout(
            outfile=WordListDefault.TOP1K_RULE_BEST64.path)
        hashcat_stdout.add_wordlists(WordListDefault.TOP1K)
        hashcat_stdout.add_rule(Rule.BEST_64)
        subprocess_call(hashcat_stdout.build())