Skip to content

Commit c135293

Browse files
committed
ip and url parse
1 parent c538c6b commit c135293

File tree

7 files changed

+53
-14
lines changed

7 files changed

+53
-14
lines changed

cmd/commons/attack/attack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func init() {
2727
func addPoc(pocs map[string]interface{}) map[string]interface{} {
2828
log.Debugln("github.com/SummerSec/SpringExploit/cmd/commons/attack/attack.go:25")
2929
log.Debug("[*] Add PoC")
30-
//pocs["demo"] = &poc.Demo{}
31-
pocs["CVE202222947"] = &poc.CVE202222947{}
30+
pocs["demo"] = &poc.Demo{}
31+
//pocs["CVE202222947"] = &poc.CVE202222947{}
3232
return pocs
3333

3434
}

cmd/commons/core/options.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Options struct {
3030
// 重复请求次数
3131
Retry int
3232
// ip 段
33-
IP string
33+
//IP string
3434

3535
// 保存结果
3636
Out string
@@ -43,16 +43,16 @@ func (o Options) toString() interface{} {
4343

4444
func ParseOptions() *Options {
4545
options := &Options{}
46-
flag.IntVar(&options.Mode, "m", 6, "debug mode off ( Infolevel = 0 PanicLevel = 1 FatalLevel = 2 \n"+"\t ErrorLevel = 3 WarnLevel = 4 InfoLevel = 5 DebugLevel = 6 TraceLevel = 7)")
46+
flag.IntVar(&options.Mode, "m", 6, "debug mode off (debug mode = 6)")
4747
flag.IntVar(&options.Thread, "t", 1, "threads number ")
48-
flag.StringVar(&options.File, "f", "", "file to read example: -file=test.txt")
49-
flag.StringVar(&options.Url, "u", "", "url to read example: -url=http://www.baidu.com")
48+
flag.StringVar(&options.File, "f", "", "file to read example: -file=test.txt http(s)://host:port/")
49+
flag.StringVar(&options.Url, "u", "", "url to read example: -url=http://www.baidu.com:80")
5050
flag.StringVar(&options.Proxy, "proxy", "", "proxy example: -proxy=http://127.0.0.1:8080 or -proxy=socks5://127.0.0.1:1080")
5151
flag.BoolVar(&options.Version, "version", false, "show version")
5252
flag.BoolVar(&options.Verbose, "verbose", false, "show verbose")
5353
flag.StringVar(&options.LogFile, "log", "logs.txt", "log file example: -log=/logs/logs.txt")
5454
flag.IntVar(&options.Retry, "retry", 3, "repeat request times")
55-
flag.StringVar(&options.IP, "i", "", "ip segment example: -ip=192.168.0.1/24 ")
55+
//flag.StringVar(&options.IP, "i", "", "ip segment example: -ip=192.168.0.1/24 ")
5656
flag.IntVar(&options.Timeout, "timeout", 10, "timeout")
5757
flag.StringVar(&options.Out, "o", "result.txt", "out file example: -o=result.txt default result.txt")
5858
flag.Parse()
@@ -64,10 +64,10 @@ func ParseOptions() *Options {
6464
} else if url := options.Url; url != "" {
6565
options.Thread = 1
6666
options.File = ""
67-
67+
ShowBanner(v)
6868
} else if options.File != "" {
6969
options.Url = ""
70-
70+
ShowBanner(v)
7171
} else {
7272
ShowBanner(v)
7373
flag.PrintDefaults()

cmd/commons/core/runner.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/SummerSec/SpringExploit/cmd/commons/utils"
77
"github.com/fatih/structs"
88
log "github.com/sirupsen/logrus"
9+
"net/url"
910
)
1011

1112
type Runner struct {
@@ -28,6 +29,7 @@ func (r *Runner) Run() {
2829
log.Debugln("github.com/SummerSec/SpringExploit/cmd/commons/core/runner.go: Run()")
2930
log.Info("Runner Running")
3031
f := r.options.File
32+
//ip := r.options.IP
3133
var urls []string
3234
// TODO: check if options are valid
3335
//r.options.Url = "http://127.0.0.1:8090/"
@@ -60,15 +62,23 @@ func (r *Runner) Run() {
6062

6163
}
6264

63-
func Start(url string, hashmap map[string]interface{}, i int, c chan int) {
65+
func Start(u string, hashmap map[string]interface{}, i int, c chan int) {
6466
log.Debugln("github/SummerSec/SpringExploit/cmd/commons/core/runner.go: Start")
6567

6668
log.Info("Runner started")
67-
log.Infoln("testing URL: ", url)
69+
log.Infoln("testing URL: ", u)
6870
//for k, v := range hashmap {
6971
// log.Debugln("key: ", k, " value: ", v)
7072
//}
71-
attack.Sevice(url, hashmap)
73+
r, err := url.Parse(u)
74+
if err != nil {
75+
log.Info("URL parse error")
76+
log.Errorln(err)
77+
return
78+
}
79+
target := r.Scheme + "://" + r.Host + r.Port() + r.Path
80+
81+
attack.Sevice(target, hashmap)
7282

7383
// 放到最后,不然无法生效
7484
c <- i + 1

cmd/commons/poc/demo.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ import (
88

99
type Demo struct{}
1010

11-
func (d Demo) SendPoc(url string, hashmap map[string]interface{}) {
11+
func (d Demo) SendPoc(target string, hashmap map[string]interface{}) {
1212

1313
log.Debugf("[+] Running default poc")
1414
reqinfo := NewReqInfo()
1515
reqmap := structs.Map(reqinfo)
16-
reqmap["url"] = url
16+
// TODO 每次传入的url 都是标准的 http(s)://host:port/path
17+
// 可以使用 url.Parse 来解析获取 host 和 port
18+
// for example:
19+
//result, err := url.Parse(target)
20+
//if err != nil {
21+
// log.Debugln("[-] url parse error")
22+
// log.Errorf("[-] url parse error: %s", err)
23+
// return
24+
//}
25+
//target = result.Scheme + "://" + result.Host + result.Port() + "/" + result.Path
26+
27+
reqmap["url"] = target
1728
//for k, v := range hashmap {
1829
// log.Debugln("key: ", k, " value: ", v)
1930
//}

cmd/commons/utils/readfile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"bufio"
55
log "github.com/sirupsen/logrus"
6+
"net/url"
67
"os"
78
)
89

@@ -22,6 +23,8 @@ func ReadFile(path string) (urls []string, err error) {
2223
if err != nil {
2324
return lins, err // error or EOF
2425
}
26+
url.Parse(str)
27+
2528
log.Infoln("The url is : %s", str)
2629
lins = append(lins, str)
2730
}

cmd/test/ip.go

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

cmd/test/url.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
)
7+
8+
func main() {
9+
u := "https://www.google.com:6066/search?q=go+language"
10+
r, _ := url.Parse(u)
11+
fmt.Println(r.Host)
12+
fmt.Println(r.Scheme + "://" + r.Host + r.Path)
13+
14+
}

0 commit comments

Comments
 (0)