- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
pin had no tests at all while being the foundation of everything: dict calls it
for the enumeration, and every candidate in every wordlist comes from it. It now
has 30 assertions and 94% coverage.
Writing them turned up three ways it failed without saying so:
- CustomRun called os.Exit on a usage error. It is a library entry point, and
dict runs it in a goroutine, so a bad combination of lengths killed the
process with the other stages blocked on pipes. It now renders the usage and
reports through flags.Fail, which is what gocli v0.20.0 added for this.
- -max-len 70 over two characters used to run for as long as the lengths that
do fit take -- which is forever, since they are printed first. Pow wrapped
into a value the loop skipped, and the smaller lengths ran ahead of it.
PowChecked reports the overflow and check refuses the length before anything
is written.
- an empty -c printed nothing and exited 0, which a caller cannot tell from a
run that worked.
Also depends on gocli v0.20.0, where flags.Usage() finally prints something: the
call had been resolving to the embedded flag set's empty hook, so these refusals
had a usage error to report and no way to report it.
|
||
| conv | ||
| dict | ||
| mut | ||
| pin | ||
| rev | ||
| sep | ||
| suf | ||
| template | ||
| tmpl | ||
| uniq | ||
| .gitignore | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| readme.md | ||
combo
Description
Set of utils to implement templates based on UTF-8 characters: given the shape of a secret, enumerate the plausible renderings of it.
The stages compose. pin enumerates every arrangement of a character set,
sep decides where separators go, conv writes down which characters stand
for keywords and which are separators, tmpl renders each template into the
keywords themselves, mut gives each keyword a mutation or leaves it alone,
rev emits each rendered line and its reverse, suf appends suffixes to it,
and uniq drops the lines that were already written. dict chains them:
pin → sep → conv [→ mut] → tmpl [→ suf] [→ rev] → uniq
$ combo dict love hate
love
love1
love123
love1234
love!
love1!
Love
Love1
...
Basic mutations are on by default — as typed, first letter up, all caps, and
leeted — so every keyword comes out in the shapes real passwords take. -mut ''
turns them off and gives the bare list:
$ combo dict -mut '' love hate
love
hate
lovehate
love_hate
love-hate
hatelove
hate_love
hate-love
One keyword is enough for a list of one:
$ combo dict love
love
Love
LOVE
l0v3
-max caps how many keywords one password combines, and defaults to two: most
passwords are one word or two joined, and a command naming four things should
not quietly return fifty thousand lines.
$ combo dict alex smith jane 1990 | wc -l
373
$ combo dict -max 0 alex smith jane 1990 | wc -l
47893
-max 0 means every keyword, which is how the fullest list is asked for
explicitly. Sizes for those four keywords:
-max 2— 373 lines-max 3— 6,421-max 0— 47,893, in under a second
Past five keywords at full length the count runs into the millions, and the run says so on stderr before it starts.
The separator set defaults to _- and can be replaced with -seps or
COMBO_SEPARATORS:
$ combo dict -mut '' -seps . love hate
love
hate
love.hate
hate.love
A separator has to be a character no keyword uses. The stages carry a candidate
as one character per keyword, so a separator that collides with one would be
read as a word: COMBO_SEPARATORS=a used to turn ab into love love hate.
That is refused now rather than written into the output.
dict allows each keyword once per candidate, which is what keeps the output
short enough to read. Reordering and separator choice are handled; repetition
is not.
-mut offers each keyword one of the listed mutations or none, picked
independently. It defaults to C:title|C:upper|L — first letter up, all caps,
and leet — and the empty string turns it off:
$ combo dict -mut 'C:title' love hate | head -8
love
Love
hate
Hate
lovehate
Lovehate
loveHate
LoveHate
That is the point of the stage: Lovehate and loveHate are different
passwords, and only a stage that runs before rendering can tell which keyword is
which. Each extra mutation adds a choice to every keyword, so the list grows by
(mutations+1)^keywords.
The list comes out most likely first, because a wordlist is usually tried from the top and a hit at line 4 is worth more than the same entry at line 4000. Each mutation carries a weight, a variant scores the product of its choices, and the variants are sorted by score:
alexsmith the plain form, score 1
Alexsmith one common mutation, 0.5
alexSmith 0.5
AlexSmith two mutations, 0.25
ALEXsmith 0.2
4l3xsmith 0.1 ...and the leet forms last
That ordering is the difference between a list worth truncating and one that is
not: before it, 4l3xsmith outranked AlexSmith purely because of how the
enumeration counted.
The default is not free: alex smith goes from 8 lines to 104 with it. -mut ''
is how to ask for the bare list.
It also repeats itself, which is why uniq is the last stage: a case mutation
on a number leaves it alone, so {1C:title}{2} and {1C:title}{2C:title} both
render Alex1990. Without deduplication a third of a four-keyword list is
duplicate lines.
The size is sum over L=1..max of P(n,L) * (seps+1)^(L-1) * (mutations+1)^L,
which is what makes -max matter more than anything else here: an extra keyword
in a password multiplies the list, it does not add to it.
-suf appends suffixes to each password. It defaults to 1,123,1234,!,1! —
digits, an exclamation mark, and the two together — and the empty string turns
it off:
$ combo dict -suf '!' love hate | head -4
love
love!
Love
Love!
Variants stay next to the base they came from rather than after the whole list,
so a truncated wordlist still reads sensibly. A suffix is not a keyword: passing
1990 to dict would make it a peer of the other words and produce 1990alex,
and under the default -max 2 it would not produce alexsmith1990 at all,
since that is a three-keyword password. suf appends to the finished password,
which is what people actually do.
It multiplies the list by the number of suffixes plus one: five of them make
alex smith 624 lines rather than 104.
-rev also emits every password reversed, so the list doubles:
$ combo dict -rev love
love
evol
Love
evoL
l0v3
3v0l
sep
Inserts separators into a sequence in every combination. A sequence of n
characters has n-1 gaps, and each gap is either empty or one of the
separators, so the output is (separators+1)^(gaps) lines — four for abc
with one separator, nine with two:
$ printf 'abc\n' | combo sep
abc
a_bc
a-bc
ab_c
a_b_c
a-b_c
ab-c
a_b-c
a-b-c
The unseparated form comes first. It sits between pin and conv in dict
because keyword boundaries do not exist until conv writes them down: before
that, a candidate is one character per keyword.
conv
Turns a candidate into a template. A position is the character's place in the
character set, counting from one, so b alone is {2} and not {1}:
$ printf 'b\na_b\n' | combo conv -c ab
{2}
{1}_{2}
Everything outside the set is literal text, escaped where the grammar would otherwise read it — a separator is not a word, so it never takes a position:
$ printf 'a{b\n' | combo conv -c ab
{1}\{{2}
A candidate with no character from the set is an error, since it cannot carry a word.
mut
Adds a mutation to the fields of a template, in every combination. Each field
either takes one of the offered mutations or stays as it is, the same choice
sep makes at every gap, so a template with n fields and k mutations has
(k+1)^n variants:
$ printf '{1}_{2}\n' | combo mut -m 'C:title'
{1}_{2}
{1C:title}_{2}
{1}_{2C:title}
{1C:title}_{2C:title}
Enough to see the difference it makes:
$ printf '{1}_{2}\n' | combo mut -m 'C:title' | combo tmpl love hate
love_hate
Love_hate
love_Hate
Love_Hate
-m defaults to C:title|C:upper|L, so a bare run offers four choices per
field and sixteen variants, ordered by likelihood rather than by enumeration
index:
$ printf '{1}_{2}\n' | combo mut | wc -l
16
A mutation is appended after the ops a field already carries, so it composes
rather than replaces: {1C:title} plus L becomes {1C:title|L}, which
renders as the title-cased word leeted.
Variants are ordered by how likely they are. Each choice has a weight — 1 for leaving the word alone, lower for rarer mutations — and a variant's score is the product of its choices, so one common mutation outranks two rare ones and the combinations of rare mutations end up at the bottom of the list, where a truncated wordlist never reaches them.
The weights encode an ordering, not a measurement: first letter up is commoner than all caps, which is commoner than letter substitution, which is commoner than reversal. They are round numbers on purpose, and nothing here was counted.
The spec is read with the same grammar as a field body, minus the position, and
comes from -m or COMBO_MUTATIONS. An empty spec changes nothing, which is
how a chain keeps the stage without mutating anything.
An alternative is a single transform. A pipeline cannot be one of the
alternatives, because | already separates them; a word that needs two
transforms in place writes them into the template itself.
tmpl
Renders templates. It works only with templates and converts nothing: each line
is parsed as one and rendered with the words given as arguments, so the first
argument fills {1} and the second {2}:
$ printf '{2C:title}_{1L}\n' | combo tmpl love hate
Hate_l0v3
A template is literal text with fields in it. A field names a position and applies transforms left to right:
{1} the first word
{2}{1} the two words swapped
{1C:title} title-cased
{1L} leet, the default table: love -> l0v3
{1L:o} leet, only the o rule
{1r} reversed
{1C:lower|C:title|L} normalise, then title, then leet
Transforms are C (case: title, upper, lower), L (leet) and r
(reverse). Arguments are opaque to the parser and interpreted by the transform.
Escaping is a backslash, and it is strict: only \\, \{, \} and \| are
understood, so a stray \q is an error rather than a silent literal. Templates
are best written in single quotes, since | is a shell pipe:
printf '{1C:title|L}\n' | combo tmpl love
A template naming a position there is no word for is an error, not a blank.
suf
Appends suffixes to each line, keeping the untouched line first:
$ printf 'alex\n' | combo suf
alex
alex1
alex123
alex1234
alex!
alex1!
It is a post-render stage, so it works on the finished password rather than on a
template: alex1990 is what someone types, and a suffix cannot be expressed as a
mutation because mut only reaches fields.
The list is comma-separated and comes from -s or COMBO_SUFFIXES. An empty
item is refused, since 1,,2 is a typo rather than a request for a plain line.
An empty spec adds nothing, which is how the stage is turned off.
In dict it runs after tmpl and before rev, so a password reverses into
something that looks like a reversed password.
uniq
Drops lines that were already written, keeping the first:
$ printf 'love\nLove\nlove\n' | combo uniq
love
Love
It is the last stage because a password is only a string once tmpl has
rendered it, and two different templates can render to the same string: a case
mutation leaves a number alone, so {1C:title}{2} and {1C:title}{2C:title} both
give Alex1990. dict always ends with it, which is what keeps a long list from
being long without being useful.
rev
Emits each line and its reverse:
$ printf 'love_hate\nabba\n' | combo rev
love_hate
etah_evol
abba
It is a post-render filter, so it belongs after tmpl: reversing is a
whole-line operation, and a template is not a string that survives reversal —
{1}_{2} turned around is }2{_, which is not a template at all. It is not a
template transform either: {1r} reverses one word, while rev reverses the
rendered line, separators included.
A palindrome is written once, since its reverse is itself. The original always comes first, so a run cut short still holds every unaltered line.