-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathroot.go
106 lines (95 loc) · 3.32 KB
/
root.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
package cmd
import (
"bufio"
"fmt"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"github.com/yhy0/Jie/conf"
"github.com/yhy0/Jie/pkg/output"
"github.com/yhy0/logging"
"io"
"os"
"strings"
)
/**
@author yhy
@since 2023/8/19
@desc //TODO
**/
var (
Poc []string
host string
domain string
proxy string
)
var rootCmd = &cobra.Command{
Use: "Jie",
Short: "A Powerful security assessment and utilization tools",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// PersistentPreRun 在每个子命令执行之前都会执行
initTargetList()
// 初始化日志
logging.Logger = logging.New(conf.GlobalConfig.Debug, "", "Jie", true)
// 配置文件生成
conf.Init()
if proxy != "" {
conf.GlobalConfig.Http.Proxy = proxy
}
// 结果输出
go output.Write(true)
},
}
func init() {
fmt.Println("\t" + aurora.Green(conf.Banner).String())
fmt.Println("\t\t" + aurora.Red("v"+conf.Version).String())
fmt.Println("\t" + aurora.Blue(conf.Website).String() + "\n")
fmt.Println(aurora.Red("Use with caution. You are responsible for your actions.").String())
fmt.Println(aurora.Red("Developers assume no liability and are not responsible for any misuse or damage.").String() + "\n")
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.PersistentFlags().StringVarP(&conf.GlobalConfig.Options.Target, "target", "t", "", "target\r\n主动扫描目标,被动下不需要指定")
rootCmd.PersistentFlags().StringVarP(&conf.GlobalConfig.Options.TargetFile, "file", "f", "", "target file\r\n主动扫描目标列表,每行一个")
rootCmd.PersistentFlags().StringVarP(&conf.GlobalConfig.Options.Output, "out", "o", "", "output report file(eg:vulnerability_report.html)\r\n漏洞结果报告保存地址")
rootCmd.PersistentFlags().StringVar(&proxy, "proxy", "", "proxy, (example: --proxy http://127.0.0.1:8080)\r\n指定 http/https 代理")
rootCmd.PersistentFlags().BoolVar(&conf.GlobalConfig.Debug, "debug", false, "debug")
// rootCmd.MarkPersistentFlagRequired("target")
webScanCmdInit()
shiroCmdinit()
struts2CmdInit()
webLogicCmdInit()
log4jCmdInit()
apolloCmdInit()
fastjsonCmdInit()
otherCmdInit()
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func initTargetList() {
if conf.GlobalConfig.Options.Target != "" {
conf.GlobalConfig.Options.Targets = append(conf.GlobalConfig.Options.Targets, conf.GlobalConfig.Options.Target)
}
if conf.GlobalConfig.Options.TargetFile != "" {
file, err := os.Open(conf.GlobalConfig.Options.TargetFile)
if err != nil {
fmt.Println("文件不存在", err)
return
}
buffer := bufio.NewReader(file)
for {
line, err := buffer.ReadString('\n')
line = strings.TrimSpace(line)
if err != nil {
if err == io.EOF {
return
}
fmt.Println("未知错误", err)
return
}
conf.GlobalConfig.Options.Targets = append(conf.GlobalConfig.Options.Targets, line)
}
}
return
}