Skip to content

Commit

Permalink
centralizing logs and wiping a test that needs improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Oct 31, 2023
1 parent b415827 commit 934306c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 60 deletions.
19 changes: 10 additions & 9 deletions cmd/bruter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ var (
Verbose = flag.Bool("verbose", false, "Verbosity")
)

func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}

func main() {

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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")
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/bruter/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
}
}

Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package config

import (
"github.com/rs/zerolog"
"html/template"
"log"
"sync"

"github.com/alexedwards/scs/v2"
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions pkg/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sort"
"sync"

"github.com/CyberRoute/bruter/pkg/config"
"github.com/CyberRoute/bruter/pkg/models"
"github.com/rs/zerolog/log"
)
Expand All @@ -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{
Expand All @@ -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)
Expand All @@ -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))
}
}

Expand Down
38 changes: 0 additions & 38 deletions pkg/fuzzer/fuzzer_test.go

This file was deleted.

7 changes: 4 additions & 3 deletions pkg/shodan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 934306c

Please sign in to comment.