-
Notifications
You must be signed in to change notification settings - Fork 0
/
soar.go
48 lines (41 loc) · 1.28 KB
/
soar.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
package sqlrisk
import (
"encoding/json"
"fmt"
"os/exec"
)
const soarBin = "D:\\User\\sunkai\\Desktop\\soar.windows-amd64.exe"
type SQLRiskResult struct {
ID string `json:"ID"`
Fingerprint string `json:"Finger"`
Score int `json:"Score"`
Sample string `json:"Sample"`
Explain interface{} `json:"Explain"`
HeuristicRules []struct {
Item string `json:"Item"`
Severity string `json:"Severity"`
Summary string `json:"Summary"`
Content string `json:"Content"`
Case string `json:"Case"`
Position int `json:"Position"`
} `json:"HeuristicRules"`
IndexRules interface{} `json:"IndexRules"`
Tables []string `json:"Tables"`
}
func SoarVersion() (string, error) {
stdout, err := exec.Command(soarBin, "-version").CombinedOutput()
return string(stdout), err
}
func SoarRun(sql string) ([]SQLRiskResult, error) {
result := make([]SQLRiskResult, 0, 1)
arg := fmt.Sprintf("-query=%s", sql)
stdout, err := exec.Command(soarBin, "-report-type=json", arg).CombinedOutput()
if err != nil {
return result, fmt.Errorf("soar exec '%s', %s ", sql, err)
}
err = json.Unmarshal(stdout, &result)
if err != nil {
return result, fmt.Errorf("fail to unmarshal '%s', %s ", string(stdout), err)
}
return result, err
}