mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
clean output code
enhance output format and color support jsonline output in stdout
This commit is contained in:
parent
237102124e
commit
eb328a4b52
2
go.mod
2
go.mod
@ -8,7 +8,7 @@ require (
|
|||||||
github.com/chainreactors/files v0.0.0-20231123083421-cea5b4ad18a8
|
github.com/chainreactors/files v0.0.0-20231123083421-cea5b4ad18a8
|
||||||
github.com/chainreactors/fingers v0.0.0-20240704063230-de8fec05ff8b
|
github.com/chainreactors/fingers v0.0.0-20240704063230-de8fec05ff8b
|
||||||
github.com/chainreactors/logs v0.0.0-20240207121836-c946f072f81f
|
github.com/chainreactors/logs v0.0.0-20240207121836-c946f072f81f
|
||||||
github.com/chainreactors/parsers v0.0.0-20240704062910-decf861def9e
|
github.com/chainreactors/parsers v0.0.0-20240704071623-9d0ee90230a6
|
||||||
github.com/chainreactors/utils v0.0.0-20240704062557-662d623b74f4
|
github.com/chainreactors/utils v0.0.0-20240704062557-662d623b74f4
|
||||||
github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508
|
github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508
|
||||||
github.com/expr-lang/expr v1.16.9
|
github.com/expr-lang/expr v1.16.9
|
||||||
|
4
go.sum
4
go.sum
@ -119,6 +119,10 @@ github.com/chainreactors/parsers v0.0.0-20240702104902-1ce563b7ef76 h1:i4sHuonM5
|
|||||||
github.com/chainreactors/parsers v0.0.0-20240702104902-1ce563b7ef76/go.mod h1:G/XLE5RAaUdqADkbhQ59mPrUAbsJLiQ2DN6CwtwNpBQ=
|
github.com/chainreactors/parsers v0.0.0-20240702104902-1ce563b7ef76/go.mod h1:G/XLE5RAaUdqADkbhQ59mPrUAbsJLiQ2DN6CwtwNpBQ=
|
||||||
github.com/chainreactors/parsers v0.0.0-20240704062910-decf861def9e h1:42ILX5kS76M1D9IQvXgfelpgUJDi/K+4/egE0tLzuSE=
|
github.com/chainreactors/parsers v0.0.0-20240704062910-decf861def9e h1:42ILX5kS76M1D9IQvXgfelpgUJDi/K+4/egE0tLzuSE=
|
||||||
github.com/chainreactors/parsers v0.0.0-20240704062910-decf861def9e/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA=
|
github.com/chainreactors/parsers v0.0.0-20240704062910-decf861def9e/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA=
|
||||||
|
github.com/chainreactors/parsers v0.0.0-20240704071443-8a8558f34cf9 h1:XxPUVhP29vnbLuhxFt8VT3eyBR8d/GfHR7YK44zyDVo=
|
||||||
|
github.com/chainreactors/parsers v0.0.0-20240704071443-8a8558f34cf9/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA=
|
||||||
|
github.com/chainreactors/parsers v0.0.0-20240704071623-9d0ee90230a6 h1:jUxPo0RJ/f+/4x3ydeXqCeMq5VbvYBjtmpBePWFfNc8=
|
||||||
|
github.com/chainreactors/parsers v0.0.0-20240704071623-9d0ee90230a6/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA=
|
||||||
github.com/chainreactors/utils v0.0.0-20240302165634-2b8494c9cfc3/go.mod h1:JA4eiQZm+7AsfjXBcIzIdVKBEhDCb16eNtWFCGTxlvs=
|
github.com/chainreactors/utils v0.0.0-20240302165634-2b8494c9cfc3/go.mod h1:JA4eiQZm+7AsfjXBcIzIdVKBEhDCb16eNtWFCGTxlvs=
|
||||||
github.com/chainreactors/utils v0.0.0-20240528085651-ba1b255482c1 h1:+awuysRKLmdLQbVK+HPSOGvO3dFGdNSbM2jyLh+VYOA=
|
github.com/chainreactors/utils v0.0.0-20240528085651-ba1b255482c1 h1:+awuysRKLmdLQbVK+HPSOGvO3dFGdNSbM2jyLh+VYOA=
|
||||||
github.com/chainreactors/utils v0.0.0-20240528085651-ba1b255482c1/go.mod h1:JA4eiQZm+7AsfjXBcIzIdVKBEhDCb16eNtWFCGTxlvs=
|
github.com/chainreactors/utils v0.0.0-20240528085651-ba1b255482c1/go.mod h1:JA4eiQZm+7AsfjXBcIzIdVKBEhDCb16eNtWFCGTxlvs=
|
||||||
|
@ -87,6 +87,7 @@ type OutputOptions struct {
|
|||||||
Dump bool `long:"dump" description:"Bool, dump all request" config:"dump"`
|
Dump bool `long:"dump" description:"Bool, dump all request" config:"dump"`
|
||||||
AutoFile bool `long:"auto-file" description:"Bool, auto generator output and fuzzy filename" config:"auto-file"`
|
AutoFile bool `long:"auto-file" description:"Bool, auto generator output and fuzzy filename" config:"auto-file"`
|
||||||
Format string `short:"F" long:"format" description:"String, output format, e.g.: --format 1.json" config:"format"`
|
Format string `short:"F" long:"format" description:"String, output format, e.g.: --format 1.json" config:"format"`
|
||||||
|
Json bool `short:"j" long:"json" description:"Bool, output json" config:"json"`
|
||||||
OutputProbe string `short:"o" long:"probe" description:"String, output format" config:"output_probe"`
|
OutputProbe string `short:"o" long:"probe" description:"String, output format" config:"output_probe"`
|
||||||
Quiet bool `short:"q" long:"quiet" description:"Bool, Quiet" config:"quiet"`
|
Quiet bool `short:"q" long:"quiet" description:"Bool, Quiet" config:"quiet"`
|
||||||
NoColor bool `long:"no-color" description:"Bool, no color" config:"no-color"`
|
NoColor bool `long:"no-color" description:"Bool, no color" config:"no-color"`
|
||||||
@ -158,36 +159,13 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r := &Runner{
|
r := &Runner{
|
||||||
Threads: opt.Threads,
|
Option: opt,
|
||||||
PoolSize: opt.PoolSize,
|
taskCh: make(chan *Task),
|
||||||
Mod: opt.Mod,
|
outputCh: make(chan *pkg.Baseline, 256),
|
||||||
Timeout: opt.Timeout,
|
outwg: &sync.WaitGroup{},
|
||||||
RateLimit: opt.RateLimit,
|
fuzzyCh: make(chan *pkg.Baseline, 256),
|
||||||
Deadline: opt.Deadline,
|
Headers: make(map[string]string),
|
||||||
Headers: make(map[string]string),
|
Total: opt.Limit,
|
||||||
Method: opt.Method,
|
|
||||||
Offset: opt.Offset,
|
|
||||||
Total: opt.Limit,
|
|
||||||
taskCh: make(chan *Task),
|
|
||||||
outputCh: make(chan *pkg.Baseline, 256),
|
|
||||||
outwg: &sync.WaitGroup{},
|
|
||||||
fuzzyCh: make(chan *pkg.Baseline, 256),
|
|
||||||
Fuzzy: opt.Fuzzy,
|
|
||||||
Force: opt.Force,
|
|
||||||
CheckOnly: opt.CheckOnly,
|
|
||||||
CheckPeriod: opt.CheckPeriod,
|
|
||||||
ErrPeriod: opt.ErrPeriod,
|
|
||||||
BreakThreshold: opt.BreakThreshold,
|
|
||||||
Crawl: opt.Crawl,
|
|
||||||
Scope: opt.Scope,
|
|
||||||
Finger: opt.Finger,
|
|
||||||
Bak: opt.Bak,
|
|
||||||
Common: opt.Common,
|
|
||||||
RetryCount: opt.RetryCount,
|
|
||||||
RandomUserAgent: opt.RandomUserAgent,
|
|
||||||
Random: opt.Random,
|
|
||||||
Index: opt.Index,
|
|
||||||
Proxy: opt.Proxy,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// log and bar
|
// log and bar
|
||||||
|
@ -28,86 +28,62 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
taskCh chan *Task
|
*Option
|
||||||
poolwg sync.WaitGroup
|
|
||||||
outwg *sync.WaitGroup
|
|
||||||
outputCh chan *pkg.Baseline
|
|
||||||
fuzzyCh chan *pkg.Baseline
|
|
||||||
bar *mpb.Bar
|
|
||||||
finished int
|
|
||||||
|
|
||||||
Tasks chan *Task
|
taskCh chan *Task
|
||||||
Count int // tasks total number
|
poolwg sync.WaitGroup
|
||||||
Wordlist []string
|
outwg *sync.WaitGroup
|
||||||
Rules *rule.Program
|
outputCh chan *pkg.Baseline
|
||||||
AppendRules *rule.Program
|
fuzzyCh chan *pkg.Baseline
|
||||||
AppendWords []string
|
bar *mpb.Bar
|
||||||
Headers map[string]string
|
finished int
|
||||||
Method string
|
Pools *ants.PoolWithFunc
|
||||||
Fns []func(string) []string
|
PoolName map[string]bool
|
||||||
FilterExpr *vm.Program
|
Tasks chan *Task
|
||||||
MatchExpr *vm.Program
|
Rules *rule.Program
|
||||||
RecursiveExpr *vm.Program
|
AppendRules *rule.Program
|
||||||
RecuDepth int
|
Headers map[string]string
|
||||||
Threads int
|
FilterExpr *vm.Program
|
||||||
PoolSize int
|
MatchExpr *vm.Program
|
||||||
ClientType int
|
RecursiveExpr *vm.Program
|
||||||
Pools *ants.PoolWithFunc
|
OutputFile *files.File
|
||||||
PoolName map[string]bool
|
FuzzyFile *files.File
|
||||||
Timeout int
|
DumpFile *files.File
|
||||||
Mod string
|
StatFile *files.File
|
||||||
Probes []string
|
Progress *mpb.Progress
|
||||||
Fuzzy bool
|
Fns []func(string) []string
|
||||||
OutputFile *files.File
|
Count int // tasks total number
|
||||||
FuzzyFile *files.File
|
Wordlist []string
|
||||||
DumpFile *files.File
|
AppendWords []string
|
||||||
StatFile *files.File
|
RecuDepth int
|
||||||
Progress *mpb.Progress
|
ClientType int
|
||||||
Offset int
|
Probes []string
|
||||||
Limit int
|
Total int // wordlist total number
|
||||||
RateLimit int
|
Color bool
|
||||||
Total int // wordlist total number
|
Jsonify bool
|
||||||
Deadline int
|
|
||||||
CheckPeriod int
|
|
||||||
ErrPeriod int
|
|
||||||
BreakThreshold int
|
|
||||||
Color bool
|
|
||||||
CheckOnly bool
|
|
||||||
Force bool
|
|
||||||
IgnoreWaf bool
|
|
||||||
Crawl bool
|
|
||||||
Scope []string
|
|
||||||
Finger bool
|
|
||||||
Bak bool
|
|
||||||
Common bool
|
|
||||||
RetryCount int
|
|
||||||
RandomUserAgent bool
|
|
||||||
Random string
|
|
||||||
Index string
|
|
||||||
Proxy string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) PrepareConfig() *pool.Config {
|
func (r *Runner) PrepareConfig() *pool.Config {
|
||||||
config := &pool.Config{
|
config := &pool.Config{
|
||||||
Thread: r.Threads,
|
Thread: r.Threads,
|
||||||
Timeout: r.Timeout,
|
Timeout: r.Timeout,
|
||||||
RateLimit: r.RateLimit,
|
RateLimit: r.RateLimit,
|
||||||
Headers: r.Headers,
|
Headers: r.Headers,
|
||||||
Method: r.Method,
|
Method: r.Method,
|
||||||
Mod: pool.ModMap[r.Mod],
|
Mod: pool.ModMap[r.Mod],
|
||||||
OutputCh: r.outputCh,
|
OutputCh: r.outputCh,
|
||||||
FuzzyCh: r.fuzzyCh,
|
FuzzyCh: r.fuzzyCh,
|
||||||
OutLocker: r.outwg,
|
OutLocker: r.outwg,
|
||||||
Fuzzy: r.Fuzzy,
|
Fuzzy: r.Fuzzy,
|
||||||
CheckPeriod: r.CheckPeriod,
|
CheckPeriod: r.CheckPeriod,
|
||||||
ErrPeriod: int32(r.ErrPeriod),
|
ErrPeriod: int32(r.ErrPeriod),
|
||||||
BreakThreshold: int32(r.BreakThreshold),
|
BreakThreshold: int32(r.BreakThreshold),
|
||||||
MatchExpr: r.MatchExpr,
|
MatchExpr: r.MatchExpr,
|
||||||
FilterExpr: r.FilterExpr,
|
FilterExpr: r.FilterExpr,
|
||||||
RecuExpr: r.RecursiveExpr,
|
RecuExpr: r.RecursiveExpr,
|
||||||
AppendRule: r.AppendRules,
|
AppendRule: r.AppendRules,
|
||||||
AppendWords: r.AppendWords,
|
AppendWords: r.AppendWords,
|
||||||
IgnoreWaf: r.IgnoreWaf,
|
//IgnoreWaf: r.IgnoreWaf,
|
||||||
Crawl: r.Crawl,
|
Crawl: r.Crawl,
|
||||||
Scope: r.Scope,
|
Scope: r.Scope,
|
||||||
Active: r.Finger,
|
Active: r.Finger,
|
||||||
@ -386,38 +362,55 @@ func (r *Runner) OutputHandler() {
|
|||||||
logs.Log.Debug(bl.String())
|
logs.Log.Debug(bl.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go func() {
|
|
||||||
var saveFunc func(*pkg.Baseline)
|
|
||||||
|
|
||||||
if r.OutputFile != nil {
|
var saveFunc func(string)
|
||||||
saveFunc = func(bl *pkg.Baseline) {
|
if r.OutputFile != nil {
|
||||||
r.OutputFile.SafeWrite(bl.Jsonify() + "\n")
|
saveFunc = func(line string) {
|
||||||
r.OutputFile.SafeSync()
|
r.OutputFile.SafeWrite(line + "\n")
|
||||||
|
r.OutputFile.SafeSync()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
saveFunc = func(line string) {
|
||||||
|
logs.Log.Console(line + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var fuzzySaveFunc func(string)
|
||||||
|
if r.FuzzyFile != nil {
|
||||||
|
fuzzySaveFunc = func(line string) {
|
||||||
|
r.FuzzyFile.SafeWrite(line + "\n")
|
||||||
|
r.FuzzyFile.SafeSync()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fuzzySaveFunc = func(line string) {
|
||||||
|
logs.Log.Console("[fuzzy] " + line + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputPrint := func(bl *pkg.Baseline) {
|
||||||
|
var outFunc func(string)
|
||||||
|
if bl.IsFuzzy {
|
||||||
|
outFunc = fuzzySaveFunc
|
||||||
|
} else {
|
||||||
|
outFunc = saveFunc
|
||||||
|
}
|
||||||
|
if r.Option.Json {
|
||||||
|
outFunc(bl.Jsonify())
|
||||||
|
} else if r.Color {
|
||||||
|
if len(r.Probes) > 0 {
|
||||||
|
outFunc(logs.GreenBold(bl.Format(r.Probes)))
|
||||||
|
} else {
|
||||||
|
outFunc(logs.GreenBold(bl.ColorString()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(r.Probes) > 0 {
|
if len(r.Probes) > 0 {
|
||||||
if r.Color {
|
outFunc(bl.Format(r.Probes))
|
||||||
saveFunc = func(bl *pkg.Baseline) {
|
|
||||||
logs.Log.Console(logs.GreenBold("[+] " + bl.Format(r.Probes) + "\n"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
saveFunc = func(bl *pkg.Baseline) {
|
|
||||||
logs.Log.Console("[+] " + bl.Format(r.Probes) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if r.Color {
|
outFunc(bl.String())
|
||||||
saveFunc = func(bl *pkg.Baseline) {
|
|
||||||
logs.Log.Console(logs.GreenBold("[+] " + bl.ColorString() + "\n"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
saveFunc = func(bl *pkg.Baseline) {
|
|
||||||
logs.Log.Console("[+] " + bl.String() + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case bl, ok := <-r.outputCh:
|
case bl, ok := <-r.outputCh:
|
||||||
@ -429,7 +422,7 @@ func (r *Runner) OutputHandler() {
|
|||||||
r.DumpFile.SafeSync()
|
r.DumpFile.SafeSync()
|
||||||
}
|
}
|
||||||
if bl.IsValid {
|
if bl.IsValid {
|
||||||
saveFunc(bl)
|
outputPrint(bl)
|
||||||
if bl.Recu {
|
if bl.Recu {
|
||||||
r.AddRecursive(bl)
|
r.AddRecursive(bl)
|
||||||
}
|
}
|
||||||
@ -442,23 +435,6 @@ func (r *Runner) OutputHandler() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var fuzzySaveFunc func(*pkg.Baseline)
|
|
||||||
if r.FuzzyFile != nil {
|
|
||||||
fuzzySaveFunc = func(bl *pkg.Baseline) {
|
|
||||||
r.FuzzyFile.SafeWrite(bl.Jsonify() + "\n")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if r.Color {
|
|
||||||
fuzzySaveFunc = func(bl *pkg.Baseline) {
|
|
||||||
logs.Log.Console(logs.GreenBold("[fuzzy] " + bl.ColorString() + "\n"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fuzzySaveFunc = func(bl *pkg.Baseline) {
|
|
||||||
logs.Log.Console("[fuzzy] " + bl.String() + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case bl, ok := <-r.fuzzyCh:
|
case bl, ok := <-r.fuzzyCh:
|
||||||
@ -466,7 +442,7 @@ func (r *Runner) OutputHandler() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Fuzzy {
|
if r.Fuzzy {
|
||||||
fuzzySaveFunc(bl)
|
outputPrint(bl)
|
||||||
}
|
}
|
||||||
r.outwg.Done()
|
r.outwg.Done()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user