关闭check-only的kepp-alive.

新增checkonly的--match指定过滤器
This commit is contained in:
M09Ic 2023-04-04 01:21:31 +08:00
parent 8ec00abe10
commit 77b92b44ea
4 changed files with 33 additions and 21 deletions

View File

@ -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()

View File

@ -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" {

View File

@ -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
}
}

View File

@ -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
}
}