@@ -35,7 +35,7 @@ const (
35
35
// TODO: add rate limit
36
36
)
37
37
38
- func CreateAttack (hostname string , params []string , ws * websocket.Pool , db * gorm.DB , min , max , maxSuccess int ) error {
38
+ func CreateAttack (attackID uint , hostname string , params []string , ws * websocket.Pool , db * gorm.DB , min , max , maxSuccess int ) error {
39
39
slog .Info ("Creating fuzz attack" )
40
40
41
41
// Defaults
@@ -94,7 +94,7 @@ func CreateAttack(hostname string, params []string, ws *websocket.Pool, db *gorm
94
94
defer func () { <- semaphore }()
95
95
96
96
fuzzedReq := createFuzzedRequest (& req , key , value )
97
- status , err := sendRequest (fuzzedReq , ws , db )
97
+ status , err := sendRequest (fuzzedReq , ws , db , attackID )
98
98
if err != nil {
99
99
slog .Error ("Failed to send fuzzed request" , "error" , err )
100
100
} else {
@@ -133,6 +133,15 @@ workerLoop:
133
133
// Wait for active workers to complete
134
134
wg .Wait ()
135
135
136
+ attack := models.FuzzAttack {}
137
+ db .First (& attack , attackID )
138
+ if successCount > 0 {
139
+ attack .Status = "success"
140
+ } else {
141
+ attack .Status = "completed"
142
+ }
143
+ db .Save (& attack )
144
+
136
145
msg := & types.AttackCompleteMessage {
137
146
Type : types .MessageTypeAttackComplete ,
138
147
}
@@ -178,7 +187,7 @@ func createFuzzedRequest(originalReq *models.Request, key string, value int) *ht
178
187
return req
179
188
}
180
189
181
- func sendRequest (req * http.Request , ws * websocket.Pool , db * gorm.DB ) (status int , err error ) {
190
+ func sendRequest (req * http.Request , ws * websocket.Pool , db * gorm.DB , attackID uint ) (status int , err error ) {
182
191
client := & http.Client {}
183
192
resp , err := client .Do (req )
184
193
if err != nil {
@@ -216,14 +225,16 @@ func sendRequest(req *http.Request, ws *websocket.Pool, db *gorm.DB) (status int
216
225
217
226
// Create a FuzzResult and save it to the database
218
227
fuzzResult := & models.FuzzResult {
219
- Hostname : req .URL .Hostname (),
220
- IpAddress : req .RemoteAddr ,
221
- Port : req .URL .Port (),
222
- Scheme : req .URL .Scheme ,
223
- URL : req .URL .String (),
224
- Endpoint : req .URL .Path ,
225
- Request : string (requestHeaders ) + "\n " + string (requestBody ),
226
- Response : string (responseBody ),
228
+ FuzzAttackID : attackID ,
229
+ Hostname : req .URL .Hostname (),
230
+ IpAddress : req .RemoteAddr ,
231
+ Port : req .URL .Port (),
232
+ Scheme : req .URL .Scheme ,
233
+ URL : req .URL .String (),
234
+ Endpoint : req .URL .Path ,
235
+ Request : string (requestHeaders ) + "\n " + string (requestBody ),
236
+ Response : string (responseBody ),
237
+ StatusCode : resp .StatusCode ,
227
238
}
228
239
res := db .Create (fuzzResult )
229
240
if res .Error != nil {
0 commit comments