forked from LeakIX/l9plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configjson_http.go
62 lines (55 loc) · 1.45 KB
/
configjson_http.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
package web
import (
"encoding/json"
"github.com/LeakIX/l9format"
)
type ConfigJsonHttp struct {
l9format.ServicePluginBase
}
func (ConfigJsonHttp) GetVersion() (int, int, int) {
return 0, 0, 1
}
func (ConfigJsonHttp) GetRequests() []l9format.WebPluginRequest {
return []l9format.WebPluginRequest{{
Method: "GET",
Path: "/config.json",
Headers: map[string]string{},
Body: []byte(""),
}}
}
func (ConfigJsonHttp) GetName() string {
return "ConfigJsonHttp"
}
func (ConfigJsonHttp) GetStage() string {
return "open"
}
func (plugin ConfigJsonHttp) Verify(request l9format.WebPluginRequest, response l9format.WebPluginResponse, event *l9format.L9Event, options map[string]string) (hasLeak bool) {
if !request.EqualAny(plugin.GetRequests()) || response.Response.StatusCode != 200 {
return false
}
var reply CodeJsonReply
var fullReply interface{}
// It's a trap :/
reply.Code = -323211
reply.Status = reply.Code
err := json.Unmarshal(response.Body, &reply)
err = json.Unmarshal(response.Body, &fullReply)
if err != nil {
return false
}
if reply.Code != -323211 || reply.Status != reply.Code {
return false
}
event.Leak.Dataset.Size = int64(len(response.Body))
response.Body, err = json.MarshalIndent(fullReply, "", " ")
if err != nil {
return false
}
event.Summary = string(response.Body)
event.Leak.Severity = l9format.SEVERITY_LOW
return true
}
type CodeJsonReply struct {
Code int `json:"code"`
Status int `json:"status"`
}