feat: added dictionary generating tool.
This commit is contained in:
parent
d90d443017
commit
e067b06686
6 changed files with 138 additions and 35 deletions
77
dict/dict.go
Normal file
77
dict/dict.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
package dict
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"strconv"
|
||||
|
||||
"surdeus.su/core/cli/mtool"
|
||||
"surdeus.su/util/combo/pin"
|
||||
"surdeus.su/util/combo/tmpl"
|
||||
)
|
||||
|
||||
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
var Tool = mtool.T("dict").Func(Run).Usage(
|
||||
"<token1 token2 ... [token3]>",
|
||||
).Desc("make password dictionary from custom tokens")
|
||||
|
||||
func Run(
|
||||
flags *mtool.Flags,
|
||||
) {
|
||||
var (
|
||||
maxLen int
|
||||
)
|
||||
|
||||
flags.IntVar(
|
||||
&maxLen,
|
||||
"max", 2, "max tokens in output passwords",
|
||||
)
|
||||
tokens := flags.Parse()
|
||||
if len(tokens) < 2 {
|
||||
flags.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(tokens) > len(alphabet) {
|
||||
flags.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
c := alphabet[:len(tokens)]
|
||||
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
input, output := io.Pipe()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
pin.Tool.Run([]string{
|
||||
"-c", c,
|
||||
"-m", "-max-reps", "1",
|
||||
"-max-len", strconv.Itoa(maxLen),
|
||||
"--",
|
||||
},
|
||||
io.Reader(os.Stdin), io.Writer(output),
|
||||
)
|
||||
output.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
tmpl.Tool.Run(append([]string{
|
||||
"-c", c,
|
||||
"--",
|
||||
}, tokens...),
|
||||
io.Reader(input), io.Writer(os.Stdout),
|
||||
)
|
||||
input.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
}
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module surdeus.su/util/combo
|
|||
|
||||
go 1.16
|
||||
|
||||
require surdeus.su/core/cli v0.6.0
|
||||
require surdeus.su/core/cli v0.8.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2,3 +2,7 @@ golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|||
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
|
||||
surdeus.su/core/cli v0.6.0 h1:ezyBljhVn+lTcIMPblUMsQzaXQ+xzkzZ9ZYLcirZwEI=
|
||||
surdeus.su/core/cli v0.6.0/go.mod h1:r9JtQz3aEJzpYzMaNUNQHJoYkoWKNPi047qhd5uGlmA=
|
||||
surdeus.su/core/cli v0.7.0 h1:4IBN6PyZp6BUTC2mrDPudCjUbs/fs6Pv1KG/Ua/vBCI=
|
||||
surdeus.su/core/cli v0.7.0/go.mod h1:r9JtQz3aEJzpYzMaNUNQHJoYkoWKNPi047qhd5uGlmA=
|
||||
surdeus.su/core/cli v0.8.0 h1:HGmRqWl6W5DxFX1nVkUpS+cK0BgYYJdYrZY3VTq3C4k=
|
||||
surdeus.su/core/cli v0.8.0/go.mod h1:r9JtQz3aEJzpYzMaNUNQHJoYkoWKNPi047qhd5uGlmA=
|
||||
|
|
7
main.go
7
main.go
|
@ -2,14 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"surdeus.su/util/combo/tmpl"
|
||||
"surdeus.su/util/combo/pin"
|
||||
|
||||
"surdeus.su/core/cli/mtool"
|
||||
"surdeus.su/util/combo/dict"
|
||||
"surdeus.su/util/combo/pin"
|
||||
"surdeus.su/util/combo/tmpl"
|
||||
)
|
||||
|
||||
var root = mtool.T("combo").Subs(
|
||||
tmpl.Tool,
|
||||
pin.Tool,
|
||||
dict.Tool,
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
35
pin/pin.go
35
pin/pin.go
|
@ -21,7 +21,7 @@ var (
|
|||
|
||||
func Pow(x, p int) int {
|
||||
ret := 1
|
||||
for i:=0 ; i<p ; i++ {
|
||||
for i := 0; i < p; i++ {
|
||||
ret *= x
|
||||
}
|
||||
return ret
|
||||
|
@ -30,8 +30,8 @@ func Pow(x, p int) int {
|
|||
func GetPin(chars []rune, length int, i int) string {
|
||||
ret := ""
|
||||
slen := len(chars)
|
||||
for j:=0 ; j<length ; j++ {
|
||||
ret = string(chars[ ( i/Pow(slen, j) ) % slen] ) + ret
|
||||
for j := 0; j < length; j++ {
|
||||
ret = string(chars[(i/Pow(slen, j))%slen]) + ret
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
@ -40,11 +40,12 @@ func FprintPins(
|
|||
output io.Writer,
|
||||
chars []rune,
|
||||
length int,
|
||||
maxReps int,
|
||||
) {
|
||||
n := Pow(len(chars), length)
|
||||
for i:=0 ; i<n ; i++ {
|
||||
for i := 0; i < n; i++ {
|
||||
pin := GetPin(chars, length, i)
|
||||
if Fits([]rune(pin), chars, length) {
|
||||
if Fits([]rune(pin), chars, maxReps) {
|
||||
fmt.Fprintln(
|
||||
output,
|
||||
GetPin(chars, length, i),
|
||||
|
@ -71,11 +72,19 @@ func Fits(s []rune, chrs []rune, maxReps int) bool {
|
|||
func Run(
|
||||
flags *mtool.Flags,
|
||||
) {
|
||||
cargs := flags.CustomArgs()
|
||||
if len(cargs) == 0 {
|
||||
CustomRun(
|
||||
os.Stdin,
|
||||
os.Stdout,
|
||||
flags,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
input := cargs[0].(io.Reader)
|
||||
output := cargs[1].(io.Writer)
|
||||
CustomRun(input, output, flags)
|
||||
}
|
||||
|
||||
func CustomRun(
|
||||
|
@ -103,20 +112,20 @@ func CustomRun(
|
|||
"COMBO_CHARS",
|
||||
)
|
||||
flags.IntVar(
|
||||
&minLength, "min-len", 1,
|
||||
&minLength, "min-len", 4,
|
||||
"min length of the output pins",
|
||||
)
|
||||
flags.BoolVar(
|
||||
&mFlag, "m", false,
|
||||
"set the '-min-len' flag value to 1 (overrides the '-min' it)",
|
||||
"set the '-min-len' flag value to 1 (overrides the '-min-len')",
|
||||
)
|
||||
flags.IntVar(
|
||||
&length, "max", 0,
|
||||
&length, "max-len", 0,
|
||||
"max length of the output pins",
|
||||
)
|
||||
|
||||
flags.IntVar(&maxReps, "max-reps", 1, "max repeats of the rune." )
|
||||
flags.BoolVar(&rFlag, "r", false, "make the -max-reps value equal to the length of input chars" )
|
||||
flags.IntVar(&maxReps, "max-reps", 4, "max repeats of the rune.")
|
||||
flags.BoolVar(&rFlag, "r", false, "make the -max-reps value equal to the length of input chars")
|
||||
|
||||
_ = flags.Parse()
|
||||
|
||||
|
@ -144,11 +153,11 @@ func CustomRun(
|
|||
flags.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
for i := minLength ; i<=length ; i++ {
|
||||
FprintPins(output, chrs, i)
|
||||
for i := minLength; i <= length; i++ {
|
||||
FprintPins(output, chrs, i, maxReps)
|
||||
}
|
||||
} else {
|
||||
FprintPins(output, chrs, length)
|
||||
FprintPins(output, chrs, length, maxReps)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
18
tmpl/tmpl.go
18
tmpl/tmpl.go
|
@ -4,6 +4,8 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
//"log"
|
||||
"os"
|
||||
|
||||
"surdeus.su/core/cli/mtool"
|
||||
|
@ -18,8 +20,16 @@ var (
|
|||
)
|
||||
)
|
||||
|
||||
func Run(flags *mtool.Flags){
|
||||
func Run(flags *mtool.Flags) {
|
||||
cargs := flags.CustomArgs()
|
||||
if len(cargs) == 0 {
|
||||
CustomRun(os.Stdin, os.Stdout, flags)
|
||||
return
|
||||
}
|
||||
|
||||
input := cargs[0].(io.Reader)
|
||||
output := cargs[1].(io.Writer)
|
||||
CustomRun(input, output, flags)
|
||||
}
|
||||
|
||||
func CustomRun(
|
||||
|
@ -59,15 +69,15 @@ func CustomRun(
|
|||
chrs = []rune(charsString)
|
||||
//args = args[1:]
|
||||
|
||||
tmpl := make(map[rune] string)
|
||||
tmpl := make(map[rune]string)
|
||||
for i, s := range args {
|
||||
tmpl[rune(chrs[i])] = s
|
||||
}
|
||||
|
||||
r := bufio.NewReader(input)
|
||||
for{
|
||||
for {
|
||||
s, e := r.ReadString(byte(delim))
|
||||
if e==io.EOF {
|
||||
if e == io.EOF {
|
||||
break
|
||||
}
|
||||
s = s[:len(s)-1]
|
||||
|
|
Loading…
Reference in a new issue