From b94a4c313718e5ef4c6613d3a94f854b17648167 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Tue, 6 Dec 2022 21:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=A3=85rulebase=20=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- internal/option.go | 27 ++++++++++++++++++++++++--- internal/pool.go | 2 ++ internal/runner.go | 3 +++ pkg/config.go | 2 ++ 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index d8f4bc9..e8795d8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/chainreactors/ipcs v0.0.13 github.com/chainreactors/logs v0.6.2 github.com/chainreactors/parsers v0.2.7 - github.com/chainreactors/words v0.2.1 + github.com/chainreactors/words v0.3.0 ) require ( diff --git a/go.sum b/go.sum index 685843c..3de06ef 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ github.com/chainreactors/logs v0.6.2/go.mod h1:Y0EtAnoF0kiASIJUnXN0pcOt420iRpHOA github.com/chainreactors/parsers v0.2.6/go.mod h1:Z9weht+lnFCk7UcwqFu6lXpS7u5vttiy0AJYOAyCCLA= github.com/chainreactors/parsers v0.2.7 h1:3iEuluL7gSDrElZWyf1KEiTgddgcoZC0IaIHb9KA3pk= github.com/chainreactors/parsers v0.2.7/go.mod h1:Z9weht+lnFCk7UcwqFu6lXpS7u5vttiy0AJYOAyCCLA= -github.com/chainreactors/words v0.2.1 h1:yQvNnLF3VM2QBo611FhXUEr5i+O4cWY3jUvhDfAknIA= -github.com/chainreactors/words v0.2.1/go.mod h1:jRcFgafTKqdkd1+StzPCTJG1ESrZHluXEO2eERdHBMQ= +github.com/chainreactors/words v0.3.0 h1:6wC6lARE2MuD0UihW4RTV76cbiAoGVJM3k+HZg+R+hc= +github.com/chainreactors/words v0.3.0/go.mod h1:jRcFgafTKqdkd1+StzPCTJG1ESrZHluXEO2eERdHBMQ= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/internal/option.go b/internal/option.go index d930b68..2527b0f 100644 --- a/internal/option.go +++ b/internal/option.go @@ -1,6 +1,7 @@ package internal import ( + "bytes" "fmt" "github.com/antonmedv/expr" "github.com/chainreactors/files" @@ -8,6 +9,7 @@ import ( "github.com/chainreactors/logs" "github.com/chainreactors/spray/pkg" "github.com/chainreactors/words/mask" + "github.com/chainreactors/words/rule" "github.com/gosuri/uiprogress" "io/ioutil" "os" @@ -25,13 +27,14 @@ type Option struct { } type InputOptions struct { - ResumeFrom string `short:"r" long:"resume-from"` + ResumeFrom string `long:"resume-from"` URL string `short:"u" long:"url" description:"String, input baseurl (separated by commas), e.g.: http://google.com, http://baidu.com"` URLFile string `short:"l" long:"list" description:"File, input filename"` Offset int `long:"offset" description:"Int, wordlist offset"` Limit int `long:"limit" description:"Int, wordlist limit, start with offset. e.g.: --offset 1000 --limit 100"` Dictionaries []string `short:"d" long:"dict" description:"Files, dict files, e.g.: -d 1.txt -d 2.txt"` Word string `short:"w" long:"word" description:"String, word generate dsl, e.g.: -w test{?ld#4}"` + Rules []string `short:"r" long:"rules" description:"Files, rule files, e.g.: -r rule1.txt -r rule2.txt"` Extensions string `short:"e" long:"extension" description:"String, add extensions (separated by commas), e.g.: -e jsp,jspx"` ExcludeExtensions string `long:"exclude-extension" description:"String, exclude extensions (separated by commas), e.g.: --exclude-extension jsp,jspx"` RemoveExtensions string `long:"remove-extension" description:"String, remove extensions (separated by commas), e.g.: --remove-extension jsp,jspx"` @@ -129,7 +132,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) { if opt.Quiet { logs.Log.Quiet = true } - if opt.Quiet || opt.NoBar { + if !(opt.Quiet || opt.NoBar) { r.Progress.Start() logs.Log.Writer = r.Progress.Bypass() } @@ -225,7 +228,25 @@ func (opt *Option) PrepareRunner() (*Runner, error) { Offset: opt.Offset, } - r.Total = len(r.Wordlist) + if opt.Rules != nil { + var rules bytes.Buffer + for _, rule := range opt.Rules { + content, err := ioutil.ReadFile(rule) + if err != nil { + return nil, err + } + rules.Write(content) + rules.WriteString("\n") + } + r.Rules = rule.Compile(rules.String()) + } + + if len(r.Rules) > 0 { + r.Total = len(r.Wordlist) * len(r.Rules) + } else { + r.Total = len(r.Wordlist) + } + if opt.Limit != 0 { if total := r.Offset + opt.Limit; total < r.Total { r.Total = total diff --git a/internal/pool.go b/internal/pool.go index 909f3d9..0c96856 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -42,6 +42,8 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { failedCount: 1, } + pool.worder.Rules = pool.Rules + pool.worder.RunWithRules() switch config.Mod { case pkg.PathSpray: pool.genReq = func(s string) (*ihttp.Request, error) { diff --git a/internal/runner.go b/internal/runner.go index 5588171..7644930 100644 --- a/internal/runner.go +++ b/internal/runner.go @@ -8,6 +8,7 @@ import ( "github.com/chainreactors/logs" "github.com/chainreactors/spray/pkg" "github.com/chainreactors/spray/pkg/ihttp" + "github.com/chainreactors/words/rule" "github.com/gosuri/uiprogress" "github.com/panjf2000/ants/v2" "net/http" @@ -31,6 +32,7 @@ type Runner struct { Tasks []*Task URLList []string Wordlist []string + Rules []rule.Expression Headers http.Header Fns []func(string) string FilterExpr *vm.Program @@ -65,6 +67,7 @@ func (r *Runner) PrepareConfig() *pkg.Config { Headers: r.Headers, Mod: pkg.ModMap[r.Mod], Fns: r.Fns, + Rules: r.Rules, OutputCh: r.OutputCh, FuzzyCh: r.FuzzyCh, CheckPeriod: r.CheckPeriod, diff --git a/pkg/config.go b/pkg/config.go index d3c7aeb..030fe2e 100644 --- a/pkg/config.go +++ b/pkg/config.go @@ -2,6 +2,7 @@ package pkg import ( "github.com/antonmedv/expr/vm" + "github.com/chainreactors/words/rule" "net/http" ) @@ -32,6 +33,7 @@ type Config struct { Headers http.Header ClientType int Fns []func(string) string + Rules []rule.Expression MatchExpr *vm.Program FilterExpr *vm.Program