Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring main.go #24

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions cmd/bruter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ var session *scs.SessionManager

var (
Domain = flag.String("domain", "", "domain to scan")
Apikey = flag.String("shodan", "", "shadan api key")
Address = flag.String("address", "127.0.0.1", "IP address to bind the web ui server to.")
Apikey = flag.String("shodan", "", "shodan API key")
Address = flag.String("address", "127.0.0.1", "IP address to bind the web UI server to.")
Dictionary = flag.String("dictionary", "db/apache-list", "File to use for enumeration.")
Verbose = flag.Bool("verbose", false, "Verbosity")
)


func main() {

flag.Parse()
if *Domain == "" {
fmt.Println("No domain specified.")
Expand All @@ -53,35 +51,29 @@ func main() {
}

logger := log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

app.ZeroLog = &logger

IP, _ := network.ResolveByName(*Domain)
logger.Info().Msg(fmt.Sprintf("Scanning IP %s %s", IP, "OK"))

app.InProduction = false

session = scs.New()
session.Lifetime = 24 * time.Hour
session.Cookie.Persist = true
session.Cookie.SameSite = http.SameSiteLaxMode
session.Cookie.Secure = app.InProduction

app.Session = session

tc, err := render.CreateTemplateCache()
if err != nil {
logger.Fatal().Err(err).Msg("cannot create template cache")
}

app.TemplateCache = tc
app.UseCache = false
app.Domain = *Domain
app.ShodanAPIKey = *Apikey

repo := handlers.NewRepo(&app)
handlers.NewHandlers(repo)

render.NewTemplates(&app)

srv := &http.Server{
Expand All @@ -96,46 +88,51 @@ func main() {
}
}()

buffer := make([]byte, 500000) // 500K(almost)
file, err := os.Open(*Dictionary)
if err != nil {
logger.Fatal().Err(err).Msg("")
}
defer file.Close()

list := readDictionary(file)
total := len(list)
shift := 1

queue := createQueue(&app.Mu, *Domain, list, shift, total, *Verbose)

queue.WaitDone()

fmt.Println("\nAll tasks completed, press Ctrl-C to quit.")
select {}
}

func readDictionary(file *os.File) []string {
buffer := make([]byte, 500000) // 500K (almost)
EOB, err := file.Read(buffer)
if err != nil {
logger.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("")
}
return strings.Split(string(buffer[:EOB]), "\n")
}

list := strings.Split(string(buffer[:EOB]), "\n")
total := len(list)
shift := 1

func createQueue(mu *sync.Mutex, domain string, list []string, shift, total int, verbose bool) *async.WorkQueue {
queue := async.NewQueue(0, func(arg async.Job) {
ctx := arg.(*workerContext)
fuzzer.Get(ctx.Mu, &app, ctx.Domain, ctx.Path, ctx.Progress, ctx.Verbose)
})

for index, payload := range list {
modifiedIndex := index + shift

// Replace %EXT% with extensions
payload = strings.ReplaceAll(payload, "%EXT%", "js")

progress := 100 * float32(modifiedIndex) / float32(total)
progress = float32(math.Round(float64(progress))) // Round the progress to the nearest integer
progress = float32(math.Round(float64(progress)))
queue.Add(async.Job(&workerContext{
Mu: &app.Mu,
Domain: *Domain,
Mu: mu,
Domain: domain,
Path: payload,
Progress: progress,
Verbose: *Verbose,
Verbose: verbose,
}))
}

queue.WaitDone()

fmt.Println("\nAll tasks completed, press Ctrl-C to quit.")
select {}
return queue
}