Skip to content

Commit

Permalink
write output to the file
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsha committed Sep 9, 2020
1 parent 9bf152c commit 8de2c41
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ If a cloud provider is not detected or want force searching on a specific provid
```
CloudBrute -d target.com -k keyword -t 80 -T 10 -w -c amazon
```

After execution CloudBrute will write to the same directory with following format.
```target-2020-09-09T17-20-18.txt```

## in action

Expand Down
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func main() {
}


engine.AsyncHTTPHead(urls, *threads, *timeout , details)
output := engine.GenerateOutputName(*keyword)

engine.AsyncHTTPHead(urls, *threads, *timeout , details , output)


}
18 changes: 16 additions & 2 deletions internal/brute.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func HandleHTTPRequests(reqs, results chan string, quit chan int, bar *pb.Progre

}

func AsyncHTTPHead(urls []string, threads int, timeout int , details RequestDetails) {
func AsyncHTTPHead(urls []string, threads int, timeout int , details RequestDetails , output string) {

result := make(chan string)
reqs := make(chan string, len(urls)) // buffered
Expand All @@ -169,7 +169,7 @@ func AsyncHTTPHead(urls []string, threads int, timeout int , details RequestDeta
}()



var results []string

// parsing http codes
// 500 , 502 server error
Expand All @@ -184,16 +184,23 @@ func AsyncHTTPHead(urls []string, threads int, timeout int , details RequestDeta
if res != "err" {
if strings.Contains(res, "200") {
log.Info().Msg("Open : " + "[response code :" + res +"]")
results = append(results,"Open : " + "[response code :" + res +"]")
}
if strings.Contains(res, "301") || strings.Contains(res, "402") {
log.Warn().Msg("Redirect : " + "[response code :" + res +"]")
results = append(results,"Redirect : " + "[response code :" + res +"]")

}
if strings.Contains(res, "400") || strings.Contains(res, "401") ||
strings.Contains(res, "403") {
log.Warn().Msg("Protected : " + "[response code :" + res +"]")
results = append(results,"Protected : " + "[response code :" + res +"]")

}
if strings.Contains(res, "500") || strings.Contains(res, "502") {
log.Warn().Msg("Server error :" + "[response code :" + res +"]")
results = append(results,"Server error :" + "[response code :" + res +"]")

}
}

Expand All @@ -204,12 +211,19 @@ func AsyncHTTPHead(urls []string, threads int, timeout int , details RequestDeta
bar.Set(len(urls))
bar.Finish()

if len(results) >0 {

WriteResultsToFile(results , output)
}


return
}
}




}

func GenerateMutatedUrls(wordListPath string, provider string, providerPath string, target string , environments []string) ([]string, error) {
Expand Down
47 changes: 47 additions & 0 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"bufio"
"fmt"
"github.com/rs/zerolog/log"
"math/rand"
"os"
Expand Down Expand Up @@ -41,3 +42,49 @@ func SelectRandomItem(agents []string) string {
return chosen

}

func WriteResultsToFile(results []string, output string) {


file, err := os.OpenFile(output+".txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer file.Close()

if err != nil {
log.Fatal().Err(err).Msg("failed creating file")
}

lineWriter := bufio.NewWriter(file)

for _, result := range results {
_, _ = lineWriter.WriteString(result + "\n")
}

lineWriter.Flush()


}

func Unique(input []string) []string {
unique := make(map[string]bool, len(input))
list := make([]string, len(unique))
for _, el := range input {
if len(el) != 0 {
if !unique[el] {
list = append(list, el)
unique[el] = true
}
}
}
return list
}


func GenerateOutputName(output string) string {

t := time.Now()
result := fmt.Sprintf("%s-%d-%02d-%02dT%02d-%02d-%02d",
output, t.Year(), t.Month(), t.Day(),
t.Hour(), t.Minute(), t.Second())

return result
}

0 comments on commit 8de2c41

Please sign in to comment.