Skip to content

Commit b08ec0c

Browse files
committed
init
1 parent abfbea2 commit b08ec0c

File tree

18 files changed

+615
-1
lines changed

18 files changed

+615
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
1+
.idea
2+
logs/**

cmd/commons/core/banner.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package core
2+
3+
import log "github.com/sirupsen/logrus"
4+
5+
const banner = `
6+
7+
8+
9+
`
10+
11+
func ShowBanner(Version string) {
12+
log.Println(banner)
13+
log.Println("Version:", Version)
14+
15+
}

cmd/commons/core/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package core

cmd/commons/core/getreq.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package core
2+
3+
// GetReq get request
4+
func GetReq() map[string]string {
5+
var req = map[string]string{
6+
"method": "GET",
7+
}
8+
return req
9+
10+
}

cmd/commons/core/options.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
}

cmd/commons/core/request.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package core
2+
3+
type ReqInfo struct {
4+
method string
5+
url string
6+
body string
7+
header map[string]string
8+
proxy string
9+
timeout string
10+
repeat string
11+
mode string
12+
}
13+
14+
func (r *ReqInfo) Method() string {
15+
return r.method
16+
}
17+
18+
func (r *ReqInfo) SetMethod(method string) {
19+
r.method = method
20+
}
21+
22+
func (r *ReqInfo) Url() string {
23+
return r.url
24+
}
25+
26+
func (r *ReqInfo) SetUrl(url string) {
27+
r.url = url
28+
}
29+
30+
func (r *ReqInfo) Body() string {
31+
return r.body
32+
}
33+
34+
func (r *ReqInfo) SetBody(body string) {
35+
r.body = body
36+
}
37+
38+
func (r *ReqInfo) Header() map[string]string {
39+
return r.header
40+
}
41+
42+
func (r *ReqInfo) SetHeader(header map[string]string) {
43+
r.header = header
44+
}
45+
46+
func (r *ReqInfo) Proxy() string {
47+
return r.proxy
48+
}
49+
50+
func (r *ReqInfo) SetProxy(proxy string) {
51+
r.proxy = proxy
52+
}
53+
54+
func (r *ReqInfo) Timeout() string {
55+
return r.timeout
56+
}
57+
58+
func (r *ReqInfo) SetTimeout(timeout string) {
59+
r.timeout = timeout
60+
}
61+
62+
func (r *ReqInfo) Repeat() string {
63+
return r.repeat
64+
}
65+
66+
func (r *ReqInfo) SetRepeat(repeat string) {
67+
r.repeat = repeat
68+
}
69+
70+
func (r *ReqInfo) Mode() string {
71+
return r.mode
72+
}
73+
74+
func (r *ReqInfo) SetMode(mode string) {
75+
r.mode = mode
76+
}
77+
78+
//func NewReqInfo(hashmap map[string]interface{}) *ReqInfo {
79+
// reqInfo := &ReqInfo{
80+
// method: hashmap["method"].(string),
81+
// url: hashmap["url"].(string),
82+
// body: hashmap["body"].(string),
83+
// header: hashmap["header"].(map[string]string),
84+
// proxy: hashmap["proxy"].(string),
85+
// timeout: hashmap["timeout"].(string),
86+
// repeat: hashmap["repeat"].(string),
87+
// mode: hashmap["mode"].(string),
88+
// }
89+
//
90+
// return reqInfo
91+
//}
92+
93+
func NewReqInfo() *ReqInfo {
94+
reqInfo := &ReqInfo{
95+
method: "",
96+
url: "",
97+
body: "",
98+
header: make(map[string]string),
99+
proxy: "",
100+
timeout: "",
101+
repeat: "",
102+
mode: "",
103+
}
104+
return reqInfo
105+
}

cmd/commons/core/runner.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package core
2+
3+
import (
4+
"encoding/json"
5+
"github.com/SummerSec/SpringExploit/cmd/commons/utils"
6+
"github.com/fatih/structs"
7+
log "github.com/sirupsen/logrus"
8+
)
9+
10+
type Runner struct {
11+
options *Options
12+
}
13+
14+
func NewRunner(options *Options) (*Runner, error) {
15+
r := Runner{options: options}
16+
mops := structs.Map(&r.options)
17+
data, _ := json.Marshal(mops)
18+
log.Info("Runner created")
19+
log.Debug(mops)
20+
log.Debug("Runner options: ", string(data))
21+
return &r, nil
22+
23+
}
24+
25+
func (r *Runner) Run() {
26+
log.Info("Runner Running")
27+
f := r.options.File
28+
var urls []string
29+
if f == "" {
30+
urls = append(urls, r.options.Url)
31+
} else {
32+
urls, _ = utils.ReadFile(r.options.File)
33+
}
34+
var i = 0
35+
k := r.options.Thread
36+
for i < len(urls) {
37+
for t := 0; t < k; t++ {
38+
if urls[i] != "" {
39+
go Start(urls[i]) // Start 3 goroutines
40+
i++
41+
} else {
42+
break
43+
}
44+
}
45+
}
46+
47+
}
48+
49+
func Start(url string) {
50+
log.Info("Runner started")
51+
log.Infoln("testing URL: ", url)
52+
53+
}

cmd/commons/utils/httpclient.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package utils
2+
3+
import (
4+
"encoding/json"
5+
"github.com/imroc/req/v3"
6+
log "github.com/sirupsen/logrus"
7+
"strconv"
8+
"time"
9+
)
10+
11+
func InIt(mode int, timeout int, proxy string, repeat int) (client *req.Client) {
12+
log.Info("init httpclient")
13+
client = req.NewClient()
14+
client.SetLogger(log.StandardLogger())
15+
if mode != 0 {
16+
client.DevMode()
17+
}
18+
// 设置超时时间
19+
client.SetTimeout(time.Duration(timeout) * time.Second)
20+
client.SetCommonRetryCount(repeat)
21+
// 设置代理
22+
f := IsProxyUrl(proxy)
23+
if f {
24+
proxy = GetProxyUrl(proxy)
25+
client.SetProxyURL(proxy)
26+
} else {
27+
log.Error("proxy: " + proxy + " is not a valid url")
28+
return nil
29+
}
30+
return client
31+
}
32+
33+
func Send(hashmap map[string]string) (resp *req.Response) {
34+
method := hashmap["method"]
35+
url := hashmap["url"]
36+
proxy := hashmap["proxy"]
37+
repeat, _ := strconv.Atoi(hashmap["repeat"])
38+
timeout, _ := strconv.Atoi(hashmap["timeout"])
39+
mode, _ := strconv.Atoi(hashmap["mode"])
40+
header := hashmap["header"]
41+
body := hashmap["body"]
42+
// string to map
43+
var tempmap map[string]string
44+
err := json.Unmarshal([]byte(header), &tempmap)
45+
if err != nil {
46+
log.Error("header: " + header + " is not a valid json")
47+
return nil
48+
}
49+
50+
client := InIt(mode, timeout, proxy, repeat).EnableDumpAll()
51+
52+
req := client.R()
53+
reqs := SetRequest(req, tempmap, body)
54+
resp, err = reqs.Send(method, url)
55+
if err != nil {
56+
log.Error("send request error: " + err.Error())
57+
return nil
58+
}
59+
60+
return resp
61+
}

cmd/commons/utils/proxy.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package utils
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"net/url"
6+
"strings"
7+
)
8+
9+
func IsProxyUrl(proxy string) bool {
10+
11+
if strings.Contains(proxy, ":") {
12+
return true
13+
}
14+
return false
15+
16+
}
17+
18+
func GetProxyUrl(proxy string) (proxys string) {
19+
20+
url, err := url.Parse(proxy)
21+
if err != nil {
22+
log.Errorf(err.Error())
23+
return
24+
} else {
25+
proxys = url.Scheme + "://" + url.Host
26+
}
27+
return proxys
28+
29+
}

0 commit comments

Comments
 (0)