├── test ├── file1.txt ├── test.txt ├── file2.txt └── urls.txt ├── assets ├── head.png ├── min.png ├── append.png ├── basic.png ├── meth1.png ├── meth2.png ├── meth3.png ├── ranges.png ├── repeat.png ├── search.png ├── using.png ├── Frame 214.png ├── functions.png ├── methdocs.png ├── methods.png ├── prefixsuffix.png ├── savewordlist.png ├── multiplemethods.png ├── multipleencodings.png └── parameterapproach.png ├── v2 ├── cmd │ └── cook │ │ ├── verbose.go │ │ ├── version.go │ │ ├── vars.go │ │ ├── main.go │ │ ├── cmds.go │ │ └── usage.go ├── pkg │ ├── config │ │ ├── verbose.go │ │ ├── type.go │ │ ├── url.go │ │ ├── yaml.go │ │ ├── update.go │ │ ├── file.go │ │ ├── config.go │ │ ├── cache.go │ │ └── parse.go │ ├── cook │ │ ├── verbose.go │ │ ├── params.go │ │ ├── type.go │ │ ├── search_test.go │ │ ├── output.go │ │ ├── repeat.go │ │ ├── search.go │ │ ├── run.go │ │ ├── methods.go │ │ ├── cook_test.go │ │ ├── cook.go │ │ └── cmd.go │ ├── util │ │ ├── base.go │ │ ├── cmd.go │ │ ├── colors.go │ │ └── yaml.go │ ├── methods │ │ ├── regex.go │ │ ├── type.go │ │ ├── json.go │ │ ├── new.go │ │ ├── cases.go │ │ ├── leet.go │ │ ├── encode.go │ │ ├── strings.go │ │ ├── smart.go │ │ ├── methods.go │ │ └── urls.go │ └── parse │ │ ├── syntax.go │ │ └── parse.go ├── go.mod └── go.sum ├── .github └── FUNDING.yml ├── LICENSE └── README.md /test/file1.txt: -------------------------------------------------------------------------------- 1 | AAAA 2 | BBBB 3 | CCCC 4 | DDDD -------------------------------------------------------------------------------- /test/test.txt: -------------------------------------------------------------------------------- 1 | line1 2 | line2 3 | line3 4 | line4 -------------------------------------------------------------------------------- /test/file2.txt: -------------------------------------------------------------------------------- 1 | 1111 2 | 2222 3 | 3333 4 | 4444 5 | 6 | cook f1 * f2 -------------------------------------------------------------------------------- /assets/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/head.png -------------------------------------------------------------------------------- /assets/min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/min.png -------------------------------------------------------------------------------- /test/urls.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/test/urls.txt -------------------------------------------------------------------------------- /assets/append.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/append.png -------------------------------------------------------------------------------- /assets/basic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/basic.png -------------------------------------------------------------------------------- /assets/meth1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/meth1.png -------------------------------------------------------------------------------- /assets/meth2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/meth2.png -------------------------------------------------------------------------------- /assets/meth3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/meth3.png -------------------------------------------------------------------------------- /assets/ranges.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/ranges.png -------------------------------------------------------------------------------- /assets/repeat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/repeat.png -------------------------------------------------------------------------------- /assets/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/search.png -------------------------------------------------------------------------------- /assets/using.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/using.png -------------------------------------------------------------------------------- /assets/Frame 214.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/Frame 214.png -------------------------------------------------------------------------------- /assets/functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/functions.png -------------------------------------------------------------------------------- /assets/methdocs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/methdocs.png -------------------------------------------------------------------------------- /assets/methods.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/methods.png -------------------------------------------------------------------------------- /assets/prefixsuffix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/prefixsuffix.png -------------------------------------------------------------------------------- /assets/savewordlist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/savewordlist.png -------------------------------------------------------------------------------- /assets/multiplemethods.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/multiplemethods.png -------------------------------------------------------------------------------- /assets/multipleencodings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/multipleencodings.png -------------------------------------------------------------------------------- /assets/parameterapproach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchedgitz/cook/HEAD/assets/parameterapproach.png -------------------------------------------------------------------------------- /v2/cmd/cook/verbose.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func VPrint(msg string) { 9 | if verbose { 10 | fmt.Fprintln(os.Stderr, msg) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /v2/pkg/config/verbose.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func (conf *Config) VPrint(msg string) { 9 | if conf.Verbose { 10 | fmt.Fprintln(os.Stderr, msg) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /v2/pkg/cook/verbose.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func (cook *COOK) VPrint(msg string) { 9 | if cook.Config.Verbose { 10 | fmt.Fprintln(os.Stderr, msg) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /v2/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/glitchedgitz/cook/v2 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/adrg/strutil v0.2.3 7 | github.com/buger/jsonparser v1.1.1 8 | github.com/ffuf/pencode v0.0.0-20210513164852-47e578431524 9 | golang.org/x/net v0.17.0 10 | gopkg.in/yaml.v3 v3.0.0 11 | ) 12 | -------------------------------------------------------------------------------- /v2/pkg/cook/params.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func (cook *COOK) ShowCols() { 9 | fmt.Fprintln(os.Stderr) 10 | for i, p := range cook.Pattern { 11 | fmt.Fprintf(os.Stderr, "Col %d: %s\n", i, p) 12 | } 13 | fmt.Fprintln(os.Stderr) 14 | os.Exit(0) 15 | } 16 | -------------------------------------------------------------------------------- /v2/pkg/util/base.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | func Exists(path string) bool { 9 | _, err := os.Stat(path) 10 | if err == nil { 11 | return true 12 | } 13 | if os.IsNotExist(err) { 14 | return false 15 | } 16 | log.Fatalln(path) 17 | return false 18 | } 19 | -------------------------------------------------------------------------------- /v2/pkg/methods/regex.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import cook "github.com/glitchedgitz/cook/v2/pkg/config" 4 | 5 | func (m *Methods) Regex(values []string, regex string, array *[]string) { 6 | data := []byte{} 7 | for _, v := range values { 8 | data = append(data, []byte(v+"\n")...) 9 | } 10 | cook.FindRegex(data, regex, array) 11 | } 12 | -------------------------------------------------------------------------------- /v2/pkg/methods/type.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "net/url" 5 | 6 | "github.com/ffuf/pencode/pkg/pencode" 7 | ) 8 | 9 | type Methods struct { 10 | LeetValues map[string][]string 11 | MethodFuncs map[string]func([]string, string, *[]string) 12 | UrlFuncs map[string]func(*url.URL, *[]string) 13 | EncodersFuncs map[string]pencode.Encoder 14 | } 15 | -------------------------------------------------------------------------------- /v2/pkg/methods/json.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/buger/jsonparser" 7 | ) 8 | 9 | func (m *Methods) GetJsonField(lines []string, get string, array *[]string) { 10 | values := strings.Split(get, ":") 11 | for _, line := range lines { 12 | data := []byte(line) 13 | value, _, _, _ := jsonparser.Get(data, values...) 14 | v := string(value) 15 | *array = append(*array, v) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v2/pkg/util/cmd.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func TerminalColor(text, color string) string { 8 | return fmt.Sprintf("%s%s%s", color, text, Reset) 9 | } 10 | 11 | func TerminalLink(url, text, color string) string { 12 | // When colors are disabled (Reset is empty), skip hyperlink escape sequences 13 | if Reset == "" { 14 | return text 15 | } 16 | return fmt.Sprintf("%s\033]8;;%s\033\\%s\033]8;;\033\\%s", color, url, text, Reset) 17 | } 18 | -------------------------------------------------------------------------------- /v2/pkg/config/type.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "sync" 4 | 5 | type Config struct { 6 | wg sync.WaitGroup 7 | ConfigInfo string 8 | Ingredients map[string]map[string][]string 9 | CheckIngredients map[string][]string 10 | InputFile map[string]bool 11 | HomeFolder string 12 | ReConfigure bool 13 | ConfigPath string 14 | CachePath string 15 | IngredientsPath string 16 | Peek int 17 | Verbose bool 18 | } 19 | -------------------------------------------------------------------------------- /v2/pkg/methods/new.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "net/url" 5 | 6 | "github.com/ffuf/pencode/pkg/pencode" 7 | ) 8 | 9 | func New(LeetValues map[string][]string) *Methods { 10 | 11 | m := &Methods{ 12 | LeetValues: LeetValues, 13 | } 14 | m.MethodFuncs = make(map[string]func([]string, string, *[]string)) 15 | m.UrlFuncs = make(map[string]func(*url.URL, *[]string)) 16 | m.EncodersFuncs = make(map[string]pencode.Encoder) 17 | 18 | m.SetupMethodFunc() 19 | m.SetupUrlFunc() 20 | m.SetupEncodersFunc() 21 | 22 | return m 23 | } 24 | -------------------------------------------------------------------------------- /v2/pkg/cook/type.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "github.com/glitchedgitz/cook/v2/pkg/config" 5 | "github.com/glitchedgitz/cook/v2/pkg/methods" 6 | ) 7 | 8 | type COOK struct { 9 | Config *config.Config 10 | Method *methods.Methods 11 | Pattern []string // pattern but now parsed 12 | Params map[string]string 13 | Min int 14 | MethodParam string 15 | MethodsForAll string 16 | AppendParam string 17 | MethodMap map[int][]string 18 | AppendMap map[int]bool 19 | Final []string 20 | TotalCols int 21 | PrintResult bool 22 | } 23 | -------------------------------------------------------------------------------- /v2/pkg/methods/cases.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | func (m *Methods) Upper(values []string, useless string, array *[]string) { 8 | for _, v := range values { 9 | *array = append(*array, strings.ToUpper(v)) 10 | } 11 | } 12 | 13 | func (m *Methods) Lower(values []string, useless string, array *[]string) { 14 | for _, v := range values { 15 | *array = append(*array, strings.ToLower(v)) 16 | } 17 | } 18 | 19 | func (m *Methods) Title(values []string, useless string, array *[]string) { 20 | for _, v := range values { 21 | *array = append(*array, strings.Title(v)) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: glitchedgitz 4 | patreon: # 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://www.buymeacoffee.com/glitchedgitz 13 | -------------------------------------------------------------------------------- /v2/cmd/cook/version.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const version = "2.0" 6 | 7 | var banner = fmt.Sprintf(` 8 | 9 | ░ ░ ░ ░ ░ ░ ░ ░ ░ 10 | ░ ░ ░ ░ ░ ░ ▒ ░ ░ ▒ ░ 11 | ░░▒ ▒░ ░ ░ ▒ ▒░ ░ ▒ ▒░ ░ ░ ▒ ░ 12 | ░ ░▒ ▒ ░░ ▒░▒░▒░ ░ ▒░▒░▒░ ▒ ▒▒ ▓▒ 13 | ▄████▄ ▒█████ ▒█████ ██ ▄█▀ 14 | ▒██▀ ▀█ ▒██▒ ██▒▒██▒ ██▒ ██▄█▒ 15 | ▒▓█ ▄ ▒██░ ██▒▒██░ ██▒▓███▄░ 16 | ▒▓███▀ ░░ ████▓▒░░ ████▓▒░▒██▒ █▄ 17 | 18 | THE WORDLIST'S FRAMEWORK 19 | 20 | Version %s 21 | Gitesh Sharma @glitchedgitz 22 | `, version) 23 | -------------------------------------------------------------------------------- /v2/pkg/util/colors.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "os" 4 | 5 | // These are messed up, something is something else 6 | var ( 7 | Blue = "\u001b[38;5;45m" 8 | Grey = "\u001b[38;5;252m" 9 | Red = "\u001b[38;5;42m" 10 | White = "\u001b[38;5;255m" 11 | Background = "\u001b[48;5;239m" 12 | Reset = "\u001b[0m" 13 | Reverse = "\u001b[7m" 14 | ) 15 | 16 | // InitColors disables colors if --no-color flag or NO_COLOR env var is set 17 | func InitColors(noColor bool) { 18 | if noColor || os.Getenv("NO_COLOR") != "" { 19 | Blue = "" 20 | Grey = "" 21 | Red = "" 22 | White = "" 23 | Background = "" 24 | Reset = "" 25 | Reverse = "" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /v2/pkg/methods/leet.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "log" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | func (m *Methods) Leet(values []string, value string, array *[]string) { 10 | 11 | mode, err := strconv.Atoi(value) 12 | if err != nil { 13 | log.Fatalln("Err: Leet can be 0 or 1, usage: leet[0]") 14 | } 15 | 16 | for _, v := range values { 17 | var tmp = make(map[string]bool) 18 | v2 := v 19 | for l, ch := range m.LeetValues { 20 | for _, c := range ch { 21 | if strings.Contains(v, c) { 22 | t := strings.ReplaceAll(v, c, l) 23 | v2 = strings.ReplaceAll(v2, c, l) 24 | tmp[t] = true 25 | tmp[v2] = true 26 | } 27 | } 28 | } 29 | 30 | if mode == 0 { 31 | *array = append(*array, v2) 32 | } else { 33 | for k := range tmp { 34 | *array = append(*array, k) 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /v2/cmd/cook/vars.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/glitchedgitz/cook/v2/pkg/util" 8 | ) 9 | 10 | // cook [cmdFunctions] 11 | var cmdFunctions = map[string]func([]string){ 12 | "search": searchMode, 13 | "show": showMode, 14 | "help": helpMode, 15 | "add": addMode, 16 | "clean": cleanMode, 17 | "info": infoMode, 18 | "update": updateMode, 19 | "delete": deleteMode, 20 | } 21 | 22 | // cook help [helpFunctions] 23 | var helpFunctions = map[string]func(){ 24 | "methods": methHelp, 25 | "usage": usageHelp, 26 | "flags": flagsHelp, 27 | } 28 | 29 | func showConf() { 30 | // cook.CookConfig() 31 | 32 | fmt.Println(util.Blue + "\n CONFIG" + util.Reset) 33 | fmt.Printf(" Location: %v\n", COOK.Config.ConfigPath) 34 | fmt.Printf(util.Blue+"\n %-25s %s %s %s %s\n"+util.Reset, "FILE", "SETS", "VERN", "PREFIX", "REPO") 35 | fmt.Println(COOK.Config.ConfigInfo) 36 | 37 | os.Exit(0) 38 | } 39 | -------------------------------------------------------------------------------- /v2/pkg/methods/encode.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import "strconv" 4 | 5 | // Get Charcode of string 6 | func (m *Methods) Charcode(values []string, semicolon string, array *[]string) { 7 | addSemiColon := false 8 | if semicolon == "1" { 9 | addSemiColon = true 10 | } 11 | 12 | for _, str := range values { 13 | encoded := "" 14 | for _, s := range str { 15 | encoded += "&#" + strconv.Itoa(int(s)) 16 | if addSemiColon { 17 | encoded += ";" 18 | } 19 | } 20 | *array = append(*array, encoded) 21 | } 22 | } 23 | 24 | // func EnclosedAlphaNumeric(values []string, semicolon string, array *[]string) { 25 | // enclosedalphanum := "① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿ ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ ⒜ ⒝ ⒞ ⒟ ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ ⓪ ⓫ ⓬ ⓭ ⓮ ⓯ ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿" 26 | // alphanum:= 27 | // } 28 | -------------------------------------------------------------------------------- /v2/pkg/cook/search_test.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "testing" 7 | 8 | "gopkg.in/yaml.v3" 9 | ) 10 | 11 | func TestSearch(t *testing.T) { 12 | // TODO: Write test cases for the New function 13 | scenarios := []struct { 14 | search string 15 | }{ 16 | // Integer 17 | {"test"}, 18 | {"api"}, 19 | {"xss"}, 20 | {"tld"}, 21 | {"orange"}, 22 | } 23 | 24 | for i, scenario := range scenarios { 25 | t.Run(fmt.Sprintf("s%d:%s", i, scenario.search), func(t *testing.T) { 26 | fmt.Println() 27 | dashes := strings.Repeat("-", 49-len(scenario.search)) 28 | fmt.Printf("Search: %s %s\n", dashes, scenario.search) 29 | COOK := NewWithoutConfig() 30 | results, found := COOK.Search(scenario.search) 31 | if found { 32 | //Convert results object to yaml 33 | r, err := yaml.Marshal(results) 34 | if err != nil { 35 | t.Fatal("Error: ", err) 36 | } 37 | fmt.Println(string(r)) 38 | } else { 39 | fmt.Println("Not Found") 40 | } 41 | }) 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /v2/pkg/parse/syntax.go: -------------------------------------------------------------------------------- 1 | package parse 2 | 3 | import "strings" 4 | 5 | func SplitMethods(p string) []string { 6 | chars := strings.Split(p, "") 7 | s := []string{} 8 | tmp := "" 9 | insidebrackets := false 10 | for _, c := range chars { 11 | 12 | if c == "." { 13 | if !insidebrackets { 14 | s = append(s, tmp) 15 | tmp = "" 16 | continue 17 | } 18 | } 19 | if c == "[" { 20 | insidebrackets = true 21 | } 22 | if c == "]" { 23 | insidebrackets = false 24 | } 25 | tmp += c 26 | } 27 | s = append(s, tmp) 28 | return s 29 | } 30 | 31 | func SplitValues(p string) []string { 32 | chars := strings.Split(p, "") 33 | s := []string{} 34 | tmp := "" 35 | insideraw := false 36 | 37 | for _, c := range chars { 38 | 39 | if c == "," { 40 | if !insideraw { 41 | s = append(s, tmp) 42 | tmp = "" 43 | continue 44 | } 45 | } 46 | if c == "`" { 47 | if insideraw { 48 | insideraw = false 49 | } else { 50 | insideraw = true 51 | } 52 | } 53 | 54 | tmp += c 55 | } 56 | s = append(s, tmp) 57 | return s 58 | } 59 | -------------------------------------------------------------------------------- /v2/pkg/config/url.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "net/http" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | func URLValues(url string, array *[]string) { 12 | 13 | // Make an HTTP GET request to the URL 14 | response, err := http.Get(url) 15 | if err != nil { 16 | fmt.Println("Error:", err) 17 | os.Exit(1) 18 | } 19 | defer response.Body.Close() 20 | 21 | // Check if the status code is okay (e.g., 200) 22 | if response.StatusCode != http.StatusOK { 23 | fmt.Println("Error: HTTP status code", response.StatusCode) 24 | os.Exit(1) 25 | } 26 | 27 | // Create a bufio.Reader to read the response body 28 | scanner := bufio.NewScanner(response.Body) 29 | for scanner.Scan() { 30 | line := scanner.Text() 31 | line = strings.TrimRight(line, "\r") 32 | *array = append(*array, line) 33 | } 34 | // Read and print the body line by line 35 | // for { 36 | // line, err := reader.ReadString('\n') 37 | // if err != nil { 38 | // break 39 | // } 40 | // line = strings.TrimRight(line, "\n") 41 | // line = strings.TrimRight(line, "\r") 42 | // *array = append(*array, line) 43 | // } 44 | } 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Gitesh Sharma @glitchedgitz 4 | 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /v2/pkg/util/yaml.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | 7 | "gopkg.in/yaml.v3" 8 | ) 9 | 10 | func ReadFile(filepath string) []byte { 11 | content, err := ioutil.ReadFile(filepath) 12 | if err != nil { 13 | log.Fatalln("Err: Reading File ", filepath, err) 14 | } 15 | return content 16 | } 17 | 18 | func WriteFile(filepath string, data []byte) { 19 | err := ioutil.WriteFile(filepath, data, 0644) 20 | if err != nil { 21 | log.Fatalln("Err: Writing File ", filepath, err) 22 | } 23 | } 24 | 25 | func ReadYaml(filepath string, m map[string]map[string][]string) { 26 | 27 | content := ReadFile(filepath) 28 | 29 | err := yaml.Unmarshal([]byte(content), &m) 30 | if err != nil { 31 | log.Fatalf("Err: Parsing YAML %s %v", filepath, err) 32 | } 33 | } 34 | 35 | func WriteYaml(filepath string, m interface{}) { 36 | data, err := yaml.Marshal(&m) 37 | 38 | if err != nil { 39 | log.Fatal(err) 40 | } 41 | 42 | WriteFile(filepath, data) 43 | } 44 | 45 | func ReadInfoYaml(filepath string, m map[string][]string) { 46 | content := ReadFile(filepath) 47 | 48 | err := yaml.Unmarshal([]byte(content), &m) 49 | if err != nil { 50 | log.Fatalf("Err: Parsing YAML %s %v", filepath, err) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /v2/pkg/config/yaml.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "path" 5 | "path/filepath" 6 | "strings" 7 | ) 8 | 9 | func (conf *Config) checkFileSet(p string, array *[]string) bool { 10 | if files, exists := conf.Ingredients["files"][p]; exists { 11 | 12 | conf.CheckFileCache(p, files) 13 | FileValues(path.Join(conf.CachePath, p), array, conf.Peek) 14 | return true 15 | 16 | } else if files, exists := conf.Ingredients["raw-files"][p]; exists { 17 | 18 | tmp := make(map[string]bool) 19 | for _, file := range files { 20 | if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") { 21 | RawFileValues(path.Join(conf.ConfigPath, filepath.Base(file)), tmp) 22 | } else { 23 | RawFileValues(file, tmp) 24 | } 25 | } 26 | 27 | for k := range tmp { 28 | *array = append(*array, k) 29 | } 30 | return true 31 | 32 | } 33 | 34 | return false 35 | } 36 | 37 | func (conf *Config) CheckYaml(p string, array *[]string) bool { 38 | 39 | if val, exists := conf.Ingredients["lists"][p]; exists { 40 | if conf.Peek > 0 && len(val) > conf.Peek { 41 | *array = append(*array, val[:conf.Peek]...) 42 | } else { 43 | *array = append(*array, val...) 44 | } 45 | return true 46 | } 47 | 48 | if val, exists := conf.Ingredients["ports"][p]; exists { 49 | ParsePorts(val, array, conf.Peek) 50 | return true 51 | } 52 | 53 | if conf.checkFileSet(p, array) { 54 | return true 55 | } 56 | 57 | return false 58 | } 59 | -------------------------------------------------------------------------------- /v2/pkg/cook/output.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/glitchedgitz/cook/v2/pkg/config" 8 | "github.com/glitchedgitz/cook/v2/pkg/parse" 9 | ) 10 | 11 | func (cook *COOK) AppendMode(values []string) { 12 | tmp := []string{} 13 | till := len(cook.Final) 14 | if len(cook.Final) > len(values) { 15 | till = len(values) 16 | } 17 | for i := 0; i < till; i++ { 18 | tmp = append(tmp, cook.Final[i]+values[i]) 19 | } 20 | cook.Final = tmp 21 | } 22 | 23 | func (cook *COOK) PermutationMode(values []string) { 24 | tmp := []string{} 25 | for _, t := range cook.Final { 26 | for _, v := range values { 27 | tmp = append(tmp, t+v) 28 | } 29 | } 30 | cook.Final = tmp 31 | } 32 | 33 | func (cook *COOK) CheckParam(p string, array *[]string) bool { 34 | if val, exists := cook.Params[p]; exists { 35 | if config.PipeInput(val, array) || config.RawInput(val, array) || RepeatOp(val, array) || cook.Config.ParseFunc(val, array) || cook.Config.ParseFile(p, val, array) || cook.CheckMethods(val, array) { 36 | return true 37 | } 38 | 39 | *array = append(*array, parse.SplitValues(val)...) 40 | return true 41 | } 42 | return false 43 | } 44 | 45 | func (cook *COOK) Print() { 46 | 47 | if !cook.PrintResult { 48 | return 49 | } 50 | 51 | if len(cook.MethodsForAll) > 0 { 52 | tmp := []string{} 53 | 54 | for _, meth := range strings.Split(cook.MethodsForAll, ",") { 55 | cook.ApplyMethods(cook.Final, parse.SplitMethods(meth), &tmp) 56 | } 57 | for _, v := range tmp { 58 | fmt.Println(v) 59 | } 60 | } else { 61 | for _, v := range cook.Final { 62 | fmt.Println(v) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /v2/pkg/methods/strings.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "log" 5 | "sort" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | func (m *Methods) Sort(values []string, useless string, array *[]string) { 11 | sort.Strings(values) 12 | *array = append(*array, values...) 13 | } 14 | 15 | func (m *Methods) SortUnique(values []string, useless string, array *[]string) { 16 | 17 | tmp := make(map[string]bool) 18 | 19 | sort.Strings(values) 20 | 21 | for _, v := range values { 22 | if tmp[v] { 23 | continue 24 | } 25 | 26 | tmp[v] = true 27 | *array = append(*array, v) 28 | } 29 | } 30 | 31 | func (m *Methods) Reverse(values []string, useless string, array *[]string) { 32 | for _, v := range values { 33 | runes := []rune(v) 34 | for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { 35 | runes[i], runes[j] = runes[j], runes[i] 36 | } 37 | 38 | *array = append(*array, string(runes)) 39 | } 40 | } 41 | 42 | func (m *Methods) Replace(values []string, value string, array *[]string) { 43 | s := strings.SplitN(value, ":", 2) 44 | replaceText := s[0] 45 | replaceWith := s[1] 46 | for _, v := range values { 47 | *array = append(*array, strings.ReplaceAll(v, replaceText, replaceWith)) 48 | } 49 | } 50 | 51 | func (m *Methods) Split(values []string, split string, array *[]string) { 52 | for _, v := range values { 53 | *array = append(*array, strings.Split(v, split)...) 54 | } 55 | } 56 | 57 | func (m *Methods) SplitIndex(values []string, value string, array *[]string) { 58 | 59 | vals := strings.Split(value, ":") 60 | split := strings.Join(vals[:len(vals)-1], ":") 61 | index, err := strconv.Atoi(vals[len(vals)-1]) 62 | 63 | if err != nil { 64 | log.Fatalln("Not Integer Value: "+values[1], err) 65 | } 66 | 67 | for _, v := range values { 68 | vv := strings.Split(v, split) 69 | if len(vv) >= index+1 { 70 | *array = append(*array, vv[index]) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /v2/pkg/cook/repeat.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | ) 7 | 8 | const ( 9 | RepeatRangeOp = "-" 10 | RepeatHorizontalOp = "*" 11 | RepeatVerticalOp = "**" 12 | ) 13 | 14 | func RepeatOp(value string, array *[]string) bool { 15 | 16 | getRange := func(looprange string) (int, int, bool) { 17 | t := strings.Split(looprange, RepeatRangeOp) 18 | 19 | start, err := strconv.Atoi(t[0]) 20 | if err != nil { 21 | return 0, 0, false 22 | } 23 | 24 | stop, err := strconv.Atoi(t[1]) 25 | if err != nil { 26 | return 0, 0, false 27 | } 28 | 29 | if start == stop { 30 | return 0, 0, false 31 | } 32 | 33 | return start, stop, true 34 | } 35 | 36 | if strings.Count(value, RepeatVerticalOp) >= 1 { 37 | s := strings.Split(value, RepeatVerticalOp) 38 | input := strings.Join(s[:len(s)-1], RepeatVerticalOp) 39 | last := s[len(s)-1] 40 | till, err := strconv.Atoi(last) 41 | if err == nil { 42 | for i := 0; i < till; i++ { 43 | *array = append(*array, input) 44 | } 45 | return true 46 | } 47 | } 48 | 49 | if strings.Count(value, RepeatHorizontalOp) >= 1 { 50 | s := strings.Split(value, RepeatHorizontalOp) 51 | 52 | input := strings.Join(s[:len(s)-1], RepeatHorizontalOp) 53 | last := s[len(s)-1] 54 | 55 | if strings.Count(last, RepeatRangeOp) == 1 { 56 | start, stop, chk := getRange(last) 57 | if !chk { 58 | return false 59 | } 60 | 61 | if start < stop { 62 | for i := start; i <= stop; i++ { 63 | *array = append(*array, strings.Repeat(input, i)) 64 | } 65 | } else { 66 | for i := start; i >= stop; i-- { 67 | *array = append(*array, strings.Repeat(input, i)) 68 | } 69 | } 70 | return true 71 | } 72 | 73 | times, err := strconv.Atoi(last) 74 | if err != nil { 75 | return false 76 | } 77 | 78 | *array = append(*array, strings.Repeat(input, times)) 79 | 80 | return true 81 | } 82 | 83 | return false 84 | } 85 | -------------------------------------------------------------------------------- /v2/pkg/methods/smart.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | func (m *Methods)SmartWords(words []string, useless string, array *[]string) { 8 | for _, word := range words { 9 | str := []string{} 10 | 11 | if strings.Contains(word, "_") { 12 | str = strings.Split(word, "_") 13 | 14 | } else if strings.Contains(word, "-") { 15 | str = strings.Split(word, "-") 16 | 17 | } else { 18 | 19 | j := 0 20 | for i, letter := range word { 21 | if letter > 'A' && letter < 'Z' { 22 | str = append(str, word[j:i]) 23 | j = i 24 | } 25 | } 26 | str = append(str, word[j:]) 27 | } 28 | 29 | *array = append(*array, str...) 30 | } 31 | } 32 | 33 | func (m *Methods) SmartWordsJoin(words []string, values string, array *[]string) { 34 | 35 | vals := strings.SplitN(values, ":", 2) 36 | applyCase := strings.ToLower(vals[0]) 37 | joinWith := vals[1] 38 | 39 | fn1 := func(s string) string { 40 | return s 41 | } 42 | fn2 := fn1 43 | 44 | caseMap := map[string]func(string) string{ 45 | "l": strings.ToLower, 46 | "u": strings.ToUpper, 47 | "t": strings.Title, 48 | "c": strings.Title, 49 | } 50 | if _, exists := caseMap[applyCase]; exists { 51 | fn2 = caseMap[applyCase] 52 | fn1 = caseMap[applyCase] 53 | } 54 | if applyCase == "c" { 55 | fn1 = strings.ToLower 56 | } 57 | 58 | for _, word := range words { 59 | str := []string{} 60 | 61 | if strings.Contains(word, "_") { 62 | str = strings.Split(word, "_") 63 | 64 | } else if strings.Contains(word, "-") { 65 | str = strings.Split(word, "-") 66 | 67 | } else { 68 | 69 | j := 0 70 | for i, letter := range word { 71 | if letter > 'A' && letter < 'Z' { 72 | str = append(str, word[j:i]) 73 | j = i 74 | } 75 | } 76 | str = append(str, word[j:]) 77 | } 78 | 79 | str[0] = fn1(str[0]) 80 | for i, word := range str[1:] { 81 | str[i+1] = fn2(word) 82 | } 83 | *array = append(*array, strings.Join(str, joinWith)) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /v2/pkg/cook/search.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type CookIngredient struct { 8 | // keyword name 9 | Name string `json:"name"` 10 | 11 | // Type: files, raw-files, functions, sets, etc 12 | Type string `json:"type"` 13 | 14 | // Path: only for files and raw-files, otherwise empty 15 | Path string `json:"path"` 16 | 17 | // Content 18 | // - For files and raw-files it will be `links` 19 | // - For functions it will be permutatons 20 | // - For sets it will be the wordsets 21 | // - For ports it will be the ports 22 | Content []string `json:"content"` 23 | } 24 | 25 | func (cook *COOK) Search(search string) ([]CookIngredient, bool) { 26 | found := false 27 | // convert the below fucntion to as data to map 28 | var searches = []CookIngredient{} 29 | 30 | for category, item := range cook.Config.Ingredients { 31 | for keyword, content := range item { 32 | 33 | keyword = strings.ToLower(keyword) 34 | keyword = strings.TrimSpace(keyword) 35 | 36 | if category == "files" || category == "raw-files" { 37 | link := "" 38 | if strings.HasPrefix(content[0], "https://raw.githubusercontent.com") { 39 | path := strings.Split(content[0], "/")[4:] 40 | link = strings.ToTitle(path[0]) + " > " + strings.Join(path[2:len(path)-1], " > ") 41 | } else { 42 | d := strings.TrimPrefix(content[0], "http://") 43 | d = strings.TrimPrefix(d, "https://") 44 | link = d 45 | // link = strings.Join(strings.Split(d, "/"), " > ") 46 | } 47 | 48 | if strings.Contains(strings.ToLower(link+keyword), search) { 49 | link = strings.ToLower(link) 50 | searches = append(searches, 51 | CookIngredient{ 52 | Name: keyword, 53 | Type: category, 54 | Path: link, 55 | Content: content, 56 | }, 57 | ) 58 | found = true 59 | } 60 | } else { 61 | if strings.Contains(keyword, search) { 62 | searches = append(searches, 63 | CookIngredient{ 64 | Name: keyword, 65 | Type: category, 66 | Path: "", 67 | Content: content, 68 | }, 69 | ) 70 | found = true 71 | } 72 | } 73 | } 74 | } 75 | 76 | return searches, found 77 | } 78 | -------------------------------------------------------------------------------- /v2/pkg/cook/run.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/glitchedgitz/cook/v2/pkg/config" 7 | "github.com/glitchedgitz/cook/v2/pkg/parse" 8 | ) 9 | 10 | func (cook *COOK) CurrentStage() { 11 | fmt.Println("Config----") 12 | fmt.Print("\tConfigPath: ", cook.Config.ConfigPath, "\n") 13 | fmt.Print("\tIngredientsPath: ", cook.Config.IngredientsPath, "\n") 14 | fmt.Print("\tCachePath: ", cook.Config.CachePath, "\n") 15 | // fmt.Println("cook.Config.Ingredients: ", cook.Config.Ingredients) 16 | // fmt.Println("cook.checkM: ", cook.Config.Ingredients) 17 | 18 | fmt.Println("Vars----") 19 | fmt.Print("\tPattern: ", cook.Pattern, "\n") 20 | fmt.Print("\tParams: ", cook.Params, "\n") 21 | fmt.Print("\tMin: ", cook.Min, "\n") 22 | fmt.Print("\tMethodParam: ", cook.MethodParam, "\n") 23 | fmt.Print("\tMethodsForAll: ", cook.MethodsForAll, "\n") 24 | fmt.Print("\tAppendParam: ", cook.AppendParam, "\n") 25 | fmt.Print("\tMethodMap: ", cook.MethodMap, "\n") 26 | fmt.Print("\tAppendMap: ", cook.AppendMap, "\n") 27 | fmt.Print("\tFinal: ", cook.Final, "\n") 28 | fmt.Print("\tTotalCols: ", cook.TotalCols, "\n") 29 | } 30 | 31 | func (cook *COOK) Generate() { 32 | for columnNum, param := range cook.Pattern { 33 | 34 | columnValues := []string{} 35 | 36 | for _, p := range parse.SplitValues(param) { 37 | if config.RawInput(p, &columnValues) || config.ParseRanges(p, &columnValues, cook.Config.Peek) || RepeatOp(p, &columnValues) || cook.CheckMethods(p, &columnValues) || cook.CheckParam(p, &columnValues) || cook.Config.CheckYaml(p, &columnValues) { 38 | continue 39 | } 40 | columnValues = append(columnValues, p) 41 | } 42 | 43 | // config.VPrint(fmt.Sprintf("%-40s: %s", "Time after getting values", time.Since(start))) 44 | 45 | if mapval, exists := cook.MethodMap[columnNum]; exists { 46 | tmp := []string{} 47 | cook.ApplyMethods(columnValues, mapval, &tmp) 48 | columnValues = tmp 49 | } 50 | 51 | if !cook.AppendMap[columnNum] || columnNum == 0 { 52 | cook.PermutationMode(columnValues) 53 | } else { 54 | cook.AppendMode(columnValues) 55 | } 56 | 57 | // config.VPrint(fmt.Sprintf("%-40s: %s", "Time ApplyColumnCases", time.Since(start))) 58 | 59 | if columnNum >= cook.Min { 60 | cook.Print() 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /v2/pkg/config/update.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "log" 7 | "path" 8 | 9 | "github.com/glitchedgitz/cook/v2/pkg/util" 10 | "gopkg.in/yaml.v3" 11 | ) 12 | 13 | func (conf *Config) getLocalFile(m map[string][]string) { 14 | // if len(os.Getenv("COOK")) > 0 { 15 | // ConfigFolder = os.Getenv("COOK") 16 | // } 17 | 18 | localfile := path.Join(conf.ConfigPath, "info.yaml") 19 | util.ReadInfoYaml(localfile, m) 20 | } 21 | 22 | func (conf *Config) getRepoFile(m map[string][]string) { 23 | content := conf.GetData("https://raw.githubusercontent.com/glitchedgitz/cook-ingredients/main/info.yaml") 24 | 25 | err := yaml.Unmarshal([]byte(content), &m) 26 | if err != nil { 27 | log.Fatalf("Err: Parsing YAML %s %v", "https://raw.githubusercontent.com/glitchedgitz/cook-ingredients/main/info.yaml", err) 28 | } 29 | } 30 | 31 | func (conf *Config) getConfigFiles(m map[string]bool) { 32 | files, err := ioutil.ReadDir(conf.ConfigPath) 33 | if err != nil { 34 | panic(err) 35 | } 36 | for _, file := range files { 37 | m[file.Name()] = true 38 | } 39 | } 40 | 41 | // Updating yaml file 42 | func (conf *Config) updateFile(file string) { 43 | // fmt.Println("Updating : ", file) 44 | defer conf.wg.Done() 45 | content := conf.GetData("https://raw.githubusercontent.com/glitchedgitz/cook-ingredients/main/" + file) 46 | localFile := path.Join(conf.ConfigPath, file) 47 | util.WriteFile(localFile, content) 48 | } 49 | 50 | // Updating cook's database 51 | func (conf *Config) UpdateDb() { 52 | var local = make(map[string][]string) 53 | var repo = make(map[string][]string) 54 | var files = make(map[string]bool) 55 | var updatedFiles = 0 56 | 57 | conf.getLocalFile(local) 58 | conf.getRepoFile(repo) 59 | conf.getConfigFiles(files) 60 | 61 | for file, values := range repo { 62 | version := values[0] 63 | if localv, exists := local[file]; exists { 64 | if version > localv[0] { 65 | conf.wg.Add(1) 66 | go conf.updateFile(file) 67 | updatedFiles++ 68 | } 69 | } else if files[file] { 70 | log.Fatalf("\nErr: Please rename the file '%s' because cook-ingredients has new file with the same name.\n", file) 71 | } else { 72 | conf.wg.Add(1) 73 | fmt.Println("\nAdding new file :)") 74 | go conf.updateFile(file) 75 | updatedFiles++ 76 | } 77 | } 78 | 79 | if updatedFiles > 0 { 80 | conf.wg.Add(1) 81 | go conf.updateFile("info.yaml") 82 | } else { 83 | fmt.Println("\nEverything is updated :)") 84 | } 85 | 86 | conf.wg.Wait() 87 | } 88 | -------------------------------------------------------------------------------- /v2/pkg/cook/methods.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "strings" 8 | 9 | "github.com/adrg/strutil" 10 | "github.com/adrg/strutil/metrics" 11 | "github.com/glitchedgitz/cook/v2/pkg/parse" 12 | ) 13 | 14 | func (cook *COOK) ApplyMethods(vallll []string, meths []string, array *[]string) { 15 | tmp := []string{} 16 | analyseMethods := [][]string{} 17 | 18 | for _, g := range meths { 19 | if strings.Contains(g, "[") { 20 | name, value := parse.ReadSqBr(g) 21 | analyseMethods = append(analyseMethods, []string{strings.ToLower(name), value}) 22 | } else { 23 | analyseMethods = append(analyseMethods, []string{strings.ToLower(g), ""}) 24 | } 25 | } 26 | 27 | for _, v := range analyseMethods { 28 | f := v[0] 29 | value := v[1] 30 | if fn, exists := cook.Method.MethodFuncs[f]; exists { 31 | fn(vallll, value, &tmp) 32 | } else if fn, exists := cook.Method.UrlFuncs[f]; exists { 33 | cook.Method.AnalyzeURLs(vallll, fn, &tmp) 34 | } else if e, exists := cook.Method.EncodersFuncs[f]; exists { 35 | for _, v := range vallll { 36 | output, err := e.Encode([]byte(v)) 37 | if err != nil { 38 | log.Fatalln("Err") 39 | } 40 | tmp = append(tmp, string(output)) 41 | } 42 | } else { 43 | fmt.Fprintf(os.Stderr, "\nMethod \"%s\" Doesn't exists\n", f) 44 | cook.MistypedCheck(f) 45 | os.Exit(0) 46 | } 47 | vallll = tmp 48 | tmp = nil 49 | } 50 | 51 | *array = append(*array, vallll...) 52 | } 53 | 54 | func (cook *COOK) MistypedCheck(mistyped string) { 55 | fmt.Fprintln(os.Stderr) 56 | 57 | fmt.Fprintln(os.Stderr, "Similar Methods") 58 | found := false 59 | check := func(k string) { 60 | similarity := strutil.Similarity(mistyped, k, metrics.NewHamming()) 61 | if similarity >= 0.3 { 62 | fmt.Println("-", k) 63 | found = true 64 | } 65 | } 66 | 67 | for k := range cook.Method.MethodFuncs { 68 | check(k) 69 | } 70 | 71 | for k := range cook.Method.UrlFuncs { 72 | check(k) 73 | } 74 | 75 | for k := range cook.Method.EncodersFuncs { 76 | check(k) 77 | } 78 | 79 | if !found { 80 | fmt.Fprintln(os.Stderr, "None") 81 | } 82 | 83 | } 84 | 85 | func (cook *COOK) CheckMethods(p string, array *[]string) bool { 86 | if strings.Count(p, ".") > 0 { 87 | splitS := parse.SplitMethods(p) 88 | u := splitS[0] 89 | if _, exists := cook.Params[u]; exists { 90 | 91 | vallll := []string{} 92 | 93 | if !cook.CheckParam(u, &vallll) && !cook.Config.CheckYaml(u, &vallll) { 94 | return false 95 | } 96 | 97 | cook.ApplyMethods(vallll, splitS[1:], array) 98 | 99 | return true 100 | } 101 | 102 | } 103 | return false 104 | } 105 | -------------------------------------------------------------------------------- /v2/pkg/cook/cook_test.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | func compareTwoArrays(a, b []string) bool { 10 | if len(a) != len(b) { 11 | return false 12 | } 13 | 14 | for i, v := range a { 15 | if v != b[i] { 16 | return false 17 | } 18 | } 19 | 20 | return true 21 | } 22 | 23 | func TestNew(t *testing.T) { 24 | // TODO: Write test cases for the New function 25 | scenarios := []struct { 26 | pattern []string 27 | expectedResult []string 28 | expectedError bool 29 | }{ 30 | // Integer 31 | {[]string{"test"}, []string{"test"}, false}, 32 | {[]string{"a,b,c"}, []string{"a", "b", "c"}, false}, 33 | {[]string{"a,b,c"}, []string{"a", "b", "d"}, true}, 34 | {[]string{"a,b,c", "1,2,3"}, []string{"a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"}, false}, 35 | 36 | //Repeat Operators 37 | {[]string{"r**5"}, []string{"r", "r", "r", "r", "r"}, false}, 38 | {[]string{"r*5"}, []string{"rrrrr"}, false}, 39 | 40 | // Ranges 41 | {[]string{"1-5"}, []string{"1", "2", "3", "4", "5"}, false}, 42 | {[]string{"a-z"}, []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}, false}, 43 | {[]string{"1-5", "a,b,c"}, []string{"1a", "1b", "1c", "2a", "2b", "2c", "3a", "3b", "3c", "4a", "4b", "4c", "5a", "5b", "5c"}, false}, 44 | 45 | // Wordlist 46 | {[]string{"sec-amazon-api-gateway.txt"}, []string{"AmazonAPIGateway_5m3r4dmaP1", "AmazonAPIGateway_6qpee1cnq6"}, false}, 47 | 48 | // Params 49 | {[]string{"-p", "test,vest", "p"}, []string{"test", "vest"}, false}, 50 | 51 | // File params 52 | {[]string{"-f:", "../../../test_file/test.txt", "f"}, []string{"line1", "line2", "line3", "line4"}, false}, 53 | } 54 | 55 | for i, scenario := range scenarios { 56 | t.Run(fmt.Sprintf("s%d:%s", i, scenario.pattern), func(t *testing.T) { 57 | fmt.Printf("\nScenario: ------------------------------------------ %d\n", i) 58 | COOK := New(&COOK{ 59 | Pattern: scenario.pattern, 60 | }) 61 | COOK.Generate() 62 | fmt.Printf("Given Pattern: %v\n", strings.Join(scenario.pattern, " ")) 63 | fmt.Printf("Generated Pattern: %v\n", COOK.Final) 64 | fmt.Printf("Expected Pattern: %v\n", scenario.expectedResult) 65 | fmt.Printf("Expected Error: %v\n", scenario.expectedError) 66 | 67 | areSame := compareTwoArrays(COOK.Final, scenario.expectedResult) 68 | 69 | if !scenario.expectedError && !areSame { 70 | t.Fatalf("For Pattern %v Expected %v, got %v", scenario.pattern, scenario.expectedResult, COOK.Final) 71 | } 72 | if scenario.expectedError && areSame { 73 | t.Fatalf("For Pattern %v Expected %v, got %v", scenario.pattern, scenario.expectedResult, COOK.Final) 74 | } 75 | }) 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /v2/cmd/cook/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "time" 8 | 9 | "github.com/glitchedgitz/cook/v2/pkg/config" 10 | "github.com/glitchedgitz/cook/v2/pkg/cook" 11 | "github.com/glitchedgitz/cook/v2/pkg/parse" 12 | "github.com/glitchedgitz/cook/v2/pkg/util" 13 | ) 14 | 15 | var COOK *cook.COOK 16 | var configPath string 17 | var total = 0 18 | 19 | // Initializing with empty string, so loops will run for 1st column 20 | var start = time.Now() 21 | 22 | // Flags 23 | var ( 24 | help bool 25 | verbose bool 26 | showCol bool 27 | min int 28 | peek int 29 | methodParam string 30 | methodsForAll string 31 | appendParam string 32 | showConfig bool 33 | reConfigure bool 34 | noColor bool 35 | ) 36 | 37 | func main() { 38 | parseFlags := parse.NewParse() 39 | parseFlags.Help = banner 40 | // cook.Verbose = verbose 41 | help = parseFlags.Boolean("-h", "-help") 42 | verbose = parseFlags.Boolean("-v", "-verbose") 43 | showCol = parseFlags.Boolean("-c", "-col") 44 | min = parseFlags.Integer("-min", "-min") 45 | peek = parseFlags.Integer("-peek", "-peek") 46 | methodParam = parseFlags.String("-mc", "-methodcol") 47 | methodsForAll = parseFlags.String("-m", "-method") 48 | appendParam = parseFlags.String("-a", "-append") 49 | showConfig = parseFlags.Boolean("-conf", "-config") 50 | reConfigure = parseFlags.Boolean("-reconfigure", "-reconf") 51 | configPath = parseFlags.String("-config-path", "-config-path") 52 | noColor = parseFlags.Boolean("-no-color", "-nocolor") 53 | parseFlags.Parse() 54 | 55 | util.InitColors(noColor) 56 | 57 | if !verbose { 58 | log.SetFlags(0) 59 | } 60 | 61 | if help { 62 | // terminate after showing help 63 | showHelp() 64 | } 65 | 66 | if showConfig { 67 | // terminate after showing config 68 | showConf() 69 | } 70 | 71 | if len(os.Getenv("COOK")) > 0 { 72 | configPath = os.Getenv("COOK") 73 | } 74 | 75 | COOK = cook.New(&cook.COOK{ 76 | Config: &config.Config{ 77 | ConfigPath: configPath, 78 | ReConfigure: reConfigure, 79 | Verbose: verbose, 80 | Peek: peek, 81 | }, 82 | Pattern: parseFlags.Args, 83 | Min: min, 84 | AppendParam: appendParam, 85 | MethodParam: methodParam, 86 | MethodsForAll: methodsForAll, 87 | PrintResult: true, 88 | }) 89 | 90 | if showCol { 91 | COOK.ShowCols() 92 | } 93 | 94 | if COOK.TotalCols > 0 { 95 | if fn, exists := cmdFunctions[COOK.Pattern[0]]; exists { 96 | fn(COOK.Pattern[1:]) 97 | os.Exit(0) 98 | } 99 | } 100 | 101 | VPrint(fmt.Sprintf("Pattern: %v \n", COOK.Pattern)) 102 | // COOK.CurrentStage() 103 | COOK.Generate() 104 | 105 | if verbose { 106 | COOK.CurrentStage() 107 | } 108 | 109 | VPrint(fmt.Sprintf("%-40s: %s", "Elapsed Time", time.Since(start))) 110 | VPrint(fmt.Sprintf("%-40s: %d", "Total words generated", total)) 111 | } 112 | -------------------------------------------------------------------------------- /v2/pkg/config/file.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "bufio" 5 | "log" 6 | "os" 7 | "path/filepath" 8 | "regexp" 9 | "strings" 10 | 11 | "github.com/glitchedgitz/cook/v2/pkg/util" 12 | ) 13 | 14 | func AddFilesToArray(value string, array *[]string) { 15 | tmp := make(map[string]bool) 16 | RawFileValues(value, tmp) 17 | for k := range tmp { 18 | *array = append(*array, k) 19 | } 20 | } 21 | 22 | func FileValues(pattern string, array *[]string, peek int) { 23 | files, err := filepath.Glob(pattern) 24 | if err != nil { 25 | log.Fatalln("Err: In pattern ", err) 26 | } 27 | for _, file := range files { 28 | ReadFile, err := os.Open(file) 29 | 30 | if err != nil { 31 | log.Fatalln("Err: Opening File ", file) 32 | } 33 | 34 | defer ReadFile.Close() 35 | 36 | fileScanner := bufio.NewScanner(ReadFile) 37 | 38 | for fileScanner.Scan() { 39 | line := fileScanner.Text() 40 | line = strings.TrimRight(line, "\r") 41 | *array = append(*array, line) 42 | if peek > 0 { 43 | peek-- 44 | if peek == 0 { 45 | break 46 | } 47 | } 48 | } 49 | 50 | if err := fileScanner.Err(); err != nil { 51 | log.Fatal(err) 52 | } 53 | 54 | } 55 | } 56 | 57 | func RawFileValues(pattern string, allLines map[string]bool) { 58 | files, err := filepath.Glob(pattern) 59 | if err != nil { 60 | log.Fatalln("Err: In pattern ", err) 61 | } 62 | for _, file := range files { 63 | ReadFile, err := os.Open(file) 64 | 65 | if err != nil { 66 | log.Fatalln("Err: Opening File ", file) 67 | } 68 | 69 | defer ReadFile.Close() 70 | 71 | fileScanner := bufio.NewScanner(ReadFile) 72 | 73 | for fileScanner.Scan() { 74 | line := fileScanner.Text() 75 | line = strings.TrimRight(line, "\n") 76 | line = strings.TrimRight(line, "\r") 77 | if allLines[line] { 78 | continue 79 | } 80 | allLines[line] = true 81 | } 82 | if err := fileScanner.Err(); err != nil { 83 | log.Fatal(err) 84 | } 85 | } 86 | } 87 | 88 | func FindRegex(data []byte, expresssion string, array *[]string) { 89 | 90 | r, err := regexp.Compile(expresssion) 91 | if err != nil { 92 | log.Fatalln(err) 93 | } 94 | 95 | e := make(map[string]bool) 96 | 97 | // replacing \r (carriage return) as it puts cursor on beginning of line 98 | for _, found := range r.FindAllString(strings.ReplaceAll(string(data), "\r", ""), -1) { 99 | if e[found] { 100 | continue 101 | } 102 | e[found] = true 103 | *array = append(*array, found) 104 | } 105 | } 106 | 107 | func (conf *Config) FileRegex(file string, expresssion string, array *[]string) { 108 | FindRegex(util.ReadFile(file), expresssion, array) 109 | } 110 | 111 | func (conf *Config) RawFileRegex(files []string, expresssion string, array *[]string) { 112 | for _, file := range files { 113 | if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") { 114 | FindRegex(conf.GetData(file), expresssion, array) 115 | } else { 116 | conf.FileRegex(file, expresssion, array) 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /v2/pkg/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "path" 8 | "strings" 9 | 10 | "github.com/glitchedgitz/cook/v2/pkg/util" 11 | "gopkg.in/yaml.v3" 12 | ) 13 | 14 | // First Run 15 | func (conf *Config) FirstRun() { 16 | 17 | fmt.Fprintln(os.Stderr, "First Run") 18 | fmt.Fprintln(os.Stderr, "Creating and Downloading Cook's Ingredients...\n\n ") 19 | 20 | err := os.MkdirAll(conf.ConfigPath, os.ModePerm) 21 | if err != nil { 22 | log.Fatalln(err) 23 | } 24 | 25 | err = os.MkdirAll(conf.IngredientsPath, os.ModePerm) 26 | if err != nil { 27 | log.Fatalln(err) 28 | } 29 | 30 | err = os.MkdirAll(conf.CachePath, os.ModePerm) 31 | if err != nil { 32 | log.Fatalln(err) 33 | } 34 | 35 | structure := make(map[string][]string) 36 | err = yaml.Unmarshal([]byte(conf.GetData("https://raw.githubusercontent.com/glitchedgitz/cook-ingredients/main/structure")), &structure) 37 | if err != nil { 38 | log.Fatalf("Err: Parsing YAML %v", err) 39 | } 40 | 41 | for _, v := range structure["infofiles"] { 42 | filename := path.Base(v) 43 | fmt.Fprint(os.Stderr, "\rDownloading \r", filename) 44 | util.WriteFile(path.Join(conf.ConfigPath, filename), conf.GetData(v)) 45 | } 46 | for _, v := range structure["yamlfiles"] { 47 | filename := path.Base(v) 48 | fmt.Fprint(os.Stderr, "\rDownloading \r", filename) 49 | util.WriteFile(path.Join(conf.IngredientsPath, filename), conf.GetData(v)) 50 | } 51 | fmt.Fprint(os.Stderr, "\rDone \r") 52 | 53 | } 54 | 55 | func (conf *Config) CookConfig() { 56 | 57 | if conf.ReConfigure || !util.Exists(conf.ConfigPath) { 58 | fmt.Println("First Run") 59 | conf.FirstRun() 60 | } 61 | 62 | files, err := os.ReadDir(conf.IngredientsPath) 63 | if err != nil { 64 | log.Fatalln(err) 65 | } 66 | 67 | wholeTotal := 0 68 | totalFiles := 0 69 | 70 | var local = make(map[string][]string) 71 | conf.getLocalFile(local) 72 | 73 | conf.Ingredients = make(map[string]map[string][]string) 74 | conf.CheckIngredients = make(map[string][]string) 75 | 76 | for _, file := range files { 77 | var m = make(map[string]map[string][]string) 78 | 79 | filename := file.Name() 80 | 81 | prefix := "" 82 | configRows := "" 83 | if val, exists := local[filename]; exists { 84 | 85 | v, p, r := val[0], val[1], val[2] 86 | if p != "" { 87 | prefix = p + "-" 88 | } 89 | 90 | configRows = fmt.Sprintf("%-4s %-6s %s", v, p, r) 91 | } 92 | 93 | util.ReadYaml(path.Join(conf.IngredientsPath, filename), m) 94 | 95 | total := 0 96 | for k, v := range m { 97 | if _, exists := conf.Ingredients[k]; !exists { 98 | conf.Ingredients[k] = make(map[string][]string) 99 | } 100 | 101 | for kk, vv := range v { 102 | conf.Ingredients[k][prefix+strings.ToLower(kk)] = vv 103 | total++ 104 | } 105 | } 106 | wholeTotal += total 107 | totalFiles++ 108 | // Temporary Commented 109 | conf.ConfigInfo += fmt.Sprintf(" %-25s %-8d %s\n", filename, total, configRows) 110 | } 111 | 112 | conf.ConfigInfo += fmt.Sprintf("\n %-25s %d\n", "TOTAL FILES", totalFiles) 113 | conf.ConfigInfo += fmt.Sprintf(" %-25s %d\n", "TOTAL WORDLISTS SET", wholeTotal) 114 | 115 | util.ReadInfoYaml(path.Join(conf.ConfigPath, "check.yaml"), conf.CheckIngredients) 116 | } 117 | -------------------------------------------------------------------------------- /v2/pkg/config/cache.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "net/http" 9 | "os" 10 | "path" 11 | "sync" 12 | 13 | "github.com/glitchedgitz/cook/v2/pkg/util" 14 | ) 15 | 16 | // Return data from url 17 | func (conf *Config) GetData(url string) []byte { 18 | conf.VPrint(fmt.Sprintf("GetData(): Fetching %s\n", url)) 19 | 20 | res, err := http.Get(url) 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | 25 | data, _ := ioutil.ReadAll(res.Body) 26 | 27 | res.Body.Close() 28 | return data 29 | } 30 | 31 | func (conf *Config) makeCacheFolder() { 32 | err := os.MkdirAll(conf.CachePath, os.ModePerm) 33 | if err != nil { 34 | log.Fatalln("Err: Making .cache folder in HOME/USERPROFILE ", err) 35 | } 36 | } 37 | 38 | // Checking if file's cache present 39 | func (conf *Config) CheckFileCache(filename string, files []string) { 40 | 41 | conf.makeCacheFolder() 42 | filepath := path.Join(conf.CachePath, filename) 43 | 44 | if _, e := os.Stat(filepath); e != nil { 45 | fmt.Fprintf(os.Stderr, "Creating cache for %s\n", filename) 46 | var tmp = make(map[string]bool) 47 | f, err := os.OpenFile(filepath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) 48 | if err != nil { 49 | log.Fatal("Creating File: ", err) 50 | } 51 | 52 | defer f.Close() 53 | 54 | for _, file := range files { 55 | fmt.Fprintf(os.Stderr, "Fetching %s\n", file) 56 | 57 | res, err := http.Get(file) 58 | 59 | if err != nil { 60 | log.Fatal("Getting Data", err) 61 | } 62 | 63 | defer res.Body.Close() 64 | 65 | fileScanner := bufio.NewScanner(res.Body) 66 | 67 | for fileScanner.Scan() { 68 | line := fileScanner.Text() 69 | if tmp[line] { 70 | continue 71 | } 72 | tmp[line] = true 73 | if _, err = f.WriteString(fileScanner.Text() + "\n"); err != nil { 74 | log.Fatalf("Writing File: %v", err) 75 | } 76 | } 77 | 78 | if err := fileScanner.Err(); err != nil { 79 | log.Fatalf("FileScanner: %v", err) 80 | } 81 | } 82 | conf.CheckIngredients[filename] = files 83 | util.WriteYaml(path.Join(conf.ConfigPath, "check.yaml"), conf.CheckIngredients) 84 | 85 | } else { 86 | 87 | chkfiles := conf.CheckIngredients[filename] 88 | if len(files) != len(chkfiles) { 89 | os.Remove(filepath) 90 | conf.CheckFileCache(filename, files) 91 | util.WriteYaml(path.Join(conf.ConfigPath, "check.yaml"), conf.CheckIngredients) 92 | return 93 | } 94 | for i, v := range chkfiles { 95 | if v != files[i] { 96 | os.Remove(filepath) 97 | conf.CheckFileCache(filename, files) 98 | util.WriteYaml(path.Join(conf.ConfigPath, "check.yaml"), conf.CheckIngredients) 99 | break 100 | } 101 | } 102 | } 103 | } 104 | 105 | func (conf *Config) UpdateCache() { 106 | 107 | type filedata struct { 108 | filename string 109 | files []string 110 | } 111 | 112 | goaddresses := make(chan filedata) 113 | var wg sync.WaitGroup 114 | 115 | for i := 0; i < 10; i++ { 116 | go func() { 117 | for f := range goaddresses { 118 | filepath := path.Join(conf.CachePath, f.filename) 119 | os.Remove(filepath) 120 | conf.CheckFileCache(f.filename, f.files) 121 | wg.Done() 122 | } 123 | }() 124 | } 125 | 126 | for filename, files := range conf.CheckIngredients { 127 | wg.Add(1) 128 | goaddresses <- filedata{filename, files} 129 | } 130 | 131 | wg.Wait() 132 | fmt.Fprintf(os.Stderr, "All files updated") 133 | } 134 | -------------------------------------------------------------------------------- /v2/cmd/cook/cmds.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "strings" 7 | 8 | "github.com/glitchedgitz/cook/v2/pkg/config" 9 | "github.com/glitchedgitz/cook/v2/pkg/parse" 10 | "github.com/glitchedgitz/cook/v2/pkg/util" 11 | ) 12 | 13 | func printWordlistNames(k, search string) string { 14 | return util.TerminalColor(strings.ReplaceAll(k, 15 | search, util.TerminalColor(search, util.Background)+util.Red), util.Red) + util.Reset 16 | } 17 | 18 | func searchMode(cmds []string) { 19 | found := false 20 | search := cmds[0] 21 | // convert the below fucntion to as data to map 22 | 23 | for cat, vv := range COOK.Config.Ingredients { 24 | for k, v := range vv { 25 | k = strings.ToLower(k) 26 | k = strings.TrimSpace(k) 27 | if cat == "files" || cat == "raw-files" { 28 | link := "" 29 | if strings.HasPrefix(v[0], "https://raw.githubusercontent.com") { 30 | path := strings.Split(v[0], "/")[4:] 31 | link = strings.ToTitle(path[0]) + " > " + strings.Join(path[2:len(path)-1], " > ") 32 | } else { 33 | d := strings.TrimPrefix(v[0], "http://") 34 | d = strings.TrimPrefix(d, "https://") 35 | link = d 36 | // link = strings.Join(strings.Split(d, "/"), " > ") 37 | } 38 | if strings.Contains(strings.ToLower(link+k), search) { 39 | coloredName := k 40 | coloredName = printWordlistNames(k, search) 41 | link = strings.ToLower(link) 42 | 43 | link = printWordlistNames(link, search) 44 | links := "" 45 | for i, file := range v { 46 | 47 | // fmt.Println(link) 48 | links += fmt.Sprintf(" " + util.TerminalLink(file, fmt.Sprintf("%d", i+1), util.Blue)) 49 | } 50 | 51 | // because of color encoding using %-70s was not working right 52 | repeat := 50 - len(k) 53 | extraSpace := "" 54 | if repeat > 0 { 55 | extraSpace = strings.Repeat(" ", repeat) 56 | } 57 | 58 | fmt.Printf("%s%s %s [%s ]", coloredName, extraSpace, link, links) 59 | found = true 60 | fmt.Println() 61 | } 62 | } else { 63 | if strings.Contains(k, search) { 64 | if cat == "functions" { 65 | config.PrintFunc(k, v, search) 66 | } else { 67 | coloredName := printWordlistNames(k, search) 68 | // words := fmt.Sprintf(strings.ReplaceAll(fmt.Sprintf(" %v\n", v), search, util.Blue+search+config.Reset)) 69 | words := util.TerminalColor(fmt.Sprint(v), util.Blue) 70 | fmt.Printf("%-90s Wordset %s", coloredName, words) 71 | } 72 | found = true 73 | fmt.Println() 74 | } 75 | } 76 | } 77 | } 78 | 79 | if !found { 80 | fmt.Println("Not Found: ", search) 81 | } 82 | // COOK.SearchMode(cmds[0]) 83 | } 84 | 85 | func showMode(cmds []string) { 86 | set := cmds[0] 87 | COOK.Show(set) 88 | } 89 | 90 | func addMode(cmds []string) { 91 | if len(cmds) != 3 { 92 | log.Println("Usage: cook add [keyword]=[values separated by comma] in [category]") 93 | } 94 | k := strings.SplitN(cmds[0], "=", 2) 95 | keyword := k[0] 96 | values := parse.SplitValues(k[1]) 97 | category := cmds[2] 98 | COOK.Add(category, keyword, values) 99 | } 100 | 101 | func cleanMode(cmds []string) { 102 | fmt.Println("Not implemented yet") 103 | COOK.Clean() 104 | } 105 | 106 | func infoMode(cmds []string) { 107 | set := cmds[0] 108 | COOK.Info(set) 109 | } 110 | 111 | func updateMode(cmds []string) { 112 | f := cmds[0] 113 | COOK.Update(f) 114 | 115 | } 116 | 117 | func deleteMode(cmds []string) { 118 | if len(cmds) != 1 { 119 | log.Fatalln("Usage: cook delete [keyword]") 120 | } 121 | keyword := cmds[0] 122 | COOK.Delete(keyword) 123 | } 124 | -------------------------------------------------------------------------------- /v2/pkg/methods/methods.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "net/url" 5 | 6 | "github.com/ffuf/pencode/pkg/pencode" 7 | ) 8 | 9 | func (m *Methods) SetupMethodFunc() { 10 | m.MethodFuncs = map[string]func([]string, string, *[]string){ 11 | "u": m.Upper, 12 | "upper": m.Upper, 13 | "l": m.Lower, 14 | "lower": m.Lower, 15 | "t": m.Title, 16 | "title": m.Title, 17 | "fb": m.FileBase, 18 | "filebase": m.FileBase, 19 | "leet": m.Leet, 20 | "json": m.GetJsonField, 21 | "smart": m.SmartWords, 22 | "smartjoin": m.SmartWordsJoin, 23 | "regex": m.Regex, 24 | "sort": m.Sort, 25 | "sortu": m.SortUnique, 26 | "split": m.Split, 27 | "replace": m.Replace, 28 | "splitindex": m.SplitIndex, 29 | "reverse": m.Reverse, 30 | "c": m.Charcode, 31 | "charcode": m.Charcode, 32 | } 33 | } 34 | 35 | func (m *Methods) SetupUrlFunc() { 36 | m.UrlFuncs = map[string]func(*url.URL, *[]string){ 37 | "k": m.UrlKey, 38 | "keys": m.UrlKey, 39 | "sub": m.UrlSub, 40 | "subdomain": m.UrlSub, 41 | "allsub": m.UrlAllSub, 42 | "tld": m.UrlTld, 43 | "user": m.UrlUser, 44 | "pass": m.UrlPass, 45 | "h": m.UrlHost, 46 | "host": m.UrlHost, 47 | "p": m.UrlPort, 48 | "port": m.UrlPort, 49 | "ph": m.UrlPath, 50 | "path": m.UrlPath, 51 | "f": m.UrlFrag, 52 | "fragment": m.UrlFrag, 53 | "q": m.UrlRawQuery, 54 | "query": m.UrlRawQuery, 55 | "v": m.UrlValue, 56 | "value": m.UrlValue, 57 | "s": m.UrlScheme, 58 | "scheme": m.UrlScheme, 59 | "d": m.UrlDomain, 60 | "domain": m.UrlDomain, 61 | "alldir": m.UrlAllDir, 62 | } 63 | } 64 | 65 | func (m *Methods) SetupEncodersFunc() { 66 | m.EncodersFuncs = map[string]pencode.Encoder{ 67 | "b64e": pencode.Base64Encoder{}, 68 | "b64encode": pencode.Base64Encoder{}, 69 | "b64d": pencode.Base64Decoder{}, 70 | "b64decode": pencode.Base64Decoder{}, 71 | "filename.tmpl": pencode.Template{}, 72 | "hexe": pencode.HexEncoder{}, 73 | "hexencode": pencode.HexEncoder{}, 74 | "hexd": pencode.HexDecoder{}, 75 | "hexdecode": pencode.HexDecoder{}, 76 | "jsone": pencode.JSONEscaper{}, 77 | "jsonescape": pencode.JSONEscaper{}, 78 | "jsonu": pencode.JSONUnescaper{}, 79 | "jsonunescape": pencode.JSONUnescaper{}, 80 | "md5": pencode.MD5Hasher{}, 81 | "sha1": pencode.SHA1Hasher{}, 82 | "sha224": pencode.SHA224Hasher{}, 83 | "sha256": pencode.SHA256Hasher{}, 84 | "sha384": pencode.SHA384Hasher{}, 85 | "sha512": pencode.SHA512Hasher{}, 86 | "unicoded": pencode.UnicodeDecode{}, 87 | "unicodedecode": pencode.UnicodeDecode{}, 88 | "unicodee": pencode.UnicodeEncodeAll{}, 89 | "unicodeencodeall": pencode.UnicodeEncodeAll{}, 90 | "urle": pencode.URLEncoder{}, 91 | "urlencode": pencode.URLEncoder{}, 92 | "urld": pencode.URLDecoder{}, 93 | "urldecode": pencode.URLDecoder{}, 94 | "urlea": pencode.URLEncoderAll{}, 95 | "urlencodeall": pencode.URLEncoderAll{}, 96 | "utf16": pencode.UTF16LEEncode{}, 97 | "utf16be": pencode.UTF16BEEncode{}, 98 | "xmle": pencode.XMLEscaper{}, 99 | "xmlescape": pencode.XMLEscaper{}, 100 | "xmlu": pencode.XMLUnescaper{}, 101 | "xmlunescape": pencode.XMLUnescaper{}, 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /v2/pkg/parse/parse.go: -------------------------------------------------------------------------------- 1 | package parse 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | type CookParse struct { 12 | Args []string 13 | showError bool 14 | Help string 15 | userDefined map[string]string 16 | // Help = "" 17 | // userDefined = make(map[string]string) 18 | // p.Args = os.p.Args[1:] 19 | // showError = false 20 | // Help = "" 21 | // userDefined = make(map[string]string) 22 | } 23 | 24 | func (p *CookParse) Boolean(flag, flagL string) bool { 25 | for i, cmd := range p.Args { 26 | if cmd == flag || cmd == flagL { 27 | p.Args = append(p.Args[:i], p.Args[i+1:]...) 28 | return true 29 | } 30 | } 31 | return false 32 | } 33 | 34 | func (p *CookParse) String(flag, flagL string) string { 35 | l := len(p.Args) 36 | for i, cmd := range p.Args { 37 | if cmd == flag || cmd == flagL { 38 | if i+1 == l { 39 | fmt.Printf("Err: Flag '%s' doesn't have any value", cmd) 40 | os.Exit(0) 41 | } 42 | value := p.Args[i+1] 43 | p.Args = append(p.Args[:i], p.Args[i+2:]...) 44 | return value 45 | } 46 | } 47 | 48 | return "" 49 | } 50 | 51 | func (p *CookParse) Integer(flag, flagL string) int { 52 | intValue := 0 53 | l := len(p.Args) 54 | 55 | for i, cmd := range p.Args { 56 | if cmd == flag || cmd == flagL { 57 | if i+1 == l || p.Args[i+1] == "" { 58 | fmt.Printf("Err: Flag '%s' doesn't have any value", cmd) 59 | os.Exit(0) 60 | } else { 61 | var err error 62 | intValue, err = strconv.Atoi(p.Args[i+1]) 63 | // min -= 1 64 | if err != nil { 65 | log.Fatalf("Err: Flag %s needs integer value", flag) 66 | } 67 | } 68 | p.Args = append(p.Args[:i], p.Args[i+2:]...) 69 | return intValue 70 | } 71 | } 72 | return -4541 73 | } 74 | 75 | func (p *CookParse) UserDefinedFlags() map[string]string { 76 | tmp := []string{} 77 | 78 | tmp = append(tmp, p.Args...) 79 | 80 | for _, cmd := range tmp { 81 | 82 | if len(cmd) > 1 && strings.Count(cmd, "-") == 1 && strings.HasPrefix(cmd, "-") { 83 | value := p.String(cmd, cmd) 84 | cmd = strings.Replace(cmd, "-", "", 1) 85 | p.userDefined[cmd] = value 86 | } 87 | } 88 | 89 | return p.userDefined 90 | } 91 | 92 | // Read square brackets 93 | func ReadSqBr(cmd string) (string, string) { 94 | c := strings.SplitN(cmd, "[", 2) 95 | name := c[0] 96 | values := c[1][:len(c[1])-1] 97 | return name, values 98 | } 99 | 100 | // Read square brackets and separate values by a string/char 101 | func ReadSqBrSepBy(cmd string, sep string) (string, []string) { 102 | c := strings.SplitN(cmd, "[", 2) 103 | 104 | name := c[0] 105 | values := strings.Split(c[1][:len(c[1])-1], sep) 106 | return name, values 107 | } 108 | 109 | // Read circular brackets 110 | func ReadCrBr(cmd string) (string, string) { 111 | c := strings.SplitN(cmd, "(", 2) 112 | name := c[0] 113 | values := c[1][:len(c[1])-1] 114 | return name, values 115 | } 116 | 117 | // Read circular brackets and separate values by a string/char 118 | func ReadCrBrSepBy(cmd string, sep string) (string, []string) { 119 | c := strings.SplitN(cmd, "(", 2) 120 | name := c[0] 121 | values := strings.Split(c[1][:len(c[1])-1], sep) 122 | return name, values 123 | } 124 | 125 | func NewParse(args ...string) *CookParse { 126 | if len(args) == 0 { 127 | args = os.Args[1:] 128 | } 129 | return &CookParse{ 130 | Args: args, 131 | showError: false, 132 | Help: "", 133 | userDefined: make(map[string]string), 134 | } 135 | } 136 | 137 | func (p *CookParse) Parse() { 138 | 139 | if len(os.Args) < 2 { 140 | print(p.Help) 141 | } 142 | 143 | if p.showError && len(p.userDefined) > 0 { 144 | panic(fmt.Sprintf("Undefined Flags%v", p.userDefined)) 145 | } 146 | 147 | } 148 | 149 | func init() { 150 | log.SetFlags(0) 151 | } 152 | -------------------------------------------------------------------------------- /v2/pkg/cook/cook.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "path" 8 | "strconv" 9 | "strings" 10 | 11 | "github.com/glitchedgitz/cook/v2/pkg/config" 12 | "github.com/glitchedgitz/cook/v2/pkg/methods" 13 | "github.com/glitchedgitz/cook/v2/pkg/parse" 14 | "github.com/glitchedgitz/cook/v2/pkg/util" 15 | ) 16 | 17 | func (cook *COOK) SetupConfig() { 18 | if cook.Config == nil { 19 | cook.Config = &config.Config{} 20 | } 21 | 22 | if cook.Config.HomeFolder == "" { 23 | cook.Config.HomeFolder, _ = os.UserHomeDir() 24 | } 25 | 26 | if cook.Config.ConfigPath == "" { 27 | cook.Config.ConfigPath = path.Join(cook.Config.HomeFolder, ".config", "cook") 28 | } 29 | 30 | cook.Config.InputFile = make(map[string]bool) 31 | 32 | cacheDir, err := os.UserCacheDir() 33 | if err != nil { 34 | log.Fatalln(err) 35 | } 36 | 37 | cook.Config.CachePath = path.Join(cacheDir, "cook") 38 | cook.Config.IngredientsPath = path.Join(cook.Config.ConfigPath, "cook-ingredients") 39 | 40 | cook.VPrint(fmt.Sprintln("ConfigPath: ", cook.Config.ConfigPath)) 41 | cook.VPrint(fmt.Sprintln("IngredientsPath: ", cook.Config.IngredientsPath)) 42 | cook.VPrint(fmt.Sprintln("CachePath: ", cook.Config.CachePath)) 43 | 44 | } 45 | 46 | // Cook pattern can contain flags and values 47 | // So we are parsing them here 48 | func (cook *COOK) ParseCustomFlags() { 49 | parseFlags := parse.NewParse(cook.Pattern...) 50 | cook.Params = parseFlags.UserDefinedFlags() 51 | cook.Pattern = parseFlags.Args 52 | } 53 | 54 | func (cook *COOK) SetupMethods() { 55 | leetValues := make(map[string][]string) 56 | util.ReadInfoYaml(path.Join(cook.Config.ConfigPath, "leet.yaml"), leetValues) 57 | m := methods.New(leetValues) 58 | cook.Method = m 59 | } 60 | 61 | func (cook *COOK) SetMin() { 62 | if cook.Min < 0 { 63 | cook.Min = cook.TotalCols - 1 64 | } else { 65 | if cook.Min > cook.TotalCols { 66 | fmt.Println("Err: min is greator than no of columns") 67 | os.Exit(0) 68 | } 69 | cook.Min -= 1 70 | } 71 | } 72 | 73 | func (cook *COOK) ParseAppend() { 74 | columns := strings.Split(cook.AppendParam, ",") 75 | for _, colNum := range columns { 76 | intValue, err := strconv.Atoi(colNum) 77 | if err != nil { 78 | log.Fatalf("Err: Column Value %s in not integer", colNum) 79 | } 80 | cook.AppendMap[intValue] = true 81 | } 82 | } 83 | 84 | func (cook *COOK) ParseMethod() { 85 | meths := strings.Split(cook.MethodParam, ";") 86 | forAllCols := []string{} 87 | 88 | var modifiedCol = make(map[int]bool) 89 | 90 | for _, m := range meths { 91 | if strings.Contains(m, ":") { 92 | s := strings.SplitN(m, ":", 2) 93 | i, err := strconv.Atoi(s[0]) 94 | if err != nil { 95 | log.Fatalf("Err: \"%s\" is not integer", s[0]) 96 | } 97 | if i >= cook.TotalCols { 98 | log.Fatalf("Err: No Column %d", i) 99 | } 100 | cook.MethodMap[i] = strings.Split(s[1], ",") 101 | modifiedCol[i] = true 102 | } else { 103 | forAllCols = append(forAllCols, strings.Split(m, ",")...) 104 | } 105 | } 106 | 107 | for i := 0; i < cook.TotalCols; i++ { 108 | if !modifiedCol[i] { 109 | cook.MethodMap[i] = forAllCols 110 | } 111 | } 112 | } 113 | 114 | func NewWithoutConfig() *COOK { 115 | NewCook := &COOK{} 116 | return New(NewCook) 117 | } 118 | 119 | func New(newCook *COOK) *COOK { 120 | 121 | newCook.SetupConfig() 122 | newCook.Config.CookConfig() 123 | newCook.ParseCustomFlags() 124 | newCook.SetupMethods() 125 | 126 | newCook.TotalCols = len(newCook.Pattern) 127 | if newCook.Min < 0 { 128 | newCook.Min = newCook.TotalCols 129 | } 130 | 131 | newCook.SetMin() 132 | newCook.AnalyseParams() 133 | newCook.Final = []string{""} 134 | 135 | newCook.AppendMap = make(map[int]bool) 136 | newCook.MethodMap = make(map[int][]string) 137 | 138 | if len(newCook.AppendParam) > 0 { 139 | newCook.ParseAppend() 140 | } 141 | 142 | if len(newCook.MethodParam) > 0 { 143 | newCook.ParseMethod() 144 | } 145 | return newCook 146 | } 147 | -------------------------------------------------------------------------------- /v2/pkg/methods/urls.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "log" 5 | "net" 6 | "net/url" 7 | "path/filepath" 8 | "regexp" 9 | "strings" 10 | 11 | "golang.org/x/net/publicsuffix" 12 | ) 13 | 14 | func (m *Methods) FileBase(urls []string, useless string, array *[]string) { 15 | for _, u := range urls { 16 | file := filepath.Base(u) 17 | *array = append(*array, file) 18 | } 19 | } 20 | 21 | func (m *Methods) UrlScheme(u *url.URL, array *[]string) { 22 | *array = append(*array, u.Scheme) 23 | } 24 | func (m *Methods) UrlUser(u *url.URL, array *[]string) { 25 | *array = append(*array, u.User.Username()) 26 | } 27 | func (m *Methods) UrlPass(u *url.URL, array *[]string) { 28 | p, _ := u.User.Password() 29 | *array = append(*array, p) 30 | } 31 | func (m *Methods) UrlHost(u *url.URL, array *[]string) { 32 | host, _, _ := net.SplitHostPort(u.Host) 33 | if strings.Contains(u.Host, ":") { 34 | *array = append(*array, host) 35 | } else { 36 | *array = append(*array, u.Host) 37 | } 38 | } 39 | func (m *Methods) UrlPort(u *url.URL, array *[]string) { 40 | _, port, _ := net.SplitHostPort(u.Host) 41 | *array = append(*array, port) 42 | } 43 | func (m *Methods) UrlPath(u *url.URL, array *[]string) { 44 | *array = append(*array, u.Path) 45 | } 46 | func (m *Methods) UrlFrag(u *url.URL, array *[]string) { 47 | *array = append(*array, u.Fragment) 48 | } 49 | func (m *Methods) UrlRawQuery(u *url.URL, array *[]string) { 50 | *array = append(*array, u.RawQuery) 51 | } 52 | func (m *Methods) UrlKey(u *url.URL, array *[]string) { 53 | for k := range u.Query() { 54 | *array = append(*array, k) 55 | } 56 | } 57 | func (m *Methods) UrlValue(u *url.URL, array *[]string) { 58 | for _, vals := range u.Query() { 59 | *array = append(*array, vals...) 60 | } 61 | } 62 | func (m *Methods) UrlDomain(u *url.URL, array *[]string) { 63 | *array = append(*array, u.Scheme+"://"+u.Host) 64 | } 65 | func (m *Methods) UrlTld(u *url.URL, array *[]string) { 66 | host, _, _ := net.SplitHostPort(u.Host) 67 | var domain string 68 | if strings.Contains(u.Host, ":") { 69 | domain = host 70 | } else { 71 | domain = u.Host 72 | } 73 | eTLD, _ := publicsuffix.PublicSuffix(domain) 74 | *array = append(*array, eTLD) 75 | } 76 | func (m *Methods) UrlSub(u *url.URL, array *[]string) { 77 | host, _, _ := net.SplitHostPort(u.Host) 78 | 79 | var domain string 80 | if strings.Contains(u.Host, ":") { 81 | domain = host 82 | } else { 83 | domain = u.Host 84 | } 85 | mainDomain, _ := publicsuffix.EffectiveTLDPlusOne(domain) 86 | till := len(domain) - len(mainDomain) - 1 87 | if till < 0 { 88 | till = 0 89 | } 90 | subdomain := domain[:till] 91 | *array = append(*array, subdomain) 92 | } 93 | func (m *Methods) UrlAllSub(u *url.URL, array *[]string) { 94 | host, _, _ := net.SplitHostPort(u.Host) 95 | 96 | var domain string 97 | if strings.Contains(u.Host, ":") { 98 | domain = host 99 | } else { 100 | domain = u.Host 101 | } 102 | mainDomain, _ := publicsuffix.EffectiveTLDPlusOne(domain) 103 | till := len(domain) - len(mainDomain) - 1 104 | if till < 0 { 105 | till = 0 106 | } 107 | subdomain := domain[:till] 108 | *array = append(*array, strings.Split(subdomain, ".")...) 109 | } 110 | func (m *Methods) UrlAllDir(u *url.URL, array *[]string) { 111 | *array = append(*array, strings.Split(u.Path, "/")...) 112 | } 113 | 114 | func (m *Methods) AnalyzeURLs(urls []string, fn func(*url.URL, *[]string), array *[]string) { 115 | 116 | for _, s := range urls { 117 | if !strings.HasPrefix(s, "http://") && !strings.HasPrefix(s, "https://") { 118 | s = "http://" + s 119 | } 120 | sanitizedURL := sanitizeURL(s) 121 | u, err := url.Parse(sanitizedURL) 122 | if err != nil { 123 | log.Println("Err: AnalyseURLs in url ", err) 124 | continue 125 | } 126 | 127 | fn(u, array) 128 | } 129 | } 130 | 131 | // Function to sanitize the URL string 132 | func sanitizeURL(s string) string { 133 | // Regular expression to match any characters outside the valid ASCII range 134 | controlCharsRegex := regexp.MustCompile(`[^ -~]`) 135 | 136 | // Replace any characters outside the valid ASCII range with an empty string 137 | sanitizedURL := controlCharsRegex.ReplaceAllString(s, "") 138 | 139 | return sanitizedURL 140 | } 141 | 142 | func (m *Methods) init() { 143 | log.SetFlags(0) 144 | } 145 | -------------------------------------------------------------------------------- /v2/pkg/cook/cmd.go: -------------------------------------------------------------------------------- 1 | package cook 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "path" 8 | "sort" 9 | "strings" 10 | 11 | "github.com/glitchedgitz/cook/v2/pkg/config" 12 | "github.com/glitchedgitz/cook/v2/pkg/util" 13 | ) 14 | 15 | const myyaml = "my.yaml" 16 | 17 | func (cook *COOK) AnalyseParams() { 18 | for param, value := range cook.Params { 19 | if strings.HasSuffix(param, ":") { 20 | // remove the param from the list 21 | delete(cook.Params, param) 22 | param = strings.TrimSuffix(param, ":") 23 | 24 | // add the param to the list without colon 25 | cook.Params[param] = value 26 | 27 | // parsing file 28 | cook.Config.InputFile[param] = true 29 | } 30 | } 31 | } 32 | 33 | // Add new set in custom.yaml 34 | // cook add [keyord]=[values separated by comma] in [category] 35 | func (cook *COOK) Add(category, keyword string, values []string) { 36 | 37 | m := make(map[string]map[string][]string) 38 | util.ReadYaml(path.Join(cook.Config.IngredientsPath, myyaml), m) 39 | 40 | if _, exists := m[category]; exists { 41 | m[category][keyword] = append(m[category][keyword], values...) 42 | } else { 43 | m[category] = map[string][]string{ 44 | keyword: values, 45 | } 46 | } 47 | 48 | util.WriteYaml(path.Join(cook.Config.IngredientsPath, myyaml), m) 49 | fmt.Printf("Added \"%s\" in \"%s\" ", keyword, category) 50 | } 51 | 52 | func (cook *COOK) Update(f string) { 53 | 54 | const ( 55 | updateAllStr = "*" 56 | updateDBStr = "db" 57 | updateCacheStr = "cache" 58 | ) 59 | 60 | if f == updateAllStr { 61 | cook.Config.UpdateDb() 62 | cook.Config.UpdateCache() 63 | } else if f == updateDBStr { 64 | cook.Config.UpdateDb() 65 | } else if f == updateCacheStr { 66 | cook.Config.UpdateCache() 67 | } else if files, exists := cook.Config.Ingredients["files"][f]; exists { 68 | filepath := path.Join(cook.Config.CachePath, f) 69 | os.Remove(filepath) 70 | cook.Config.CheckFileCache(f, files) 71 | } else { 72 | log.Println("No mode or keyword found\nUse \"db\" to update cook-ingredients\nUse \"cache\" to update cached files from soruce\nUse \"*\" to do the both") 73 | } 74 | } 75 | 76 | // Delete from custom.yaml 77 | // cook delete [keyword] 78 | func (cook *COOK) Delete(keyword string) { 79 | 80 | m := make(map[string]map[string][]string) 81 | util.ReadYaml(myyaml, m) 82 | category := "" 83 | 84 | found := false 85 | for k, v := range m { 86 | 87 | if _, exists := v[keyword]; exists { 88 | category = k 89 | 90 | // Take input from user 91 | fmt.Println("Enter your input:") 92 | var input string 93 | _, err := fmt.Scanln(&input) 94 | if err != nil { 95 | fmt.Printf("Read from console failed, %s\n", err) 96 | return 97 | } 98 | 99 | input = strings.ToLower(input) 100 | 101 | if input == "yes" || input == "y" { 102 | found = true 103 | } else { 104 | log.Fatalln("Not deleted") 105 | } 106 | break 107 | } 108 | } 109 | 110 | if found { 111 | delete(m[category], keyword) 112 | fmt.Printf("Deleted \"%s\" from \"%s\" ", keyword, category) 113 | util.WriteYaml(path.Join(cook.Config.IngredientsPath, myyaml), m) 114 | } else { 115 | log.Fatalln("Keyword doesn't exists") 116 | } 117 | 118 | } 119 | 120 | func (cook *COOK) Clean() { 121 | } 122 | 123 | func (cook *COOK) Info(set string) { 124 | 125 | m := make(map[string]map[string][]string) 126 | if strings.HasSuffix(set, ".yaml") || strings.HasPrefix(set, ".yml") { 127 | util.ReadYaml(set, m) 128 | } 129 | 130 | fmt.Println("\n" + util.Blue + set + util.Reset) 131 | fmt.Println("Path : ", path.Join(cook.Config.IngredientsPath, set)) 132 | fmt.Println("Sets : ", len(m)) 133 | fmt.Println("Version : ", len(m)) 134 | } 135 | 136 | func (cook *COOK) Show(set string) { 137 | 138 | if strings.HasSuffix(set, ".yaml") || strings.HasPrefix(set, ".yml") { 139 | fmt.Println(string(util.ReadFile(set))) 140 | return 141 | } 142 | 143 | if vals, exists := cook.Config.Ingredients[set]; exists { 144 | fmt.Printf("\n" + util.Blue + strings.ToUpper(set) + util.Reset + "\n\n") 145 | 146 | keys := []string{} 147 | for k := range vals { 148 | keys = append(keys, k) 149 | } 150 | sort.Strings(keys) 151 | if set != "patterns" { 152 | for _, k := range keys { 153 | fmt.Printf(" %-12s "+"%v\n", k, vals[k]) 154 | } 155 | } else { 156 | for _, k := range keys { 157 | config.PrintFunc(k, vals[k], "") 158 | } 159 | } 160 | } else { 161 | fmt.Println("\nNot Found " + set + "\nTry functions, files, raw-files, ports or .yaml") 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /v2/go.sum: -------------------------------------------------------------------------------- 1 | github.com/adrg/strutil v0.2.3 h1:WZVn3ItPBovFmP4wMHHVXUr8luRaHrbyIuLlHt32GZQ= 2 | github.com/adrg/strutil v0.2.3/go.mod h1:+SNxbiH6t+O+5SZqIj5n/9i5yUjR+S3XXVrjEcN2mxg= 3 | github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= 4 | github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= 5 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 6 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 7 | github.com/ffuf/pencode v0.0.0-20210513164852-47e578431524 h1:1mN5/i+atczHYY8niCGqIBHGJqBqXIPKiCeA+b2g+aY= 8 | github.com/ffuf/pencode v0.0.0-20210513164852-47e578431524/go.mod h1:Qmgn2URTRtZ5wMntUke1+/G7z8rofTFHG1EvN3addNY= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 15 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 16 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 17 | golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= 18 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 19 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 20 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 21 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 22 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 23 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 24 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 25 | golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= 26 | golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= 27 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 28 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 29 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 30 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 31 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 32 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 33 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 34 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 35 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 36 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 37 | golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 38 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 39 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 40 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 41 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 42 | golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= 43 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 44 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 45 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 46 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 47 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 48 | golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 49 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 50 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 51 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 52 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 53 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 54 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 55 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 56 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 57 | gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= 58 | gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 59 | -------------------------------------------------------------------------------- /v2/pkg/config/parse.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "log" 7 | "os" 8 | "strconv" 9 | "strings" 10 | 11 | "github.com/glitchedgitz/cook/v2/pkg/parse" 12 | "github.com/glitchedgitz/cook/v2/pkg/util" 13 | ) 14 | 15 | func PrintFunc(k string, v []string, search string) { 16 | // fmt.Println(strings.ReplaceAll(k, search, "\u001b[48;5;239m"+search+Reset)) 17 | fmt.Printf("%s%s{\n", util.Blue+k+util.Reset, strings.ReplaceAll(v[0], search, util.Blue+search+util.Reset)) 18 | for _, file := range v[1:] { 19 | fmt.Printf(" %s\n", strings.ReplaceAll(file, search, util.Blue+search+util.Reset)) 20 | } 21 | fmt.Print("}\n\n") 22 | } 23 | 24 | // Checking for functions 25 | func (conf *Config) ParseFunc(value string, array *[]string) bool { 26 | 27 | if !(strings.Contains(value, "[") && strings.Contains(value, "]")) { 28 | return false 29 | } 30 | 31 | funcName, funcArgs := parse.ReadSqBrSepBy(value, ",") 32 | // fmt.Println(funcName) 33 | // fmt.Println(funcArgs) 34 | 35 | fmt.Print("") 36 | 37 | if funcPatterns, exists := conf.Ingredients["functions"][funcName]; exists { 38 | 39 | funcDef := strings.Split(funcPatterns[0][1:len(funcPatterns[0])-1], ",") 40 | 41 | // fmt.Printf("Func Arg: %v", funcArgs) 42 | // fmt.Printf("\tFunc Def: %v", funcDef) 43 | 44 | if len(funcDef) != len(funcArgs) { 45 | log.Fatalln("\nErr: No of Arguments are different for") 46 | PrintFunc(funcName, funcPatterns, funcName) 47 | } 48 | 49 | for _, p := range funcPatterns[1:] { 50 | for index, arg := range funcDef { 51 | p = strings.ReplaceAll(p, arg, funcArgs[index]) 52 | } 53 | *array = append(*array, p) 54 | } 55 | 56 | return true 57 | } 58 | return false 59 | } 60 | 61 | func (conf *Config) ParseFile(param string, value string, array *[]string) bool { 62 | 63 | if conf.InputFile[param] { 64 | if strings.Contains(value, "https://") || strings.Contains(value, "http://") { 65 | // Parse URL 66 | URLValues(value, array) 67 | } else { 68 | // When you paste URL from chrome 69 | // file:///C://Users//gites//AppData//Local/grroxy/downloaded_lL5A 70 | value = strings.TrimLeft(value, "file:///") 71 | FileValues(value, array, conf.Peek) 72 | } 73 | return true 74 | } 75 | 76 | if conf.checkFileSet(value, array) { 77 | return true 78 | } 79 | 80 | return false 81 | } 82 | 83 | func PipeInput(value string, array *[]string) bool { 84 | var pipe []string 85 | if value == "-" { 86 | sc := bufio.NewScanner(os.Stdin) 87 | if len(pipe) > 0 { 88 | *array = append(*array, pipe...) 89 | } 90 | for sc.Scan() { 91 | *array = append(*array, sc.Text()) 92 | pipe = append(pipe, sc.Text()) 93 | } 94 | return true 95 | } 96 | return false 97 | } 98 | 99 | func RawInput(value string, array *[]string) bool { 100 | if value == "`" { 101 | return true 102 | } 103 | if strings.HasPrefix(value, "`") && strings.HasSuffix(value, "`") { 104 | lv := len(value) 105 | *array = append(*array, []string{value[1 : lv-1]}...) 106 | return true 107 | } 108 | return false 109 | } 110 | 111 | func ParseRanges(p string, array *[]string, peek int) bool { 112 | 113 | chars := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 114 | 115 | if strings.Count(p, "-") == 1 { 116 | 117 | numRange := strings.SplitN(p, "-", 2) 118 | from := numRange[0] 119 | to := numRange[1] 120 | 121 | start, err1 := strconv.Atoi(from) 122 | stop, err2 := strconv.Atoi(to) 123 | 124 | if err1 == nil && err2 == nil { 125 | // this is number 126 | fromLen := len(from) 127 | toLen := len(to) 128 | 129 | minPadded := 0 130 | if fromLen < toLen { 131 | minPadded = fromLen 132 | } else { 133 | minPadded = toLen 134 | } 135 | 136 | if start < stop { 137 | for start <= stop { 138 | repeat := minPadded - len(strconv.Itoa(start)) 139 | padZero := "" 140 | if repeat > 0 { 141 | padZero = strings.Repeat("0", repeat) 142 | } 143 | *array = append(*array, fmt.Sprintf("%s%d", padZero, start)) 144 | start++ 145 | if peek > 0 { 146 | peek-- 147 | if peek == 0 { 148 | break 149 | } 150 | } 151 | } 152 | } else { 153 | for start >= stop { 154 | repeat := minPadded - len(strconv.Itoa(start)) 155 | padZero := "" 156 | if repeat > 0 { 157 | padZero = strings.Repeat("0", repeat) 158 | } 159 | *array = append(*array, fmt.Sprintf("%s%d", padZero, start)) 160 | start-- 161 | if peek > 0 { 162 | peek-- 163 | if peek == 0 { 164 | break 165 | } 166 | } 167 | } 168 | } 169 | return true 170 | } 171 | 172 | if len(from) == 1 && len(to) == 1 && strings.Contains(chars, from) && strings.Contains(chars, to) { 173 | start = strings.Index(chars, from) 174 | stop = strings.Index(chars, to) 175 | 176 | if start < stop { 177 | charsList := strings.Split(chars, "") 178 | for start <= stop { 179 | *array = append(*array, charsList[start]) 180 | start++ 181 | } 182 | return true 183 | } 184 | } 185 | } 186 | return false 187 | } 188 | 189 | func ParsePorts(ports []string, array *[]string, peek int) { 190 | 191 | for _, p := range ports { 192 | if ParseRanges(p, array, peek) { 193 | continue 194 | } 195 | port, err := strconv.Atoi(p) 196 | if err != nil { 197 | log.Printf("Err: Is this port number -_-?? '%s'", p) 198 | } 199 | *array = append(*array, strconv.Itoa(port)) 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /v2/cmd/cook/usage.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "strings" 8 | 9 | "github.com/glitchedgitz/cook/v2/pkg/util" 10 | ) 11 | 12 | func helpMode(h []string) { 13 | 14 | helpModeNames := func() string { 15 | t := "" 16 | for k := range helpFunctions { 17 | t += k + ", " 18 | } 19 | return t 20 | }() 21 | 22 | if len(h) <= 0 { 23 | log.Fatalf("Ask for these... %s", helpModeNames) 24 | } 25 | 26 | help := strings.ToLower(h[0]) 27 | 28 | if fn, exists := helpFunctions[help]; exists { 29 | fn() 30 | } else { 31 | log.Fatalf("Ask for these... %s", helpModeNames) 32 | } 33 | 34 | os.Exit(0) 35 | } 36 | 37 | func showHelp() { 38 | fmt.Fprintln(os.Stderr, banner) 39 | fmt.Fprintln(os.Stderr, util.Reset) 40 | flagsHelp() 41 | os.Exit(0) 42 | } 43 | 44 | func printHelp(title string, description ...string) { 45 | fmt.Println(util.Blue + title + util.Reset) 46 | for _, d := range description { 47 | fmt.Println(" " + d) 48 | } 49 | fmt.Println() 50 | } 51 | 52 | func flagsHelp() { 53 | 54 | printHelp("GITHUB", "https://github.com/glitchedgitz/cook") 55 | 56 | printHelp( 57 | "USAGE", 58 | "cook [params and values] [pattern]", 59 | "cook -param1 value -file: filename -param3 value param3,admin_set param1 file,[1-300]", 60 | ) 61 | 62 | printHelp( 63 | "MODES", 64 | "Search cook search [word]", 65 | "Help cook help [word]", 66 | "Update cook update [filename]", 67 | " This will update the file's cache.", 68 | " - Use \"cache\" to update cached file from source", 69 | " - Use \"db\" to update cooks-ingredients", 70 | " - Use \"*\" to do both", 71 | "Add cook add keyword=[values, separated by comma] in [category]", 72 | " (files, raw-files, functions and lists)", 73 | " (This will only make changes in my.yaml)", 74 | "Delete cook delete [keyword]", 75 | " (This will only make changes in my.yaml)", 76 | "Show cook show [category]", 77 | " Better not try for \"files\"", 78 | ) 79 | 80 | printHelp( 81 | "FLAGS", 82 | " -peek Peek the output using `-peek 50` for first 50 lines", 83 | "-a -append Append to the previous lines, instead of permutations", 84 | "-c -col Print column numbers and there values", 85 | "-conf, -config Config Information", 86 | "-mc, -methodcol Apply methods column wise", 87 | " -mc 0:md5,b64e; 1:reverse", 88 | " To all cols separate", 89 | " -mc md5,b64e", 90 | "-m, -method Apply methods to final output", 91 | "-h, -help Help", 92 | " -min Minimum no of columns to print", 93 | ) 94 | } 95 | 96 | func methHelp() { 97 | printHelp( 98 | "METHODS", 99 | "Apply different sets of operations to your wordlists", 100 | ) 101 | printHelp( 102 | "STRING/LIST/JSON", 103 | "sort - Sort them", 104 | "sortu - Sort them with unique values only", 105 | "reverse - Reverse string", 106 | "split - split[char]", 107 | "splitindex - splitindex[char:index]", 108 | "replace - Replace All replace[this:tothis]", 109 | "leet - a->4, b->8, e->3 ...", 110 | " leet[0] or leet[1]", 111 | "json - Extract JSON field", 112 | " json[key] or json[key:subkey:sub-subkey]", 113 | "smart - Separate words with naming convensions", 114 | " redirectUri, redirect_uri, redirect-uri -> [redirect, uri]", 115 | "smartjoin - This will split the words from naming convensions &", 116 | " param.smartjoin[c,_] (case, join)", 117 | " redirect-uri, redirectUri, redirect_uri -> redirect_Uri", 118 | "", 119 | "u upper - Uppercase", 120 | "l lower - Lowercase", 121 | "t title - Titlecase", 122 | ) 123 | printHelp( 124 | "URLS", 125 | "fb filebase - Extract filename from path or url", 126 | "s scheme - Extract http, https, gohper, ws, etc. from URL", 127 | " user - Extract username from url", 128 | " pass - Extract password from url", 129 | "h host - Extract host from url", 130 | "p port - Extract port from url", 131 | "ph path - Extract path from url", 132 | "f fragment - Extract fragment from url", 133 | "q query - Extract whole query from url", 134 | "k keys - Extract keys from url", 135 | "v values - Extract values from url", 136 | "d domain - Extract domain from url", 137 | " tld - Extract tld from url", 138 | " alldir - Extract all dirrectories from url's path", 139 | "sub subdomain - Extract subdomain from url", 140 | " allsubs - Extract subdomain from url", 141 | ) 142 | printHelp( 143 | "ENCODERS", 144 | "b64e b64encode - Base64 encoder", 145 | "hexe hexencode - Hex string encoder", 146 | " charcode - Give charcode encoding", 147 | " charcode[0] without semicolon", 148 | " charcode[1] with semicolon", 149 | "jsone jsonescape - JSON escape", 150 | "urle urlencode - URL encode reserved characters", 151 | " utf16 - UTF-16 encoder (Little Endian)", 152 | " utf16be - UTF-16 encoder (Big Endian)", 153 | "xmle xmlescape - XML escape", 154 | "urleall urlencodeall - URL encode all characters", 155 | "unicodee unicodeencodeall - Unicode escape string encode (all characters)", 156 | ) 157 | printHelp( 158 | "DECODERS", 159 | "b64d b64decode - Base64 decoder", 160 | "hexd hexdecode - Hex string decoder", 161 | "jsonu jsonunescape - JSON unescape", 162 | "unicoded unicodedecode - Unicode escape string decode", 163 | "urld urldecode - URL decode", 164 | "xmlu xmlunescape - XML unescape", 165 | ) 166 | printHelp( 167 | "HASHES", 168 | "md5 - MD5 sum", 169 | "sha1 - SHA1 checksum", 170 | "sha224 - SHA224 checksum", 171 | "sha256 - SHA256 checksum", 172 | "sha384 - SHA384 checksum", 173 | "sha512 - SHA512 checksum", 174 | ) 175 | } 176 | 177 | func usageHelp() { 178 | printHelp( 179 | "BASIC USAGE", 180 | "$ cook -start admin,root -sep _,- -end secret,critical / start sep end", 181 | "$ cook / admin,root _,- secret,critical", 182 | ) 183 | printHelp( 184 | "FUNCTIONS", 185 | "Use functions such as date for different variations of values", 186 | "$ cook -dob date(17,Sep,1994) elliot _,- dob", 187 | ) 188 | printHelp( 189 | "RANGES", 190 | "Use ranges like 1-100, A-Z, a-z or A-z in pattern of command", 191 | "$ cook 1-999", 192 | "$ cook a-z", 193 | "$ cook A-Z", 194 | "$ cook X-d", 195 | ) 196 | printHelp( 197 | "RAW STRINGS", 198 | "Print value without any parsing/modification.", 199 | "$ cook -date `date(17,Sep,1994)` date", 200 | ) 201 | printHelp( 202 | "PIPE INPUT", 203 | "Use - as param value for pipe input", 204 | "$ cook -d - d / test", 205 | ) 206 | printHelp( 207 | "USING -min", 208 | "Print value without any parsing/modification", 209 | "$ cook n n n -min 1", 210 | ) 211 | } 212 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # COOK 4 | An overpowered wordlist generator, splitter, merger, finder, saver, create words permutation and combinations, apply different encoding/decoding and everything you need. 5 | 6 | Frustration killer! & Customizable! 7 | 8 | # Index 9 | - [Installation](#installation) 10 | - [Configuration](#configuration) 11 | - [Basic](#basic) 12 | - [Ranges](#ranges) 13 | - [Param Approach](#param-approach) 14 | - [COOK's Ingredients](#cooks-ingredients) 15 | - [Categories](#categories) 16 | - [Save wordlists/lists/chars everything in `my.yaml`](#save-wordlistslistschars-everything-in-myyaml) 17 | - [Functions](#functions) 18 | - [Customize `my.yaml`](#customize-myyaml) 19 | [▸ Add/Update](#▸-add/update) 20 | [▸ Delete](#▸-delete) 21 | - [Local File / Fetch URL](#local-file--fetch-url) 22 | - [Methods](#methods) 23 | - [Multiple Encoding](#multiple-encoding) 24 | - [Break naming conventions 💫](#break-naming-conventions-💫) 25 | - [All methods `cook help methods`](#all-methods-cook-help-methods) 26 | - [Some Usecases Examples](#some-usecases-examples) 27 | - [Join wordlists line-by-line](#join-wordlists-line-by-line) 28 | - [Print at every step](#print-at-every-step) 29 | - [Combine with tools](#combine-with-tools) 30 | - [ULTIMATE USAGE](#ultimate-usage) 31 | - [Real life usage example:](#real-life-usage-example) 32 | - [Repeat Operator `*` and `**`](#repeat-operator--and) 33 | - [Parsing Rules](#parsing-rules) 34 | - [Flags](#flags) 35 | - [Use as library](#use-as-library) 36 | - [Share your recipies/ingredients in cook-ingredients](#share-your-recipies-and-ingredients-in-cook-ingredients) 37 | - [Contribute](#contribute) 38 | 39 | 40 | # Installation 41 | Use Go or download [latest builds](https://github.com/glitchedgitz/cook/releases/) 42 | ``` 43 | go install -v github.com/glitchedgitz/cook/v2/cmd/cook@latest 44 | ``` 45 | 46 | ### Configuration 47 | From version `v2.2` cook save [cook-ingredients](https://github.com/glitchedgitz/cook-ingredients) at `$home/.config/cook/cook-ingredients` 48 | 49 | > To change create a path variable name `COOK=[YOUR PATH]` 50 | 51 | 52 | # Basic 53 | 54 | Without basics, everything is complex. 55 | 56 | 57 | ### Ranges 58 | 59 | 60 | 61 | ## Param Approach 62 | Name them anything and use them to generate the pattern. 63 | This will be more useful when you apply encoding column-wise using [methods](#methods). 64 | 65 | ```bash 66 | cook -start intigriti,bugcrowd -sep _,- -end users.rar,secret.zip / start sep end 67 | ``` 68 | 69 | 70 | 71 | ``` 72 | Note: you must include parameter in the pattern, otherwise it will not print anything. 73 | ``` 74 | 75 | 76 | 77 | 78 | # COOK's Ingredients 79 | Cook depends on [cook-ingredients](https://github.com/glitchedgitz/cook-ingredients), which are `.yaml` files collections of wordsets, functions, ports, wordlists from [assetnotes](https://wordlists.assetnote.io/), [seclist](https://github.com/danielmiessler/SecLists), [fuzzdb](https://github.com/fuzzdb-project/fuzzdb), `15+` etc. 80 | 81 | ### Categories 82 | |Category|Description| 83 | |---|---| 84 | | `lists` | Array of values to directly use when called out | 85 | | `files` | Array of urls| 86 | | `ports` | Ranges of numbers| 87 | | `raw-files` | Array of local files| 88 | | `functions` | [Functions](#functions) are used to generate patterns | 89 | 90 | ## Save wordlists/lists/chars everything in `my.yaml` 91 | 92 | 93 | 94 | ### Functions 95 | 96 | ``` 97 | cook -dob date[17,Sep,1994] elliot _,-, dob 98 | ``` 99 | 100 | 101 | 102 | ## Customize `my.yaml` 103 | Edit `my.yaml` manually or use these commands. 104 | 105 | #### ▸ Add/Update 106 | If `keyword` doesn't exist it will create it. Otherwise it will update it and add the new value in the same variable. 107 | 108 | ``` 109 | # Syntax 110 | cook add [keyword]=[value1, value2, ..., valueN] in [category] 111 | 112 | # Command 113 | cook add unique_name=word1,word2,word3 in lists 114 | ``` 115 | 116 | #### ▸ Delete 117 | 118 | ``` 119 | cook delete [keyword] 120 | ``` 121 | 122 | ## Local File / Fetch URL 123 | 124 | use `:` after param name. 125 | 126 | ``` 127 | cook -f: live.txt f 128 | ``` 129 | 130 | ``` 131 | cook -f: https://example.com/wordlist.txt f 132 | ``` 133 | 134 | # Access Wordlists from databases 135 | Cook has fetched multiple repositories and can directly use wordlist from these repos... 136 | 137 | [assetnotes](https://wordlists.assetnote.io/), [seclist](https://github.com/danielmiessler/SecLists), [fuzzdb](https://github.com/fuzzdb-project/fuzzdb), etc. 138 | 139 | 140 | 141 | 142 | 143 | 144 | # Methods 145 | Using methods you can encode, decode, reverse, split, sort, extract and can do much more... 146 | 147 | Methods can be applied on final output or column-wise 148 | 149 | - `-m/-method` to apply methods on the final output 150 | - `-mc/-methodcol` to apply column-wise. 151 | - `param.methodname` apply to any parameter-wise, will example this param thing later. 152 | 153 | 154 | 155 | 156 | ## Multiple Encoding 157 | 158 | - **Overlapping Encodings**: 159 | - Use dot `.` 160 | - `md5.b64e.urle` apply multiple methods one by one. 161 | - Output Logic: 162 | - `Generated Pattern` > `md5 hashing` > `base 64 encoding` > `URL Encoding`. 163 | - **Different Encodings**: 164 | - Use comma `,` 165 | - `md5,sha1,sha256` apply different encoding to the same generated pattern. 166 | - Output Logic: 167 | - `Generated Pattern` > `md5 hashing` 168 | - `Generated Pattern` > `sha1 hashing` 169 | - `Generated Pattern` > `sha256 hashing` 170 | 171 | 172 | 173 | ## Break naming conventions 💫 174 | Special focus on these 2 methods, these will be great help everytime you use any wordlist. 175 | 176 | ### Smart Break `-m smart` 177 | 178 | ``` 179 | ▶ cook adminNew,admin_new -m smart 180 | ``` 181 | ``` 182 | Output: 183 | 184 | admin 185 | New 186 | admin 187 | new 188 | ``` 189 | 190 | ### Smart Join `-m smartjoin[:]` 191 | It breaks and join back with the supplied character. 192 | ``` 193 | ▶ cook adminNew,admin-old -m smartjoin[:_] 194 | ``` 195 | ``` 196 | Output: 197 | 198 | admin_New 199 | admin_old 200 | ``` 201 | **Apply Cases over separated** 202 | 203 | Here we applied camlecase 204 | ``` 205 | ▶ cook suppose_this_is_long_text -m smartjoin[c:_] 206 | ``` 207 | ``` 208 | Output: 209 | 210 | suppose_This_Is_Long_Text 211 | ``` 212 | 213 | 214 | ## All methods `cook help methods` 215 | 216 | ``` 217 | sort - Sort them 218 | sortu - Sort them with unique values only 219 | reverse - Reverse string 220 | leet - a->4, b->8, e->3 ... 221 | leet[0] or leet[1] 222 | 223 | smart - Separate words with naming convensions 224 | redirectUri, redirect_uri, redirect-uri -> [redirect, uri] 225 | smartjoin - This will split the words from naming convensions & 226 | param.smartjoin[c,_] (case, join) 227 | redirect-uri, redirectUri, redirect_uri -> redirect_Uri 228 | 229 | u upper - Uppercase 230 | l lower - Lowercase 231 | t title - Titlecase 232 | ``` 233 | 234 | ### String Operations 235 | ``` 236 | split - split[char] 237 | splitindex - splitindex[char:index] 238 | replace - Replace All replace[this:tothis] 239 | ``` 240 | 241 | 242 | 243 | ### JSON 244 | ``` 245 | json - Extract JSON field 246 | json[key] or json[key:subkey:sub-subkey] 247 | ``` 248 | 249 | ### Url Operations 250 | fb filebase - Extract filename from path or url 251 | s scheme - Extract http, https, gohper, ws, etc. from URL 252 | user - Extract username from url 253 | pass - Extract password from url 254 | h host - Extract host from url 255 | p port - Extract port from url 256 | ph path - Extract path from url 257 | f fragment - Extract fragment from url 258 | q query - Extract whole query from url 259 | k keys - Extract keys from url 260 | v values - Extract values from url 261 | d domain - Extract domain from url 262 | tld - Extract tld from url 263 | alldir - Extract all dirrectories from url's path 264 | sub subdomain - Extract subdomain from url 265 | allsubs - Extract subdomain from url 266 | 267 | ### Encode/Decode 268 | ``` 269 | b64e b64encode - Base64 encode 270 | b64d b64decode - Base64 decode 271 | 272 | charcode - Give charcode encoding 273 | - charcode[0] 274 | abc 275 | - charcode[1] with semicolon 276 | abc 277 | 278 | hexe hexencode - Hex string encode 279 | hexd hexdecode - Hex string decode 280 | 281 | jsone jsonescape - JSON escape 282 | jsonu jsonunescape - JSON unescape 283 | 284 | urle urlencode - URL encode reserved characters 285 | utf16 - UTF-16 encoder (Little Endian) 286 | utf16be - UTF-16 encoder (Big Endian) 287 | urld urldecode - URL decode 288 | urleall urlencodeall - URL encode all characters 289 | 290 | xmle xmlescape - XML escape 291 | xmlu xmlunescape - XML unescape 292 | 293 | unicodee unicodeencodeall - Unicode escape string encode (all characters) 294 | unicoded unicodedecode - Unicode escape string decode 295 | ``` 296 | 297 | 298 | ### HASHES 299 | ``` 300 | md5 - MD5 sum 301 | sha1 - SHA1 checksum 302 | sha224 - SHA224 checksum 303 | sha256 - SHA256 checksum 304 | sha384 - SHA384 checksum 305 | sha512 - SHA512 checksum 306 | ``` 307 | 308 | # Some Usecases Examples 309 | Some general usecases to grasp understanding of cook. 310 | 311 | #### ▸ Sites using custom suffix/preffix? 312 | 313 | 314 | #### ▸ Join wordlists line-by-line 315 | 316 | Use `-append` flag: 317 | ``` 318 | cook -l: live.txt -p: payloads.txt l / p -append 2 319 | ``` 320 | 321 | 322 | ``` 323 | # Multiple columns 324 | cook col1 col2 col3 col4 col5 -append 2,5 325 | ``` 326 | 327 | *Note: Sometime is confusing to find index of column, then use `-col`* 328 | 329 | #### ▸ Print at every step 330 | 331 | If you want to start printing data for each permuation, then use `-min` flag 332 | 333 | 334 | 335 | *Note: Sometime is confusing to find index of column, then use `-col`* 336 | 337 | 338 | ## Combine with tools 339 | Generate pattern and combine with other tools using PIPE. 340 | ``` 341 | cook [Generated Pattern] | [Any tool with pipe input] 342 | ``` 343 | 344 | #### ▸ Basic Auth Fuzzing with [FFUF](https://github.com/ffuf/ffuf) 345 | 346 | ```bash 347 | cook usernames_list : passwords_list -m b64e | ffuf -u https://target.com -w - -H "Authorization: Basic FUZZ" 348 | ``` 349 | 350 | #### ▸ Null Payload Fuzzing with FFUF 351 | 352 | ```bash 353 | cook https://target.com/**100 | ffuf -u FUZZ -w - 354 | ``` 355 | 356 | #### ▸ Hidden Parameters with [x8](https://github.com/Sh1Yo/x8) 357 | 358 | ```bash 359 | cook [generated output] | x8 -u https://target.com 360 | ``` 361 | 362 | #### ▸ Live Top level domains with [dnsx](https://github.com/projectdiscovery/dnsx) or [httprobe](https://github.com/tomnomnom/httprobe) 363 | 364 | ```bash 365 | cook example.com seclists-tlds.txt | dnsx -v 366 | ``` 367 | 368 | 369 | # ULTIMATE USAGE 370 | Too overpowered? But everyday you came accross weird BB stuff, like a big json file from target? May be you want to extract, join, merge or whatever. You can use cook smartly as per your usecase. 371 | 372 | ## Real life usage example: 373 | As BBH, we came arross JSON file often. YOu may be you read find wordlist to save in your collection. 374 | 375 | Let's say you read this blog about IIS Shortname Vulnerabilities 376 | https://blog.assetnote.io/2020/09/18/finding-hidden-files-folders-iis-bigquery/. 377 | 378 | Here [Assetnote](https://www.assetnote.io/) shared [BIG ZIP FILE](https://storage.googleapis.com/zipfilesbq/zipfiles.json), Now you need something that can save this file and you can recall it when you need. 379 | 380 | 381 | 382 | Save it like this..., this will save file in `my.yaml` 383 | ``` 384 | cook add shub_zip_files=[URL] in files 385 | ``` 386 | Or manually save in `my.yaml`, 387 | ```yaml 388 | shub_zip_files : [https://storage.googleapis.com/zipfilesbq/zipfiles.json] 389 | ``` 390 | > *Note: cook already saved it in default wordlists, you can use `cook shub_zip_files` to access it* 391 | 392 | 393 | 394 | ▸ File contains data like this, but this isn't directly useful. 395 | ```json 396 | {"repo_name":"cocowool/RoseCMS","ref":"refs/heads/1","path":"user_guide/_downloads/ELDocs.tmbundle.zip","mode":"33261","id":"f7a11b364ca918379b48ad525798148e7470b6b1"} 397 | {"repo_name":"xuguanfeng/practise","ref":"refs/heads/1","path":"node_modules/selenium-webdriver/node_modules/adm-zip/test/assets/fast.zip","mode":"33188","id":"f4ed17b98c9d7bcd21efc4523ce75fbe2b071d0a"} 398 | {"repo_name":"xuguanfeng/practise","ref":"refs/heads/1","path":"node_modules/selenium-webdriver/node_modules/adm-zip/test/assets/store.zip","mode":"33188","id":"e2add30dc0e3129dc89e20a71abe7314052d0002"} 399 | {"repo_name":"xuguanfeng/practise","ref":"refs/heads/1","path":"node_modules/selenium-webdriver/node_modules/adm-zip/test/assets/ultra.zip","mode":"33188","id":"86a8ec776107c075ce2c7f803472aa97dc25cbf7"} 400 | {"repo_name":"xuguanfeng/practise","ref":"refs/heads/1","path":"node_modules/selenium-webdriver/node_modules/adm-zip/test/assets/normal.zip","mode":"33188","id":"b4602c94ee000ee54c71c9302b9db956b3fd9f0e"} 401 | {"repo_name":"xuguanfeng/practise","ref":"refs/heads/1","path":"node_modules/selenium-webdriver/node_modules/adm-zip/test/assets/fastest.zip","mode":"33188","id":"f4ed17b98c9d7bcd21efc4523ce75fbe2b071d0a"} 402 | {"repo_name":"xuguanfeng/practise","ref":"refs/heads/1","path":"node_modules/selenium-webdriver/node_modules/adm-zip/test/assets/maximum.zip","mode":"33188","id":"86a8ec776107c075ce2c7f803472aa97dc25cbf7"} 403 | ... 404 | ``` 405 | 406 | **Let say you need to:** 407 | ▸ Extract json field `path` 408 | ▸ extract `filebase` from `path` 409 | ▸ then spliting it based on `naming conventions` 410 | 411 | #### Single line solution 412 | ▸ With cook not just we can extract it, we can extract filebase from path and sort unique, then use smartjoin to create diff permuataions. 413 | 414 | ``` 415 | cook -z shub_zip_files z.json[path].fb.sortu.smartjoin[c:_] 416 | ``` 417 | 418 | 419 | 420 | And this is also how cook was born, while fuzzing IIS Shortnames and later on I added other features. 421 | 422 | # Repeat Operator `*` and `**` 423 | - Use `*` for horizontal repeating. 424 | - Use `**` for vertical repeating. 425 | - And try this `*10-1` or this `*1-10`. 426 | 427 | 428 | 429 | 430 | 431 | # Parsing Rules 432 | | | | 433 | |---|---| 434 | |Columns| Separated by space | 435 | |Values| Separated by comma | 436 | |Params| You can give param any name, use `-` before anything to make it param `-param value` | 437 | |Raw Strings| Use ` before and after the string to stop cook's parsing. Useful when you need to use any keyword as a word. | 438 | |Pipe Input| Take pipe input using `-` as value of any param. | 439 | |File Input| Use `:` after param name to take file input. `cook -f: live.txt f`| 440 | |Functions | Can be called using params only. | 441 | |Methods | Can be used on params or on final output | 442 | 443 | # Flags 444 | | Flag | Usage | 445 | |---|---| 446 | |-peek| Peek the output using `-peek 50` for first 50 lines | 447 | |-a, -append| Append to the previous lines, instead of permutations | 448 | |-c, -col| Print column numbers and there values | 449 | |-conf, -config| Config Information | 450 | |-mc, -methodcol| Apply methods column wise `-mc 0:md5,b64e; 1:reverse`
To all cols separate `-mc md5,b64e` | 451 | |-m, -method| Apply methods to final output | 452 | |-h, -help| Help | 453 | |-min | Minimum no of columns to print | 454 | 455 | 456 | 457 | # Use as library 458 | 459 | ```golang 460 | COOK := New(&COOK{ 461 | Pattern: "1-10 .example.com", 462 | }) 463 | 464 | COOK.Generate() 465 | fmt.Printf("Generated list: %v", COOK.Final) 466 | ``` 467 | 468 | Search the [cook-ingredients](https://github.com/glitchedgitz/cook-ingredients) using library 469 | 470 | ```golang 471 | COOK := NewWithoutConfig() 472 | results := COOK.Search("api") 473 | fmt.Printf("Searched: %v", results) 474 | ``` 475 | 476 | # Share your recipies and ingredients in [cook-ingredients](https://github.com/glitchedgitz/cook-ingredients) 477 | - Share your yaml file with community 478 | 479 | # Contribute 480 | - Use concurrency and make it faster 481 | - Autocomplete for shells 482 | - Make append work something like this `cook file1 =/= file2`, make sure chars directly work with all terminals. 483 | - Making **raw string** works like as it works in programming languages. Means better parser. 484 | - I don't know, you might use your creativity and add some awesome features. 485 | - You can [buy me a coffee](https://www.buymeacoffee.com/glitchedgitz)☕ 486 | --------------------------------------------------------------------------------