Token Mask Attack

Description

A mask position holds one byte. That is fine for ASCII, but a Cyrillic letter, a kana or an emoji takes several bytes in UTF-8, so none of them fits in a position of an ordinary -a 3 mask.

The token mask attack (-a 13) uses the same mask syntax and gives the custom charsets ?1 to ?8 sets of strings instead of sets of bytes. One position then holds a whole token: a multibyte character, a syllable, or an entire word. It arrived in 8.1.0.

The built-in charsets are unchanged. ?l is still the 26 lowercase letters, one byte each.

Running it

A charset value that names an existing file is read as a token list, one token per line:

$ hashcat -a 13 -m 0 hashes.txt ?1?1 -1 tokens.txt

Over a file holding test and ab, that mask gives four candidates:

$ hashcat --stdout -a 13 ?1?1 -1 tokens.txt
tokenmask: host engine, 4 candidates

testtest
testab
abtest
abab

-a 13 is a front end for the tokenmask feed of the generic attack, so these two command lines are the same attack:

$ hashcat -a 13 -m 0 hashes.txt ?1?1 -1 tokens.txt
$ hashcat -a 8  -m 0 hashes.txt tokenmask ?1?1 -1 tokens.txt

Give one mask per run. Mask files and several masks on one command line are not supported.

The token sets that ship with hashcat

The tokensets/ folder holds 20 ready-made files. Each line is one token in UTF-8, so a file works as a custom charset without any preparation.

  • emoji.tokenset, every fully-qualified emoji
  • cyrillic.tokenset, greek.tokenset, hebrew.tokenset, arabic.tokenset, those alphabets
  • hiragana.tokenset, katakana.tokenset, the two Japanese kana scripts
  • french.tokenset, german.tokenset, spanish.tokenset, portuguese.tokenset, italian.tokenset, polish.tokenset, czech.tokenset, turkish.tokenset, swedish.tokenset, danish-norwegian.tokenset, icelandic.tokenset, romanian.tokenset, hungarian.tokenset, the letters each of those languages adds beyond A to Z

A script file is used on its own. Cyrillic holds 66 tokens, so two positions come to 4356 candidates:

$ hashcat --stdout -a 13 ?1?1 -1 tokensets/cyrillic.tokenset
tokenmask: host engine, 4356 candidates

A Latin language file holds only the accented letters, because the rest of the alphabet is already a built-in charset. Combine the two in a second custom charset to get the full alphabet:

$ hashcat -a 13 -m 0 hashes.txt ?2?2?2?2 -1 tokensets/french.tokenset -2 ?l?u?1

Inline charsets

A charset value that does not name a file is read as an inline charset, the same way an ordinary mask reads one:

value meaning
-1 words.txt a file, every line one token
-1 ?d?s the digits and the symbols, one byte each
-1 abc the three bytes a, b and c

A ?N inside an inline charset pulls in that charset's tokens, which is how the French example above mixes a file's multibyte letters with ASCII.

A blank line in a file is not a token. If a token has to contain a newline, a carriage return or a null byte, write the tokens in hexadecimal and add --hex-charset. The shipped sets never need it, because a multibyte UTF-8 character contains none of those bytes.

Candidate length

Two tokens in the same position can differ in length, so a token mask candidate has no fixed length. A candidate outside the hash mode's own minimum and maximum is skipped rather than renumbered, which keeps a position's place in the keyspace the same on every run. --skip, --limit and --restore therefore keep working.

One token can be up to 256 bytes, which is also the longest candidate hashcat makes. Several tokens together can exceed that. A mask whose shortest candidate is already too long is refused when it is read, rather than running and skipping every candidate.

--increment counts positions, not bytes, since the positions are not one byte each. So ?1?1?1 under --increment runs ?1, then ?1?1, then ?1?1?1. --increment-min and --increment-max bound the position count, and --increment-inverse shortens from the left, as it does for -a 3.

The two engines

On a fast hash the feed amplifies on the card, through the same device engine the PCFG and table attacks use. The trailing mask positions are walked in the kernel and only the leading ones are built on the host, so no candidate crosses the PCIe bus. A token mask then runs within a small factor of a byte mask of the same size.

The host engine takes the run instead for --stdout, a rules pass, --slow-candidates, a slow hash mode, a mode with no device-engine kernel, or a mask whose candidates are longer than the device's candidate buffer of about 127 bytes. The startup line reports which engine was chosen, as in the examples above.

The candidates and their order are the same either way. What differs is what a position counts:

  • On the host engine a position is one candidate, so --keyspace, --skip, --limit and the restore point count candidates.
  • On the device engine a position is one base word, which the card expands into many candidates, so those four count base words. For x?1?d over six tokens, --keyspace reports 1, the single base word behind 60 candidates.

The progress line counts candidates on either engine, and --total-candidates reports the exact candidate count either way.

Order and counting

The order is a plain odometer. The rightmost position runs fastest and each position counts over its own token list, exactly as a byte mask counts. The candidate at any position can be computed directly from that number, so a seek is exact and a restore is reliable.

The candidate count is the product of the per-position token counts, held in 128 bits, so a mask over several large token files is counted exactly. A count past 2^128 is reported as unknown rather than wrong.

Rules and settings

Rules apply to the candidates a token mask makes, the same as to a wordlist:

$ hashcat -a 13 -m 0 hashes.txt ?1?1 -1 tokens.txt -r rules/best66.rule

The feed also takes key=value settings, which are part of the attack: they go into the restore file and into the brain session, so two runs differing only in a setting are two attacks.

setting default meaning
pw-min the hash mode's own minimum shortest candidate to keep
pw-max the hash mode's own maximum longest candidate to keep
c1 to c8 the -1 to -8 options token charset for ?1 to ?8

Full documentation

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain