11package main
22
33import (
4+ "errors"
45 "fmt"
56 "io/ioutil"
67 "net/url"
@@ -36,7 +37,7 @@ var rootCmd = &cobra.Command{
3637 Long : `Gitjacker steals git repositories from websites which mistakenly host the contents of the .git directory.
3738More information at https://github.com/liamg/gitjacker` ,
3839 Args : cobra .ExactArgs (1 ),
39- RunE : func (cmd * cobra.Command , args []string ) error {
40+ Run : func (cmd * cobra.Command , args []string ) {
4041
4142 _ = tml .Printf (`<red>
4243 ██████ ██ ████████ ██ █████ ██████ ██ ██ ███████ ██████
@@ -53,23 +54,23 @@ https://github.com/liamg/gitjacker %9s
5354
5455 u , err := url .Parse (rawURL )
5556 if err != nil {
56- return fmt . Errorf ( "invalid url: %w " , err )
57+ fail ( "Invalid url: %s " , err )
5758 }
5859
5960 if ! u .IsAbs () {
60- return fmt . Errorf ( "invalid url: must be absolute" )
61+ fail ( "Invalid url: must be absolute e.g. https://victim.website/ " )
6162 }
6263
6364 if outputDir == "" {
6465 outputDir , err = ioutil .TempDir (os .TempDir (), "gitjacker" )
6566 if err != nil {
66- return err
67+ fail ( "Failed to create temporary directory: %s" , err )
6768 }
6869 }
6970
7071 versionData , err := exec .Command ("git" , "--version" ).Output ()
7172 if err != nil {
72- return fmt . Errorf ( "failed to start git: %w - please check it is installed" , err )
73+ fail ( "Cannot check git version : %s - please check it is installed" , err )
7374 }
7475 versionParts := strings .Split (string (versionData ), " " )
7576 version := strings .TrimSpace (versionParts [len (versionParts )- 1 ])
@@ -78,7 +79,7 @@ https://github.com/liamg/gitjacker %9s
7879 logrus .SetLevel (logrus .DebugLevel )
7980 }
8081
81- tml .Printf (`
82+ _ = tml .Printf (`
8283Target: <yellow>%s</yellow>
8384Local Git: %s
8485Output Dir: %s
@@ -93,7 +94,10 @@ Output Dir: %s
9394 if ! verbose {
9495 fmt .Printf ("\x1b [2K\r " )
9596 }
96- return err
97+ if errors .Is (err , gitjacker .ErrNotVulnerable ) {
98+ fail ("The provided URL does not appear vulnerable.\n \n Error: %s" , err )
99+ }
100+ fail ("Gitjacking failed: %s" , err )
97101 }
98102
99103 if ! verbose {
@@ -139,7 +143,10 @@ You can find the retrieved repository data in <blue>%s</blue>
139143 branchStr ,
140144 summary .OutputDirectory ,
141145 )
142-
143- return nil
144146 },
145147}
148+
149+ func fail (format string , args ... interface {}) {
150+ _ , _ = fmt .Fprintln (os .Stderr , tml .Sprintf ("<red>%s" , fmt .Sprintf (format , args ... )))
151+ os .Exit (1 )
152+ }
0 commit comments