mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
关闭check-only的kepp-alive.
新增checkonly的--match指定过滤器
This commit is contained in:
parent
8ec00abe10
commit
77b92b44ea
@ -30,7 +30,7 @@ func NewCheckPool(ctx context.Context, config *pkg.Config) (*CheckPool, error) {
|
||||
reqCount: 1,
|
||||
failedCount: 1,
|
||||
}
|
||||
|
||||
pool.Headers = map[string]string{"Connection": "close"}
|
||||
p, _ := ants.NewPoolWithFunc(config.Thread, pool.Invoke)
|
||||
|
||||
pool.pool = p
|
||||
@ -124,7 +124,7 @@ func (pool *CheckPool) Invoke(v interface{}) {
|
||||
if err != nil {
|
||||
logs.Log.Error(err.Error())
|
||||
}
|
||||
|
||||
req.SetHeaders(pool.Headers)
|
||||
start := time.Now()
|
||||
var bl *pkg.Baseline
|
||||
resp, reqerr := pool.client.Do(pool.ctx, req)
|
||||
@ -144,7 +144,13 @@ func (pool *CheckPool) Invoke(v interface{}) {
|
||||
ReqDepth: unit.depth,
|
||||
},
|
||||
}
|
||||
|
||||
if strings.Contains(reqerr.Error(), "timed out") || strings.Contains(reqerr.Error(), "actively refused") {
|
||||
|
||||
} else {
|
||||
pool.doUpgrade(bl)
|
||||
}
|
||||
|
||||
} else {
|
||||
bl = pkg.NewBaseline(req.URI(), req.Host(), resp)
|
||||
bl.Collect()
|
||||
@ -162,9 +168,14 @@ func (pool *CheckPool) Invoke(v interface{}) {
|
||||
pool.doUpgrade(bl)
|
||||
pool.FuzzyCh <- bl
|
||||
} else {
|
||||
params := map[string]interface{}{
|
||||
"current": bl,
|
||||
}
|
||||
if pool.MatchExpr == nil || CompareWithExpr(pool.MatchExpr, params) {
|
||||
pool.OutputCh <- bl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pool.reqCount++
|
||||
pool.wg.Done()
|
||||
|
@ -3,8 +3,6 @@ package internal
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/antonmedv/expr"
|
||||
"github.com/antonmedv/expr/vm"
|
||||
"github.com/chainreactors/logs"
|
||||
"github.com/chainreactors/parsers"
|
||||
"github.com/chainreactors/parsers/iutils"
|
||||
@ -561,19 +559,6 @@ func (pool *Pool) BaseCompare(bl *pkg.Baseline) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func CompareWithExpr(exp *vm.Program, params map[string]interface{}) bool {
|
||||
res, err := expr.Run(exp, params)
|
||||
if err != nil {
|
||||
logs.Log.Warn(err.Error())
|
||||
}
|
||||
|
||||
if res == true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (pool *Pool) Upgrade(bl *pkg.Baseline) error {
|
||||
rurl, err := url.Parse(bl.RedirectURL)
|
||||
if err == nil && rurl.Hostname() == bl.Url.Hostname() && bl.Url.Scheme == "http" && rurl.Scheme == "https" {
|
||||
|
@ -2,6 +2,9 @@ package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/antonmedv/expr"
|
||||
"github.com/antonmedv/expr/vm"
|
||||
"github.com/chainreactors/logs"
|
||||
"github.com/chainreactors/spray/pkg"
|
||||
"github.com/chainreactors/words/mask"
|
||||
"github.com/chainreactors/words/rule"
|
||||
@ -249,3 +252,16 @@ func FormatURL(base, u string) string {
|
||||
func RandomUA() string {
|
||||
return randomUserAgent[rand.Intn(uacount)]
|
||||
}
|
||||
|
||||
func CompareWithExpr(exp *vm.Program, params map[string]interface{}) bool {
|
||||
res, err := expr.Run(exp, params)
|
||||
if err != nil {
|
||||
logs.Log.Warn(err.Error())
|
||||
}
|
||||
|
||||
if res == true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -75,9 +75,9 @@ type Client struct {
|
||||
|
||||
func (c *Client) TransToCheck() {
|
||||
if c.fastClient != nil {
|
||||
c.fastClient.MaxConnsPerHost = 1
|
||||
c.fastClient.MaxConnsPerHost = -1 // disable keepalive
|
||||
} else if c.standardClient != nil {
|
||||
|
||||
c.standardClient.Transport.(*http.Transport).DisableKeepAlives = true // disable keepalive
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user