-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlmap.go
117 lines (107 loc) · 2.16 KB
/
sqlmap.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type SQLmapTask struct {
id string
server string
}
type SQLmapTaskInfo struct {
Url string `json:"url"`
// Headers map[string]interface{}
}
func (t SQLmapTask) unmarshalJSON(resp *http.Response, ptr interface{}) {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Panic(err)
}
if err := json.Unmarshal(data, ptr); err != nil {
log.Panic(err)
}
}
func (t *SQLmapTask) create(server string) {
if server != "" {
t.server = server
} else {
t.server = "http://127.0.0.1:8775"
}
resp, err := http.Get(t.server + "/task/new")
if err != nil {
log.Panic(err)
}
var result struct {
Success bool
Taskid string
}
t.unmarshalJSON(resp, &result)
if !result.Success {
log.Panic("Failed to create new task")
}
t.id = result.Taskid
}
func (t *SQLmapTask) delete() {
resp, err := http.Get(t.server + "/task/" + t.id + "/delete")
if err != nil {
log.Panic(err)
}
var result struct {
Success bool
Message string
}
t.unmarshalJSON(resp, &result)
if !result.Success {
log.Panic(result.Message)
}
}
func (t *SQLmapTask) start(info SQLmapTaskInfo) {
data, err := json.Marshal(info)
if err != nil {
log.Panic(err)
}
resp, err := http.Post(t.server+"/scan/"+t.id+"/start", "application/json", bytes.NewReader(data))
if err != nil {
log.Panic(err)
}
var result struct {
Success bool
EngineID int
}
t.unmarshalJSON(resp, &result)
if !result.Success {
log.Panic("Failed to start task " + t.id)
}
}
func (t SQLmapTask) status() string {
resp, err := http.Get(t.server + "/scan/" + t.id + "/status")
if err != nil {
log.Panic(err)
}
var result struct {
Success bool
Status string
}
t.unmarshalJSON(resp, &result)
if !result.Success {
log.Panic("Failed to check status of task " + t.id)
}
return result.Status
}
func (t SQLmapTask) result() interface{} {
resp, err := http.Get(t.server + "/scan/" + t.id + "/data")
if err != nil {
log.Panic(err)
}
var result struct {
Success bool
Data interface{}
}
t.unmarshalJSON(resp, &result)
if !result.Success {
log.Panic("Failed to get result of task " + t.id)
}
return result.Data
}