mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
enhance cidr parse
This commit is contained in:
parent
3e419a52a5
commit
1c9898ebf5
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
||||
github.com/chainreactors/fingers v0.0.0-20240711193807-8c1518dc63fc
|
||||
github.com/chainreactors/logs v0.0.0-20240207121836-c946f072f81f
|
||||
github.com/chainreactors/parsers v0.0.0-20240708072709-07deeece7ce2
|
||||
github.com/chainreactors/utils v0.0.0-20240711195624-66696b0879b2
|
||||
github.com/chainreactors/utils v0.0.0-20240715080349-d2d0484c95ed
|
||||
github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508
|
||||
github.com/expr-lang/expr v1.16.9
|
||||
github.com/gookit/config/v2 v2.2.5
|
||||
|
2
go.sum
2
go.sum
@ -136,6 +136,8 @@ github.com/chainreactors/utils v0.0.0-20240711193713-3f498c03d1b6 h1:U+gTyfd7rEv
|
||||
github.com/chainreactors/utils v0.0.0-20240711193713-3f498c03d1b6/go.mod h1:LajXuvESQwP+qCMAvlcoSXppQCjuLlBrnQpu9XQ1HtU=
|
||||
github.com/chainreactors/utils v0.0.0-20240711195624-66696b0879b2 h1:0Bwlb6eDCcR6hwXPOBdOooRt1wVklstwVZ47miJV0ZY=
|
||||
github.com/chainreactors/utils v0.0.0-20240711195624-66696b0879b2/go.mod h1:LajXuvESQwP+qCMAvlcoSXppQCjuLlBrnQpu9XQ1HtU=
|
||||
github.com/chainreactors/utils v0.0.0-20240715080349-d2d0484c95ed h1:5zxxMweHgo2e7r4ic7LHGibGBnOiVmCqbzbcbgoPn7U=
|
||||
github.com/chainreactors/utils v0.0.0-20240715080349-d2d0484c95ed/go.mod h1:LajXuvESQwP+qCMAvlcoSXppQCjuLlBrnQpu9XQ1HtU=
|
||||
github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508 h1:iT4HWkoZzUAfQYcQMRH8XyrMau9tCVE0zSuFQnkhrqw=
|
||||
github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508/go.mod h1:DUDx7PdsMEm5PvVhzkFyppzpiUhQb8dOJaWjVc1SMVk=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
|
@ -50,7 +50,7 @@ type InputOptions struct {
|
||||
URL []string `short:"u" long:"url" description:"Strings, input baseurl, e.g.: http://google.com"`
|
||||
URLFile string `short:"l" long:"list" description:"File, input filename"`
|
||||
PortRange string `short:"p" long:"port" description:"String, input port range, e.g.: 80,8080-8090,db"`
|
||||
CIDRs string `short:"i" long:"cidr" description:"String, input cidr, e.g.: 1.1.1.1/24 "`
|
||||
CIDRs []string `short:"i" long:"cidr" description:"String, input cidr, e.g.: 1.1.1.1/24 "`
|
||||
RawFile string `long:"raw" description:"File, input raw request filename"`
|
||||
Dictionaries []string `short:"d" long:"dict" description:"Files, Multi,dict files, e.g.: -d 1.txt -d 2.txt" config:"dictionaries"`
|
||||
//NoDict bool `long:"no-dict" description:"Bool, no dictionary" config:"no-dict"`
|
||||
@ -464,24 +464,19 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
|
||||
for k, _ := range req.Header {
|
||||
r.Headers[k] = req.Header.Get(k)
|
||||
}
|
||||
} else if opt.CIDRs != "" {
|
||||
} else if len(opt.CIDRs) != 0 {
|
||||
cidrs := utils.ParseCIDRs(opt.CIDRs)
|
||||
if len(ports) == 0 {
|
||||
ports = []string{"80", "443"}
|
||||
}
|
||||
|
||||
for _, cidr := range strings.Split(opt.CIDRs, ",") {
|
||||
ips := utils.ParseCIDR(cidr)
|
||||
if ips != nil {
|
||||
r.Count += ips.Count()
|
||||
}
|
||||
}
|
||||
r.Count = cidrs.Count()
|
||||
go func() {
|
||||
for _, cidr := range strings.Split(opt.CIDRs, ",") {
|
||||
ips := utils.ParseCIDR(cidr)
|
||||
if ips == nil {
|
||||
logs.Log.Error("cidr format error: " + cidr)
|
||||
for _, cidr := range cidrs {
|
||||
if cidr == nil {
|
||||
logs.Log.Error("cidr format error: " + cidr.String())
|
||||
}
|
||||
for ip := range ips.Range() {
|
||||
for ip := range cidr.Range() {
|
||||
opt.GenerateTasks(tasks, ip.String(), ports)
|
||||
}
|
||||
}
|
||||
@ -747,7 +742,7 @@ func (opt *Option) Validate() error {
|
||||
return errors.New("--resume and --depth cannot be used at the same time")
|
||||
}
|
||||
|
||||
if opt.ResumeFrom == "" && opt.URL == nil && opt.URLFile == "" && opt.CIDRs == "" && opt.RawFile == "" {
|
||||
if opt.ResumeFrom == "" && len(opt.URL) == 0 && opt.URLFile == "" && len(opt.CIDRs) == 0 && opt.RawFile == "" {
|
||||
return fmt.Errorf("without any target, please use -u/-l/-c/--resume to set targets")
|
||||
}
|
||||
return nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user