forked from UD94/SecondOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
189 lines (156 loc) · 4.43 KB
/
main.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"github.com/UD94/SecondOP/Common"
"github.com/UD94/SecondOP/Function"
"github.com/go-ini/ini"
)
var channel_password string
type AutoGenerated struct {
Password string `json:"Password"`
Doldfile bool `json:"Doldfile"`
Action string `json:"Action"`
Domain string `json:"Domain"`
Type string `json:"type"`
Content []string `json:"Content"`
}
type ResponseJson struct {
code int `json:"Password"`
Content []string `json:"Content"`
}
func HandlePostJson(w http.ResponseWriter, r *http.Request) {
// 根据请求body创建一个json解析器实例
var get_result AutoGenerated
var ResponseString ResponseJson
data, err := ioutil.ReadAll(r.Body)
json.Unmarshal(data, &get_result)
if err != nil {
return
}
if get_result.Password != channel_password {
ResponseString.code = 5
ResponseString.Content = append(ResponseString.Content, "access denied")
fmt.Fprintf(w, `{"code":5,"error":"access denied"}`)
} else {
switch get_result.Action {
case "dnsresolvr":
go Function.Dns_thread(get_result.Domain)
go Function.Google_domain(get_result.Domain)
ResponseString.code = 0
case "config":
_, err := Config_Workstation(get_result.Type, get_result.Content, get_result.Doldfile)
if err != nil {
ResponseString.code = 11
ResponseString.Content = append(ResponseString.Content, "config failed")
} else {
ResponseString.code = 0
}
case "md5":
result, err := Function.Md5_query(get_result.Content[0])
if err != nil {
switch result {
case "nopass":
ResponseString.code = 7
ResponseString.Content = append(ResponseString.Content, "not found")
case "nodatabse":
ResponseString.code = 8
ResponseString.Content = append(ResponseString.Content, "database not ready")
}
} else {
ResponseString.code = 0
ResponseString.Content = append(ResponseString.Content, result)
}
case "saveproject":
Function.Save()
case "readproject":
Function.Read()
case "analysis":
switch get_result.Type {
case "nmap":
Function.Nmap()
case "fscan":
Function.Fscan()
case "mimikatz":
Function.Mimikatz(get_result.Content)
}
case "downloadjob":
file, _ := os.Open("Cache\\" + get_result.Content[0])
defer file.Close()
fileHeader := make([]byte, 512)
file.Read(fileHeader)
fileStat, _ := file.Stat()
w.Header().Set("Content-Disposition", "attachment; filename="+get_result.Content[0])
w.Header().Set("Content-Type", http.DetectContentType(fileHeader))
w.Header().Set("Content-Length", strconv.FormatInt(fileStat.Size(), 10))
file.Seek(0, 0)
io.Copy(w, file)
ResponseString.code = 0
case "proxy":
default:
files, err := ioutil.ReadDir(`Cache`)
if err != nil {
panic(err)
}
ResponseString.code = 0
for _, v := range files {
ResponseString.Content = append(ResponseString.Content, v.Name())
}
}
response, _ := json.Marshal(ResponseString)
fmt.Fprint(w, string(response))
}
}
func Config_Workstation(configtype string, content []string, Doldfile bool) (string, error) {
cfg, err := ini.Load("config.ini")
if err != nil {
fmt.Printf("Load config error")
}
switch configtype {
case "dnsdomainconfig":
if Doldfile {
Common.DeleteFile("domain.txt")
}
for _, s := range content {
Common.Write_result(s+"\n", "domain.txt")
}
case "md5config":
_, err := Function.MD5_insert(content[0], content[1])
if err != nil {
return "insert md5 error", errors.New("md5configerror")
}
case "server":
cfg.Section("mysql").Key("ip").SetValue(content[0])
cfg.Section("mysql").Key("port").SetValue(content[1])
cfg.Section("mysql").Key("user").SetValue(content[2])
cfg.Section("mysql").Key("password").SetValue(content[3])
cfg.Section("mysql").Key("database").SetValue(content[4])
case "communicationconfig":
channel_password = content[0]
default:
return "noconfig", errors.New("not config")
}
return "success", nil
}
func Starthttps(ip string) {
http.HandleFunc("/post", HandlePostJson)
err := http.ListenAndServeTLS(ip+":4321", "server.crt", "server.key", nil)
if err != nil {
log.Fatal("listen error:", err.Error())
}
}
func main() {
var ip string
flag.StringVar(&channel_password, "p", "ud94iscreater", "连接密码,默认为ud94iscreater")
flag.StringVar(&ip, "i", "0.0.0.0", "监听ip,默认为0.0.0.0")
flag.Parse()
Starthttps(ip)
}