|
| 1 | +package core |
| 2 | + |
| 3 | +import ( |
| 4 | + "flag" |
| 5 | + "github.com/SummerSec/SpringExploit/cmd/logs" |
| 6 | + log "github.com/sirupsen/logrus" |
| 7 | +) |
| 8 | + |
| 9 | +type Options struct { |
| 10 | + // 日志级别 |
| 11 | + Mode int |
| 12 | + // file to read |
| 13 | + File string |
| 14 | + // 传入的url |
| 15 | + Url string |
| 16 | + |
| 17 | + // 代理设置 |
| 18 | + Proxy string |
| 19 | + |
| 20 | + // 版本号 |
| 21 | + Version bool |
| 22 | + // 是否输出详细信息 |
| 23 | + Verbose bool |
| 24 | + // 线程数量 |
| 25 | + Thread int |
| 26 | + // 日志输出文件 |
| 27 | + LogFile string |
| 28 | + // 重复请求次数 |
| 29 | + Repeat int |
| 30 | + // ip 段 |
| 31 | + IP string |
| 32 | +} |
| 33 | + |
| 34 | +func (o Options) toString() interface{} { |
| 35 | + |
| 36 | + return o |
| 37 | +} |
| 38 | + |
| 39 | +func ParseOptions() *Options { |
| 40 | + options := &Options{} |
| 41 | + flag.IntVar(&options.Mode, "mode", 6, "debug mode off (default Infolevel = 0 PanicLevel = 1 FatalLevel = 2 \n"+"\t\t ErrorLevel = 3 WarnLevel = 4 InfoLevel = 5 DebugLevel = 6 TraceLevel = 7)") |
| 42 | + flag.IntVar(&options.Thread, "thread", 1, "thread number (default thread = 1)") |
| 43 | + flag.StringVar(&options.File, "file", "", "file to read example: -file=test.txt") |
| 44 | + flag.StringVar(&options.Url, "url", "", "url to read example: -url=http://www.baidu.com") |
| 45 | + flag.StringVar(&options.Proxy, "proxy", "", "proxy example: -proxy=http://127.0.0.1:8080 or -proxy=socks5://127.0.0.1:1080") |
| 46 | + flag.BoolVar(&options.Version, "version", false, "show version") |
| 47 | + flag.BoolVar(&options.Verbose, "verbose", false, "show verbose") |
| 48 | + flag.StringVar(&options.LogFile, "log", "logs.txt", "log file example: -log=/logs/logs.txt") |
| 49 | + flag.IntVar(&options.Repeat, "repeat", 3, "repeat request times") |
| 50 | + flag.StringVar(&options.IP, "ip", "", "ip segment example: -ip=192.168.0.1/24 ") |
| 51 | + flag.Parse() |
| 52 | + |
| 53 | + v := "0.0.1" |
| 54 | + |
| 55 | + if options.Version { |
| 56 | + ShowBanner(v) |
| 57 | + } else if url := options.Url; url != "" { |
| 58 | + options.Thread = 1 |
| 59 | + options.File = "" |
| 60 | + |
| 61 | + } else if options.File != "" { |
| 62 | + options.Url = "" |
| 63 | + |
| 64 | + } else { |
| 65 | + flag.PrintDefaults() |
| 66 | + } |
| 67 | + showVerbose(options) |
| 68 | + logs.SaveLogs(options.LogFile) |
| 69 | + |
| 70 | + return options |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | +func showVerbose(options *Options) { |
| 75 | + if !options.Verbose { |
| 76 | + switch options.Mode { |
| 77 | + case 1: |
| 78 | + log.SetLevel(log.PanicLevel) |
| 79 | + case 2: |
| 80 | + log.SetLevel(log.FatalLevel) |
| 81 | + case 3: |
| 82 | + log.SetLevel(log.ErrorLevel) |
| 83 | + case 4: |
| 84 | + log.SetLevel(log.WarnLevel) |
| 85 | + case 5: |
| 86 | + log.SetLevel(log.InfoLevel) |
| 87 | + case 6: |
| 88 | + log.SetLevel(log.DebugLevel) |
| 89 | + case 7: |
| 90 | + log.SetLevel(log.TraceLevel) |
| 91 | + default: |
| 92 | + log.SetLevel(log.InfoLevel) |
| 93 | + //log.SetLevel(log.DebugLevel) |
| 94 | + } |
| 95 | + } else { |
| 96 | + log.SetLevel(log.DebugLevel) |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments