-
Notifications
You must be signed in to change notification settings - Fork 25
/
app.go
523 lines (459 loc) · 12.8 KB
/
app.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/buger/jsonparser"
uuid "github.com/satori/go.uuid"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/yhy0/ChYing/conf"
"github.com/yhy0/ChYing/pkg/file"
"github.com/yhy0/ChYing/pkg/httpx"
"github.com/yhy0/ChYing/pkg/utils"
"github.com/yhy0/ChYing/tools/burpSuite"
"github.com/yhy0/ChYing/tools/decoder"
"github.com/yhy0/ChYing/tools/fuzz"
"github.com/yhy0/ChYing/tools/gadget"
"github.com/yhy0/ChYing/tools/nucleiY"
"github.com/yhy0/ChYing/tools/swagger"
"github.com/yhy0/ChYing/tools/twj"
"github.com/yhy0/logging"
"os"
"path/filepath"
"strings"
"time"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// Menu 应用菜单
func (a *App) Menu() *menu.Menu {
return menu.NewMenuFromItems(
menu.SubMenu("承影", menu.NewMenuFromItems(
menu.Text("关于", nil, func(_ *menu.CallbackData) {
a.diag(conf.Description, false)
}),
menu.Text("检查更新", nil, func(_ *menu.CallbackData) {
resp, err := httpx.Get("https://api.github.com/repos/yhy0/ChYing/tags")
if err != nil {
a.diag("检查更新出错\n"+err.Error(), true)
return
}
lastVersion, err := jsonparser.GetString([]byte(resp.Body), "[0]", "name")
if err != nil {
a.diag("检查更新出错\n"+err.Error(), true)
return
}
needUpdate := conf.Version < lastVersion
msg := conf.VersionNewMsg
btns := []string{conf.BtnConfirmText}
if needUpdate {
msg = fmt.Sprintf(conf.VersionOldMsg, lastVersion)
btns = []string{"确定", "取消"}
}
selection, err := a.diag(msg, false, btns...)
if err != nil {
return
}
if needUpdate && selection == conf.BtnConfirmText {
url := fmt.Sprintf("https://github.com/yhy0/ChYing/releases/tag/%s", lastVersion)
runtime.BrowserOpenURL(a.ctx, url)
}
}),
menu.Text(
"主页",
keys.Combo("H", keys.CmdOrCtrlKey, keys.ShiftKey),
func(_ *menu.CallbackData) {
runtime.BrowserOpenURL(a.ctx, "https://github.com/yhy0/ChYing/")
},
),
menu.Separator(),
menu.Text("退出", keys.CmdOrCtrl("Q"), func(_ *menu.CallbackData) {
runtime.Quit(a.ctx)
}),
)),
menu.EditMenu(),
menu.SubMenu("Help", menu.NewMenuFromItems(
menu.Text(
"打开配置文件夹",
keys.Combo("C", keys.CmdOrCtrlKey, keys.ShiftKey),
func(_ *menu.CallbackData) {
err := utils.OpenFolder(file.ChyingDir)
if err != nil {
a.diag("Failed to open folder: \n"+err.Error(), true)
return
}
},
),
)),
)
}
// diag ...
func (a *App) diag(message string, error bool, buttons ...string) (string, error) {
if len(buttons) == 0 {
buttons = []string{
conf.BtnConfirmText,
}
}
var t runtime.DialogType
if error {
t = runtime.ErrorDialog
} else {
t = runtime.InfoDialog
}
return runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: t,
Title: conf.Title,
Message: message,
CancelButton: conf.BtnCancelText,
DefaultButton: conf.BtnConfirmText,
Buttons: buttons,
})
}
// startup is called when the app starts. The context is saved ,so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
burpSuite.Ctx = ctx
// 启动中间人代理
burpSuite.Init()
burpSuite.HotConf()
if utils.IsPortOccupied(burpSuite.Settings.ProxyPort) {
port, err := utils.GetRandomUnusedPort()
if err != nil {
logging.Logger.Errorln(err)
burpSuite.Settings.ProxyPort = 65530
}
burpSuite.Settings.ProxyPort = port
}
go burpSuite.Run(burpSuite.Settings.ProxyPort)
runtime.EventsEmit(ctx, "ProxyPort", burpSuite.Settings.ProxyPort)
runtime.EventsEmit(ctx, "Exclude", burpSuite.Settings.Exclude)
runtime.EventsEmit(ctx, "Include", burpSuite.Settings.Include)
runtime.EventsEmit(ctx, "FilterSuffix", burpSuite.Settings.FilterSuffix)
// 通知前端各种数据更改
go func() {
for {
select {
case percentage := <-twj.Percentage:
runtime.EventsEmit(ctx, "Percentage", percentage)
case percentage := <-fuzz.FuzzPercentage: // fuzz 的进度条
runtime.EventsEmit(ctx, "FuzzPercentage", percentage)
case _fuzz := <-fuzz.FuzzChan: // fuzz 表格数据
runtime.EventsEmit(ctx, "Fuzz", _fuzz)
case _swagger := <-swagger.SwaggerChan:
if _swagger.StatusCode == 403 {
fuzz.Bypass403(_swagger.Url, _swagger.Method)
}
runtime.EventsEmit(ctx, "swagger", _swagger)
// burp 相关
case history := <-burpSuite.HttpHistory:
if len(burpSuite.Settings.Exclude) > 0 {
if !utils.RegexpStr(burpSuite.Settings.Exclude, history.Host) {
if len(burpSuite.Settings.Include) > 0 && utils.RegexpStr(burpSuite.Settings.Include, history.Host) {
runtime.EventsEmit(ctx, "HttpHistory", history)
} else {
runtime.EventsEmit(ctx, "HttpHistory", history)
}
}
} else if len(burpSuite.Settings.Include) > 0 && utils.RegexpStr(burpSuite.Settings.Include, history.Host) {
runtime.EventsEmit(ctx, "HttpHistory", history)
} else {
runtime.EventsEmit(ctx, "HttpHistory", history)
}
case event := <-nucleiY.ResultEvent:
res := nucleiY.Result{
Url: event.Matched,
Name: event.Info.Name,
Request: event.Request,
Response: event.Response,
}
runtime.EventsEmit(ctx, "nucleiYRes", res)
}
}
}()
httpx.NewSession()
}
type Message struct {
Msg string `json:"msg"`
Error string `json:"error"`
}
func (a *App) Parser(jwt string) *twj.Jwt {
parseJWT, err := twj.ParseJWT(jwt)
if err != nil {
parseJWT = &twj.Jwt{
Header: "",
Payload: "",
Message: err.Error(),
SignatureStr: "",
}
return parseJWT
}
return parseJWT
}
func (a *App) Verify(jwt string, secret string) (msg Message) {
parseJWT, err := twj.Verify(jwt, secret)
if err != nil {
logging.Logger.Errorln(err)
msg.Msg = ""
msg.Error = err.Error()
return
}
h, err := json.Marshal(parseJWT)
msg.Msg = string(h)
msg.Error = ""
return
}
func (a *App) Brute() string {
// 爆破前判断是否有进程在爆破,如果有停止
if twj.Flag {
twj.Stop = true
time.Sleep(1 * time.Second)
twj.Stop = false
}
return twj.GenerateSignature()
}
func (a *App) TwjStop() {
twj.Stop = true
time.Sleep(2 * time.Second)
twj.Stop = false
}
func (a *App) Proxy(proxy string) (msg Message) {
if proxy == "" {
conf.Proxy = ""
httpx.NewSession()
} else {
_, err := httpx.ValidateProxyURL(proxy)
if err != nil {
msg.Msg = "代理设置失败"
msg.Error = err.Error()
return
}
msg.Msg = "代理设置成功: " + proxy
msg.Error = ""
conf.Proxy = proxy
httpx.NewSession()
return
}
return
}
// Swagger 扫描
func (a *App) Swagger(target string) {
if target != "" {
swagger.Scan(target)
}
}
func (a *App) Fuzz(target string, actions []string, filePath string) string {
if target != "" && len(actions) > 0 {
err := fuzz.Fuzz(target, actions, filePath)
if err != nil {
return err.Error()
}
} else {
return "目标和模式不能为空"
}
return ""
}
func (a *App) FuzzStop() {
fuzz.Stop = true
time.Sleep(2 * time.Second)
fuzz.Stop = false
}
// burp 相关
// Settings 配置
func (a *App) Settings(setting burpSuite.SettingUI) string {
if burpSuite.Settings.ProxyPort != setting.ProxyPort && utils.IsPortOccupied(setting.ProxyPort) {
return "端口被占用"
} else {
if burpSuite.Settings.ProxyPort != setting.ProxyPort {
err := burpSuite.Restart(setting.ProxyPort)
if err != "" {
logging.Logger.Errorln(err)
return err
}
}
burpSuite.Settings.ProxyPort = setting.ProxyPort
burpSuite.Settings.Exclude = utils.SplitStringByLines(setting.Exclude)
burpSuite.Settings.Include = utils.SplitStringByLines(setting.Include)
burpSuite.Settings.FilterSuffix = strings.Split(setting.FilterSuffix, ",")
runtime.EventsEmit(a.ctx, "ProxyPort", burpSuite.Settings.ProxyPort)
runtime.EventsEmit(a.ctx, "Exclude", strings.Join(burpSuite.Settings.Exclude, "\r\n"))
runtime.EventsEmit(a.ctx, "Include", strings.Join(burpSuite.Settings.Include, "\r\n"))
runtime.EventsEmit(a.ctx, "FilterSuffix", strings.Join(burpSuite.Settings.FilterSuffix, ","))
// 更改配置文件
exclude := ""
if len(burpSuite.Settings.Exclude) == 0 {
exclude = " - \r\n"
} else {
for _, e := range burpSuite.Settings.Exclude {
exclude += fmt.Sprintf(" - %s\r\n", e)
}
}
include := ""
if len(burpSuite.Settings.Include) == 0 {
include = " - \r\n"
} else {
for _, i := range burpSuite.Settings.Include {
include += fmt.Sprintf(" - %s\r\n", i)
}
}
filterSuffix := ""
if len(burpSuite.Settings.FilterSuffix) == 0 {
filterSuffix = " - \r\n"
} else {
for _, i := range burpSuite.Settings.FilterSuffix {
filterSuffix += fmt.Sprintf(" - %s\r\n", i)
}
}
var defaultYamlByte = []byte(fmt.Sprintf("port: %d\r\nexclude:\r\n%sinclude:\r\n%s\r\nfilterSuffix:\r\n%s", burpSuite.Settings.ProxyPort, exclude, include, filterSuffix))
err := burpSuite.WriteYamlConfig(defaultYamlByte)
if err != nil {
a.diag(err.Error(), true)
return err.Error()
}
return ""
}
}
// GetBurpSettings 配置
func (a *App) GetBurpSettings() *burpSuite.Setting {
return burpSuite.Settings
}
// Intercept 拦截包
func (a *App) Intercept(intercept, wait bool, request string) int {
if intercept {
burpSuite.Intercept = true
} else {
burpSuite.Intercept = false
}
if wait && burpSuite.Sum != 0 {
burpSuite.InterceptBody = request
burpSuite.Sum -= 1
<-burpSuite.Done
}
return burpSuite.Sum
}
// GetHistoryDump 代理记录
func (a *App) GetHistoryDump(id int) *burpSuite.HTTPBody {
return burpSuite.HTTPBodyMap.ReadMap(id)
}
// InterceptSend 从 Intercept 发给 Repeater\Intruder 界面处理
func (a *App) InterceptSend(name string) {
runtime.EventsEmit(a.ctx, name, burpSuite.HttpBodyInter)
return
}
// SendToRepeater 发给 Repeater 界面处理
func (a *App) SendToRepeater(id int) {
runtime.EventsEmit(a.ctx, "RepeaterBody", burpSuite.HTTPBodyMap.ReadMap(id))
return
}
// Raw Repeater 请求
func (a *App) Raw(request string, target string, id string) (httpBody *burpSuite.HTTPBody) {
// 说明第一次
if id == "" {
id = uuid.NewV4().String()
}
resp, err := httpx.Raw(request, target)
if err != nil {
return
}
httpBody = &burpSuite.HTTPBody{
TargetUrl: target,
Request: resp.RequestDump,
Response: resp.ResponseDump,
UUID: id,
}
value, ok := burpSuite.RepeaterBodyMap[id]
if ok {
_id := len(value)
value[_id] = httpBody
return
}
// 初始化
burpSuite.RepeaterBodyMap[id] = make(map[int]*burpSuite.HTTPBody)
burpSuite.RepeaterBodyMap[id][0] = httpBody
return
}
// SendToIntruder 发给 Intruder 界面处理
func (a *App) SendToIntruder(id int) {
runtime.EventsEmit(a.ctx, "IntruderBody", burpSuite.HTTPBodyMap.ReadMap(id))
return
}
// Intruder 处理 Intruder 传来的参数
func (a *App) Intruder(target string, req string, payloads []string, rules []string, attackType string, uuid string) {
for i, rule := range rules {
if rule == "" {
rules[i] = "None"
}
}
burpSuite.Intruder(target, req, payloads, rules, attackType, uuid, a.ctx)
}
// GetAttackDump Intruder attack 记录
func (a *App) GetAttackDump(uuid string, id int) *burpSuite.HTTPBody {
return burpSuite.IntruderMap[uuid].ReadMap(id)
}
func (a *App) Decoder(str string, mode string) string {
switch mode {
case "DecodeUnicode":
return decoder.DecodeUnicode(str)
case "EncodeUnicode":
return decoder.EncodeUnicode(str)
case "DecodeURL":
return decoder.DecodeURL(str)
case "EncodeURL":
return decoder.EncodeURL(str)
case "DecodeBase64":
return decoder.DecodeBase64(str)
case "EncodeBase64":
return decoder.EncodeBase64(str)
case "DecodeHex":
return decoder.DecodeHex(str)
case "EncodeHex":
return decoder.EncodeHex(str)
case "MD5":
return decoder.Md5(str)
default:
return str
}
}
func (a *App) TaskList(out string) map[string]string {
return gadget.Tasklist(out)
}
func (a *App) ShiroDecrypt(key, data string) *gadget.Shiro {
if data == "" {
return nil
}
shiro, err := gadget.DecryptShiro(key, data)
if err != nil {
return nil
}
return shiro
}
// NucleiLoad 加载模板
func (a *App) NucleiLoad() []nucleiY.Options {
nucleiY.New("")
var options []nucleiY.Options
for k, v := range nucleiY.Pocs {
var child []string
for _, t := range v {
child = append(child, t.Info.Name)
}
options = append(options, nucleiY.Options{Label: k, Children: child})
}
return options
}
// NucleiY 漏洞扫描
func (a *App) NucleiY(target string, tag string, proxy string) string {
templatesTempDir := filepath.Join(file.ChyingDir, "nucleiY")
if _, err := os.Stat(templatesTempDir); err != nil {
// 不存在,创建
logging.Logger.Errorln("")
return "nucleiY not find, https://github.com/yhy0/nucleiY"
}
return nucleiY.Scan(target, tag, proxy)
}