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,
|
reqCount: 1,
|
||||||
failedCount: 1,
|
failedCount: 1,
|
||||||
}
|
}
|
||||||
|
pool.Headers = map[string]string{"Connection": "close"}
|
||||||
p, _ := ants.NewPoolWithFunc(config.Thread, pool.Invoke)
|
p, _ := ants.NewPoolWithFunc(config.Thread, pool.Invoke)
|
||||||
|
|
||||||
pool.pool = p
|
pool.pool = p
|
||||||
@ -124,7 +124,7 @@ func (pool *CheckPool) Invoke(v interface{}) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Log.Error(err.Error())
|
logs.Log.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
req.SetHeaders(pool.Headers)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
var bl *pkg.Baseline
|
var bl *pkg.Baseline
|
||||||
resp, reqerr := pool.client.Do(pool.ctx, req)
|
resp, reqerr := pool.client.Do(pool.ctx, req)
|
||||||
@ -144,7 +144,13 @@ func (pool *CheckPool) Invoke(v interface{}) {
|
|||||||
ReqDepth: unit.depth,
|
ReqDepth: unit.depth,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pool.doUpgrade(bl)
|
|
||||||
|
if strings.Contains(reqerr.Error(), "timed out") || strings.Contains(reqerr.Error(), "actively refused") {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pool.doUpgrade(bl)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bl = pkg.NewBaseline(req.URI(), req.Host(), resp)
|
bl = pkg.NewBaseline(req.URI(), req.Host(), resp)
|
||||||
bl.Collect()
|
bl.Collect()
|
||||||
@ -162,7 +168,12 @@ func (pool *CheckPool) Invoke(v interface{}) {
|
|||||||
pool.doUpgrade(bl)
|
pool.doUpgrade(bl)
|
||||||
pool.FuzzyCh <- bl
|
pool.FuzzyCh <- bl
|
||||||
} else {
|
} else {
|
||||||
pool.OutputCh <- bl
|
params := map[string]interface{}{
|
||||||
|
"current": bl,
|
||||||
|
}
|
||||||
|
if pool.MatchExpr == nil || CompareWithExpr(pool.MatchExpr, params) {
|
||||||
|
pool.OutputCh <- bl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ package internal
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/antonmedv/expr"
|
|
||||||
"github.com/antonmedv/expr/vm"
|
|
||||||
"github.com/chainreactors/logs"
|
"github.com/chainreactors/logs"
|
||||||
"github.com/chainreactors/parsers"
|
"github.com/chainreactors/parsers"
|
||||||
"github.com/chainreactors/parsers/iutils"
|
"github.com/chainreactors/parsers/iutils"
|
||||||
@ -561,19 +559,6 @@ func (pool *Pool) BaseCompare(bl *pkg.Baseline) bool {
|
|||||||
return true
|
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 {
|
func (pool *Pool) Upgrade(bl *pkg.Baseline) error {
|
||||||
rurl, err := url.Parse(bl.RedirectURL)
|
rurl, err := url.Parse(bl.RedirectURL)
|
||||||
if err == nil && rurl.Hostname() == bl.Url.Hostname() && bl.Url.Scheme == "http" && rurl.Scheme == "https" {
|
if err == nil && rurl.Hostname() == bl.Url.Hostname() && bl.Url.Scheme == "http" && rurl.Scheme == "https" {
|
||||||
|
@ -2,6 +2,9 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/antonmedv/expr"
|
||||||
|
"github.com/antonmedv/expr/vm"
|
||||||
|
"github.com/chainreactors/logs"
|
||||||
"github.com/chainreactors/spray/pkg"
|
"github.com/chainreactors/spray/pkg"
|
||||||
"github.com/chainreactors/words/mask"
|
"github.com/chainreactors/words/mask"
|
||||||
"github.com/chainreactors/words/rule"
|
"github.com/chainreactors/words/rule"
|
||||||
@ -249,3 +252,16 @@ func FormatURL(base, u string) string {
|
|||||||
func RandomUA() string {
|
func RandomUA() string {
|
||||||
return randomUserAgent[rand.Intn(uacount)]
|
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() {
|
func (c *Client) TransToCheck() {
|
||||||
if c.fastClient != nil {
|
if c.fastClient != nil {
|
||||||
c.fastClient.MaxConnsPerHost = 1
|
c.fastClient.MaxConnsPerHost = -1 // disable keepalive
|
||||||
} else if c.standardClient != nil {
|
} else if c.standardClient != nil {
|
||||||
|
c.standardClient.Transport.(*http.Transport).DisableKeepAlives = true // disable keepalive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user