Skip to content

Commit 8de2c41

Browse files
committed
write output to the file
1 parent 9bf152c commit 8de2c41

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ If a cloud provider is not detected or want force searching on a specific provid
130130
```
131131
CloudBrute -d target.com -k keyword -t 80 -T 10 -w -c amazon
132132
```
133-
133+
After execution CloudBrute will write to the same directory with following format.
134+
```target-2020-09-09T17-20-18.txt```
134135

135136
## in action
136137

cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ func main() {
171171
}
172172

173173

174-
engine.AsyncHTTPHead(urls, *threads, *timeout , details)
174+
output := engine.GenerateOutputName(*keyword)
175+
176+
engine.AsyncHTTPHead(urls, *threads, *timeout , details , output)
175177

176178

177179
}

internal/brute.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func HandleHTTPRequests(reqs, results chan string, quit chan int, bar *pb.Progre
150150

151151
}
152152

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

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

171171

172-
172+
var results []string
173173

174174
// parsing http codes
175175
// 500 , 502 server error
@@ -184,16 +184,23 @@ func AsyncHTTPHead(urls []string, threads int, timeout int , details RequestDeta
184184
if res != "err" {
185185
if strings.Contains(res, "200") {
186186
log.Info().Msg("Open : " + "[response code :" + res +"]")
187+
results = append(results,"Open : " + "[response code :" + res +"]")
187188
}
188189
if strings.Contains(res, "301") || strings.Contains(res, "402") {
189190
log.Warn().Msg("Redirect : " + "[response code :" + res +"]")
191+
results = append(results,"Redirect : " + "[response code :" + res +"]")
192+
190193
}
191194
if strings.Contains(res, "400") || strings.Contains(res, "401") ||
192195
strings.Contains(res, "403") {
193196
log.Warn().Msg("Protected : " + "[response code :" + res +"]")
197+
results = append(results,"Protected : " + "[response code :" + res +"]")
198+
194199
}
195200
if strings.Contains(res, "500") || strings.Contains(res, "502") {
196201
log.Warn().Msg("Server error :" + "[response code :" + res +"]")
202+
results = append(results,"Server error :" + "[response code :" + res +"]")
203+
197204
}
198205
}
199206

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

214+
if len(results) >0 {
215+
216+
WriteResultsToFile(results , output)
217+
}
218+
219+
207220
return
208221
}
209222
}
210223

211224

212225

226+
213227
}
214228

215229
func GenerateMutatedUrls(wordListPath string, provider string, providerPath string, target string , environments []string) ([]string, error) {

internal/utils.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package internal
22

33
import (
44
"bufio"
5+
"fmt"
56
"github.com/rs/zerolog/log"
67
"math/rand"
78
"os"
@@ -41,3 +42,49 @@ func SelectRandomItem(agents []string) string {
4142
return chosen
4243

4344
}
45+
46+
func WriteResultsToFile(results []string, output string) {
47+
48+
49+
file, err := os.OpenFile(output+".txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
50+
defer file.Close()
51+
52+
if err != nil {
53+
log.Fatal().Err(err).Msg("failed creating file")
54+
}
55+
56+
lineWriter := bufio.NewWriter(file)
57+
58+
for _, result := range results {
59+
_, _ = lineWriter.WriteString(result + "\n")
60+
}
61+
62+
lineWriter.Flush()
63+
64+
65+
}
66+
67+
func Unique(input []string) []string {
68+
unique := make(map[string]bool, len(input))
69+
list := make([]string, len(unique))
70+
for _, el := range input {
71+
if len(el) != 0 {
72+
if !unique[el] {
73+
list = append(list, el)
74+
unique[el] = true
75+
}
76+
}
77+
}
78+
return list
79+
}
80+
81+
82+
func GenerateOutputName(output string) string {
83+
84+
t := time.Now()
85+
result := fmt.Sprintf("%s-%d-%02d-%02dT%02d-%02d-%02d",
86+
output, t.Year(), t.Month(), t.Day(),
87+
t.Hour(), t.Minute(), t.Second())
88+
89+
return result
90+
}

0 commit comments

Comments
 (0)