From 0f7fb8ae6cd03e71ca1190651ba0f84d849cbc85 Mon Sep 17 00:00:00 2001 From: Tillie Kottmann Date: Sun, 1 Nov 2020 17:55:19 +0100 Subject: [PATCH] Add the ability to pass in an entire list of domains --- cmd/goop.go | 21 +++++++++++++++------ pkg/goop/clone.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/cmd/goop.go b/cmd/goop.go index 765e1b5..7f47852 100644 --- a/cmd/goop.go +++ b/cmd/goop.go @@ -8,24 +8,33 @@ import ( ) var force bool +var list bool var rootCmd = &cobra.Command{ - Use: "goop", + Use: "goop", Short: "goop is a very fast tool to grab sources from exposed .git folders", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { var dir string if len(args) >= 2 { dir = args[1] } - if err := goop.Clone(args[0], dir, force); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) + if list { + if err := goop.CloneList(args[0], dir, force); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + } else { + if err := goop.Clone(args[0], dir, force); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } } }, } func init() { - rootCmd.PersistentFlags().BoolVarP(&force, "force", "f",false, "overrides DIR if it already exists") + rootCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "overrides DIR if it already exists") + rootCmd.PersistentFlags().BoolVarP(&list, "list", "l", false, "allows you to supply the name of a file containing a list of domain names instead of just one domain") } func Execute() { diff --git a/pkg/goop/clone.go b/pkg/goop/clone.go index e04a07b..39825b9 100644 --- a/pkg/goop/clone.go +++ b/pkg/goop/clone.go @@ -1,6 +1,7 @@ package goop import ( + "bufio" "bytes" "crypto/tls" "fmt" @@ -45,6 +46,38 @@ func waitForQueue(queue chan string) { close(queue) } +func CloneList(listFile, baseDir string, force bool) error { + lf, err := os.Open(listFile) + if err != nil { + return err + } + defer lf.Close() + + listScan := bufio.NewScanner(lf) + for listScan.Scan() { + u := listScan.Text() + if u == "" { + continue + } + dir := baseDir + if dir != "" { + parsed, err := url.Parse(u) + if err != nil { + fmt.Fprintf(os.Stderr, "error: %s\n", err) + continue + } + dir = utils.Url(dir, parsed.Host) + } + fmt.Printf("[-] Downloading %s to %s\n", u, dir) + if err := Clone(u, dir, force); err != nil { + fmt.Fprintf(os.Stderr, "error: %s\n", err) + } + fmt.Println() + fmt.Println() + } + return nil +} + func Clone(u, dir string, force bool) error { baseUrl := strings.TrimSuffix(u, "/") baseUrl = strings.TrimSuffix(baseUrl, "/HEAD")