/
json.go
67 lines (63 loc) · 1.56 KB
/
json.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
package plugin
import (
"net/http"
"regexp"
"strings"
"github.com/opensec-cn/kunpeng/util"
)
// JSONPlugin JSON插件
type JSONPlugin struct {
Target string `json:"target"`
Meta Plugin `json:"meta"`
Request struct {
Path string `json:"path"`
PostData string `json:"postdata"`
} `json:"request"`
Verify struct {
Type string `json:"type"`
Match string `json:"match"`
} `json:"verify"`
Extra bool
}
// jsonCheck JSON插件漏洞检测
func jsonCheck(URL string, p JSONPlugin) (bool, Plugin) {
var request *http.Request
var result Plugin
var vulURL = URL + p.Request.Path
if p.Request.PostData != "" {
request, _ = http.NewRequest("POST", vulURL, strings.NewReader(p.Request.PostData))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
} else {
request, _ = http.NewRequest("GET", vulURL, nil)
}
resp, err := util.RequestDo(request, true)
if err != nil {
return false, result
}
switch p.Verify.Type {
case "string":
if strings.Contains(resp.ResponseRaw, p.Verify.Match) {
result = p.Meta
result.Request = resp.RequestRaw
result.Response = resp.ResponseRaw
return true, result
}
break
case "regex":
if ok, _ := regexp.MatchString(p.Verify.Match, resp.ResponseRaw); ok {
result = p.Meta
result.Request = resp.RequestRaw
result.Response = resp.ResponseRaw
return true, result
}
break
case "md5":
if util.GetMd5(resp.Body) == p.Verify.Match {
result = p.Meta
result.Request = resp.RequestRaw
result.Response = resp.ResponseRaw
return true, result
}
}
return false, result
}