-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrut_force.go
92 lines (76 loc) · 1.73 KB
/
brut_force.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"time"
)
func checkResponse(res string) bool {
var ret bool = false
if strings.Contains(res, _response) {
ret = true
}
if _not {
return !ret
}
return ret
}
func brutForcePOST() {
start := time.Now()
queue := make(chan bool, _concurrencyLevel)
var index int64
scanner := getFile(_wordlistFile)
for scanner.Scan() {
queue <- true
go func(value string) {
defer func() { <-queue }()
if err := scanner.Err(); err != nil { // check scan file
log.Fatal(err)
}
if index >= _limit && _limit > -1 { // check limit
fmt.Printf("Limit: %d\n", _limit)
log.Printf("Took %s", time.Since(start))
os.Exit(0)
}
// set payload and request
var stringPayload string = fmt.Sprintf("{\"%s\":\"%s\"}", _payload, value)
if _generalPayload != "" {
stringPayload = fmt.Sprintf("{\"%s\":\"%s\", %s}", _payload, value, _generalPayload)
}
payload := []byte(stringPayload)
buffer := bytes.NewBuffer(payload)
resp, err := http.Post(_url, "application/json", buffer)
if err != nil {
log.Fatalf("An Error Occured %v", err)
}
defer resp.Body.Close()
//Read the response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("\nTest n°%d\t|\tpayload: %v\t|\tresponse: %v\n", index, string(payload), string(body))
if checkResponse(string(body)) {
log.Printf("Took %s", time.Since(start))
os.Exit(0)
}
index++
}(scanner.Text())
}
for i := 0; i < int(_concurrencyLevel); i++ {
queue <- true
}
log.Printf("Took %s", time.Since(start))
}
func brutForceGET() {
}
func brutForcePUT() {
}
func brutForcePATCH() {
}
func brutForceDELETE() {
}