diff --git a/cmd/bruter/main.go b/cmd/bruter/main.go index bee2bf9..5c38109 100644 --- a/cmd/bruter/main.go +++ b/cmd/bruter/main.go @@ -42,9 +42,6 @@ var ( Verbose = flag.Bool("verbose", false, "Verbosity") ) -func init() { - log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) -} func main() { @@ -55,8 +52,12 @@ func main() { os.Exit(1) } + logger := log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + + app.ZeroLog = &logger + IP, _ := network.ResolveByName(*Domain) - log.Info().Msg(fmt.Sprintf("Scanning IP %s %s", IP, "OK")) + logger.Info().Msg(fmt.Sprintf("Scanning IP %s %s", IP, "OK")) app.InProduction = false @@ -70,7 +71,7 @@ func main() { tc, err := render.CreateTemplateCache() if err != nil { - log.Fatal().Err(err).Msg("cannot create template cache") + logger.Fatal().Err(err).Msg("cannot create template cache") } app.TemplateCache = tc @@ -89,7 +90,7 @@ func main() { } go func() { - log.Info().Msg(fmt.Sprintf("UI running on http://%s%s/", *Address, portNumber)) + logger.Info().Msg(fmt.Sprintf("UI running on http://%s%s/", *Address, portNumber)) if err := srv.ListenAndServe(); err != nil { panic(err) } @@ -98,13 +99,13 @@ func main() { buffer := make([]byte, 500000) // 500K(almost) file, err := os.Open(*Dictionary) if err != nil { - log.Fatal().Err(err).Msg("") + logger.Fatal().Err(err).Msg("") } defer file.Close() EOB, err := file.Read(buffer) if err != nil { - log.Fatal().Err(err).Msg("") + logger.Fatal().Err(err).Msg("") } list := strings.Split(string(buffer[:EOB]), "\n") @@ -113,7 +114,7 @@ func main() { queue := async.NewQueue(0, func(arg async.Job) { ctx := arg.(*workerContext) - fuzzer.Get(ctx.Mu, ctx.Domain, ctx.Path, ctx.Progress, ctx.Verbose) + fuzzer.Get(ctx.Mu, &app, ctx.Domain, ctx.Path, ctx.Progress, ctx.Verbose) }) for index, payload := range list { diff --git a/cmd/bruter/routes.go b/cmd/bruter/routes.go index a0534ac..7808f68 100644 --- a/cmd/bruter/routes.go +++ b/cmd/bruter/routes.go @@ -11,13 +11,12 @@ import ( "github.com/CyberRoute/bruter/pkg/ssl" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" - "github.com/rs/zerolog/log" "net/http" ) func checkError(err error) { if err != nil { - log.Error().Err(err).Msg("") + app.ZeroLog.Error().Err(err).Msg("") } } @@ -36,7 +35,7 @@ func routes(app *config.AppConfig) http.Handler { } client := &http.Client{Transport: customTransport} shodan := shodan.NewClient(client, ipv4, app.ShodanAPIKey) - hostinfo, err := shodan.HostInfo() + hostinfo, err := shodan.HostInfo(app) checkError(err) headers, err := shodan.Head("http://" + app.Domain) checkError(err) @@ -48,6 +47,7 @@ func routes(app *config.AppConfig) http.Handler { checkError(err) ftp, err := grabber.GrabFTPBanner(app.Domain, hostinfo.Ports) checkError(err) + smtp, err := grabber.GrabSMTPBanner(app.Domain, hostinfo.Ports) checkError(err) pop, err := grabber.GrabPOPBanner(app.Domain, hostinfo.Ports) diff --git a/go.mod b/go.mod index c5194f4..e1e4770 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,14 @@ require ( github.com/evilsocket/islazy v1.11.0 github.com/go-chi/chi/v5 v5.0.8 github.com/rs/zerolog v1.29.0 + github.com/stretchr/testify v1.8.4 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/sys v0.6.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c16bc86..f489570 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/alexedwards/scs/v2 v2.5.1 h1:EhAz3Kb3OSQzD8T+Ub23fKsiuvE0GzbF5Lgn0uTwM3Y= github.com/alexedwards/scs/v2 v2.5.1/go.mod h1:ToaROZxyKukJKT/xLcVQAChi5k6+Pn1Gvmdl7h3RRj8= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0= github.com/evilsocket/islazy v1.11.0/go.mod h1:muYH4x5MB5YRdkxnrOtrXLIBX6LySj1uFIqys94LKdo= github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= @@ -14,11 +16,19 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/config/config.go b/pkg/config/config.go index d7838ec..4c17b10 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,8 +1,8 @@ package config import ( + "github.com/rs/zerolog" "html/template" - "log" "sync" "github.com/alexedwards/scs/v2" @@ -12,7 +12,7 @@ import ( type AppConfig struct { UseCache bool TemplateCache map[string]*template.Template - InfoLog *log.Logger + ZeroLog *zerolog.Logger InProduction bool Session *scs.SessionManager Domain string diff --git a/pkg/fuzzer/fuzzer.go b/pkg/fuzzer/fuzzer.go index 6832e62..91cf4f6 100644 --- a/pkg/fuzzer/fuzzer.go +++ b/pkg/fuzzer/fuzzer.go @@ -12,6 +12,7 @@ import ( "sort" "sync" + "github.com/CyberRoute/bruter/pkg/config" "github.com/CyberRoute/bruter/pkg/models" "github.com/rs/zerolog/log" ) @@ -22,16 +23,17 @@ func checkError(err error) { } } -func Get(Mu *sync.Mutex, domain, path string, progress float32, verbose bool) { +func Get(Mu *sync.Mutex, app *config.AppConfig, domain, path string, progress float32, verbose bool) { urjoin := "https://" + domain + path url, err := url.Parse(urjoin) if err != nil { - log.Error().Err(err).Msgf("Error parsing URL: %s", urjoin) + //log.Error().Err(err).Msgf("Error parsing URL: %s", urjoin) + app.ZeroLog.Error().Err(err).Msgf("Error parsing URL: %s", urjoin) } get, err := http.NewRequest("GET", url.String(), nil) if err != nil { - log.Error().Err(err).Msgf("Error creating request for URL: %s", urjoin) + app.ZeroLog.Error().Err(err).Msgf("Error creating request for URL: %s", urjoin) } client := &http.Client{ @@ -42,7 +44,7 @@ func Get(Mu *sync.Mutex, domain, path string, progress float32, verbose bool) { resp, err := client.Do(get) if err != nil { - log.Error().Err(err).Msgf("Error performing request for URL: %s", urjoin) + app.ZeroLog.Error().Err(err).Msgf("Error performing request for URL: %s", urjoin) } statusCode := float64(resp.StatusCode) @@ -53,7 +55,7 @@ func Get(Mu *sync.Mutex, domain, path string, progress float32, verbose bool) { dfileHandler(Mu, domain, urjoin, statusCode, progress) if verbose { - log.Info().Msg(fmt.Sprintf("%s => %s", urjoin, resp.Status)) + app.ZeroLog.Info().Msg(fmt.Sprintf("%s => %s", urjoin, resp.Status)) } } diff --git a/pkg/fuzzer/fuzzer_test.go b/pkg/fuzzer/fuzzer_test.go deleted file mode 100644 index 0c94f03..0000000 --- a/pkg/fuzzer/fuzzer_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package fuzzer_test - -import ( - "encoding/json" - "net/http" - "net/http/httptest" - "strings" - "sync" - "testing" - - "github.com/CyberRoute/bruter/pkg/fuzzer" -) - -func TestGet(t *testing.T) { - // Create a mock HTTP server - server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // Respond with a mock JSON response - response := map[string]interface{}{ - "key": "value", - } - err := json.NewEncoder(w).Encode(response) - if err != nil { - t.Fatalf("Error encoding JSON response: %v", err) - } - })) - defer server.Close() - - // Set up test input parameters - Mu := &sync.Mutex{} - path := "/test" - progress := float32(0.5) - verbose := true - - domain := strings.TrimPrefix(server.URL, "https://") - - // Call the Get function with the mock server URL - fuzzer.Get(Mu, domain, path, progress, verbose) -} diff --git a/pkg/shodan/client.go b/pkg/shodan/client.go index d95bd21..99bb168 100644 --- a/pkg/shodan/client.go +++ b/pkg/shodan/client.go @@ -3,9 +3,10 @@ package shodan import ( "encoding/json" "fmt" - "github.com/rs/zerolog/log" "net/http" "time" + + "github.com/CyberRoute/bruter/pkg/config" ) type Response struct { @@ -50,7 +51,7 @@ func NewClient(client *http.Client, ipv4, token string) *Client { } } -func (c *Client) HostInfo() (Response, error) { +func (c *Client) HostInfo(app *config.AppConfig) (Response, error) { url := fmt.Sprintf(c.BaseURL+c.Path, c.IPv4, c.Token) req, err := http.NewRequest("GET", url, nil) if err != nil { @@ -78,7 +79,7 @@ func (c *Client) HostInfo() (Response, error) { switch resp.StatusCode { case 200: - log.Info().Msg(fmt.Sprintf("status code from shodan %d => %s", resp.StatusCode, "OK")) + app.ZeroLog.Info().Msg(fmt.Sprintf("status code from shodan %d => %s", resp.StatusCode, "OK")) case 401: return Response{}, fmt.Errorf("unauthorized response") case 404: