新增--common, 探测web常见的通用文件.

优化--bak, bak现在还会带上常见的备份文件名了
This commit is contained in:
M09Ic 2023-01-06 13:07:59 +08:00
parent 6c2f5919d2
commit 4a1cb28bdd
6 changed files with 48 additions and 7 deletions

View File

@ -77,14 +77,15 @@ type RequestOptions struct {
type ModeOptions struct { type ModeOptions struct {
Advance bool `short:"a" long:"advance" description:"Bool, enable crawl and active"` Advance bool `short:"a" long:"advance" description:"Bool, enable crawl and active"`
Force bool `long:"force" description:"Bool, skip error break"`
CheckOnly bool `long:"check-only" description:"Bool, check only"`
Recursive string `long:"recursive" default:"current.IsDir()" description:"String,custom recursive rule, e.g.: --recursive current.IsDir()"`
Depth int `long:"depth" default:"0" description:"Int, recursive depth"`
Active bool `long:"active" description:"Bool, enable active finger detect"` Active bool `long:"active" description:"Bool, enable active finger detect"`
Crawl bool `long:"crawl" description:"Bool, enable crawl"` Crawl bool `long:"crawl" description:"Bool, enable crawl"`
Bak bool `long:"bak" description:"Bool, enable bak found"` Bak bool `long:"bak" description:"Bool, enable bak found"`
FileBak bool `long:"file-bak" description:"Bool, enable valid result bak found, equal --append-rule rule/filebak.txt"` FileBak bool `long:"file-bak" description:"Bool, enable valid result bak found, equal --append-rule rule/filebak.txt"`
Common bool `long:"common" description:"Bool, enable common file found"`
Force bool `long:"force" description:"Bool, skip error break"`
CheckOnly bool `long:"check-only" description:"Bool, check only"`
Recursive string `long:"recursive" default:"current.IsDir()" description:"String,custom recursive rule, e.g.: --recursive current.IsDir()"`
Depth int `long:"depth" default:"0" description:"Int, recursive depth"`
CrawlDepth int `long:"crawl-depth" default:"3" description:"Int, crawl depth"` CrawlDepth int `long:"crawl-depth" default:"3" description:"Int, crawl depth"`
CheckPeriod int `long:"check-period" default:"200" description:"Int, check period when request"` CheckPeriod int `long:"check-period" default:"200" description:"Int, check period when request"`
ErrPeriod int `long:"error-period" default:"10" description:"Int, check period when error"` ErrPeriod int `long:"error-period" default:"10" description:"Int, check period when error"`
@ -136,6 +137,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
Crawl: opt.Crawl, Crawl: opt.Crawl,
Active: opt.Active, Active: opt.Active,
Bak: opt.Bak, Bak: opt.Bak,
Common: opt.Common,
} }
if opt.Extracts != nil { if opt.Extracts != nil {
@ -181,6 +183,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
r.Crawl = true r.Crawl = true
r.Active = true r.Active = true
r.Bak = true r.Bak = true
r.Common = true
opt.AppendRule = append(opt.AppendRule, "filebak") opt.AppendRule = append(opt.AppendRule, "filebak")
} else if opt.FileBak { } else if opt.FileBak {
opt.AppendRule = append(opt.AppendRule, "filebak") opt.AppendRule = append(opt.AppendRule, "filebak")

View File

@ -9,6 +9,7 @@ import (
"github.com/chainreactors/spray/pkg" "github.com/chainreactors/spray/pkg"
"github.com/chainreactors/spray/pkg/ihttp" "github.com/chainreactors/spray/pkg/ihttp"
"github.com/chainreactors/words" "github.com/chainreactors/words"
"github.com/chainreactors/words/mask"
"github.com/chainreactors/words/rule" "github.com/chainreactors/words/rule"
"github.com/panjf2000/ants/v2" "github.com/panjf2000/ants/v2"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
@ -203,12 +204,19 @@ func (pool *Pool) Run(ctx context.Context, offset, limit int) {
pool.wg.Add(1) pool.wg.Add(1)
go pool.doBak() go pool.doBak()
} }
if pool.Common {
pool.wg.Add(1)
go pool.doCommonFile()
}
go func() { go func() {
for { for {
pool.wg.Wait() pool.wg.Wait()
pool.closeCh <- struct{}{} pool.closeCh <- struct{}{}
} }
}() }()
Loop: Loop:
for { for {
select { select {
@ -284,7 +292,7 @@ func (pool *Pool) Invoke(v interface{}) {
bl = &pkg.Baseline{UrlString: pool.BaseURL + unit.path, IsValid: false, ErrString: reqerr.Error(), Reason: ErrRequestFailed.Error()} bl = &pkg.Baseline{UrlString: pool.BaseURL + unit.path, IsValid: false, ErrString: reqerr.Error(), Reason: ErrRequestFailed.Error()}
pool.failedBaselines = append(pool.failedBaselines, bl) pool.failedBaselines = append(pool.failedBaselines, bl)
} else { } else {
if unit.source <= 3 || unit.source == CrawlSource { if unit.source <= 3 || unit.source == CrawlSource || unit.source == CommonFileSource {
bl = pkg.NewBaseline(req.URI(), req.Host(), resp) bl = pkg.NewBaseline(req.URI(), req.Host(), resp)
} else { } else {
if pool.MatchExpr != nil { if pool.MatchExpr != nil {
@ -366,7 +374,7 @@ func (pool *Pool) Invoke(v interface{}) {
case RedirectSource: case RedirectSource:
bl.FrontURL = unit.frontUrl bl.FrontURL = unit.frontUrl
pool.tempCh <- bl pool.tempCh <- bl
case CrawlSource, ActiveSource, RuleSource, BakSource: default:
pool.tempCh <- bl pool.tempCh <- bl
} }
} }
@ -572,6 +580,30 @@ func (pool *Pool) doBak() {
source: BakSource, source: BakSource,
}) })
} }
worder, err = words.NewWorderWithDsl("{@bak_name}.{@bak_ext}", nil, nil)
if err != nil {
return
}
worder.Run()
for w := range worder.C {
pool.wg.Add(1)
pool.addAddition(&Unit{
path: safePath(pool.BaseURL, w),
source: BakSource,
})
}
}
func (pool *Pool) doCommonFile() {
defer pool.wg.Done()
for _, u := range mask.SpecialWords["common_file"] {
pool.wg.Add(1)
pool.addAddition(&Unit{
path: safePath(pool.BaseURL, u),
source: CommonFileSource,
})
}
} }
func (pool *Pool) doCheck() { func (pool *Pool) doCheck() {

View File

@ -75,6 +75,7 @@ type Runner struct {
Crawl bool Crawl bool
Active bool Active bool
Bak bool Bak bool
Common bool
} }
func (r *Runner) PrepareConfig() *pkg.Config { func (r *Runner) PrepareConfig() *pkg.Config {
@ -97,6 +98,7 @@ func (r *Runner) PrepareConfig() *pkg.Config {
Crawl: r.Crawl, Crawl: r.Crawl,
Active: r.Active, Active: r.Active,
Bak: r.Bak, Bak: r.Bak,
Common: r.Common,
} }
if config.Mod == pkg.PathSpray { if config.Mod == pkg.PathSpray {
config.ClientType = ihttp.FAST config.ClientType = ihttp.FAST

View File

@ -55,6 +55,7 @@ const (
WafSource WafSource
RuleSource RuleSource
BakSource BakSource
CommonFileSource
) )
func newUnit(path string, source int) *Unit { func newUnit(path string, source int) *Unit {

View File

@ -85,7 +85,9 @@ func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Ba
bl.Host = host bl.Host = host
} }
bl.Body = resp.Body() body := resp.Body()
bl.Body = make([]byte, len(body))
copy(bl.Body, body)
bl.BodyLength = resp.ContentLength() bl.BodyLength = resp.ContentLength()
bl.Header = resp.Header() bl.Header = resp.Header()
bl.HeaderLength = len(bl.Header) bl.HeaderLength = len(bl.Header)

View File

@ -42,4 +42,5 @@ type Config struct {
Crawl bool Crawl bool
Active bool Active bool
Bak bool Bak bool
Common bool
} }