From 4b78503d64ae76d590b113cd5224fa8016d24836 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Tue, 25 Apr 2023 17:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0url=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=98=AF=E7=9A=84=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/checkpool.go | 2 +- internal/pool.go | 20 ++++++++++---------- internal/types.go | 36 ------------------------------------ pkg/baseline.go | 2 ++ pkg/types.go | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 47 deletions(-) create mode 100644 pkg/types.go diff --git a/internal/checkpool.go b/internal/checkpool.go index 406803b..3ee5830 100644 --- a/internal/checkpool.go +++ b/internal/checkpool.go @@ -140,7 +140,7 @@ func (pool *CheckPool) Invoke(v interface{}) { UrlString: unit.path, IsValid: false, ErrString: reqerr.Error(), - Reason: ErrRequestFailed.Error(), + Reason: pkg.ErrRequestFailed.Error(), ReqDepth: unit.depth, }, } diff --git a/internal/pool.go b/internal/pool.go index 17bfd66..37f53d4 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -306,7 +306,7 @@ func (pool *Pool) Invoke(v interface{}) { UrlString: pool.base + unit.path, IsValid: false, ErrString: reqerr.Error(), - Reason: ErrRequestFailed.Error(), + Reason: pkg.ErrRequestFailed.Error(), }, } pool.failedBaselines = append(pool.failedBaselines, bl) @@ -475,7 +475,7 @@ func (pool *Pool) Handler() { if _, ok := pool.uniques[bl.Unique]; ok { bl.IsValid = false bl.IsFuzzy = true - bl.Reason = ErrFuzzyNotUnique.Error() + bl.Reason = pkg.ErrFuzzyNotUnique.Error() } else { pool.uniques[bl.Unique] = struct{}{} } @@ -484,7 +484,7 @@ func (pool *Pool) Handler() { // 对通过所有对比的有效数据进行再次filter if bl.IsValid && pool.FilterExpr != nil && CompareWithExpr(pool.FilterExpr, params) { pool.Statistor.FilteredNumber++ - bl.Reason = ErrCustomFilter.Error() + bl.Reason = pkg.ErrCustomFilter.Error() bl.IsValid = false } } else { @@ -522,19 +522,19 @@ func (pool *Pool) PreCompare(resp *ihttp.Response) error { return nil } if pool.random.Status != 200 && pool.random.Status == status { - return ErrSameStatus + return pkg.ErrSameStatus } if iutils.IntsContains(BlackStatus, status) { - return ErrBadStatus + return pkg.ErrBadStatus } if iutils.IntsContains(WAFStatus, status) { - return ErrWaf + return pkg.ErrWaf } if !pool.checkRedirect(resp.GetHeader("Location")) { - return ErrRedirect + return pkg.ErrRedirect } return nil @@ -547,7 +547,7 @@ func (pool *Pool) BaseCompare(bl *pkg.Baseline) bool { var status = -1 // 30x状态码的特殊处理 if bl.RedirectURL != "" && strings.HasSuffix(bl.RedirectURL, bl.Url.Path+"/") { - bl.Reason = ErrFuzzyRedirect.Error() + bl.Reason = pkg.ErrFuzzyRedirect.Error() pool.putToFuzzy(bl) return false } @@ -568,7 +568,7 @@ func (pool *Pool) BaseCompare(bl *pkg.Baseline) bool { if ok { if status = base.Compare(bl); status == 1 { - bl.Reason = ErrCompareFailed.Error() + bl.Reason = pkg.ErrCompareFailed.Error() return false } } @@ -588,7 +588,7 @@ func (pool *Pool) BaseCompare(bl *pkg.Baseline) bool { if ok && status == 0 && base.FuzzyCompare(bl) { pool.Statistor.FuzzyNumber++ - bl.Reason = ErrFuzzyCompareFailed.Error() + bl.Reason = pkg.ErrFuzzyCompareFailed.Error() pool.putToFuzzy(bl) return false } diff --git a/internal/types.go b/internal/types.go index b42308b..c823082 100644 --- a/internal/types.go +++ b/internal/types.go @@ -6,42 +6,6 @@ import ( "github.com/chainreactors/words/rule" ) -type ErrorType uint - -const ( - NoErr ErrorType = iota - ErrBadStatus - ErrSameStatus - ErrRequestFailed - ErrWaf - ErrRedirect - ErrCompareFailed - ErrCustomCompareFailed - ErrCustomFilter - ErrFuzzyCompareFailed - ErrFuzzyRedirect - ErrFuzzyNotUnique -) - -var ErrMap = map[ErrorType]string{ - NoErr: "", - ErrBadStatus: "blacklist status", - ErrSameStatus: "same status with random baseline", - ErrRequestFailed: "request failed", - ErrWaf: "maybe banned by waf", - ErrRedirect: "duplicate redirect url", - ErrCompareFailed: "compare failed", - ErrCustomCompareFailed: "custom compare failed", - ErrCustomFilter: "custom filtered", - ErrFuzzyCompareFailed: "fuzzy compare failed", - ErrFuzzyRedirect: "fuzzy redirect", - ErrFuzzyNotUnique: "not unique", -} - -func (e ErrorType) Error() string { - return ErrMap[e] -} - const ( CheckSource = iota + 1 InitRandomSource diff --git a/pkg/baseline.go b/pkg/baseline.go index 446c7da..201ad0c 100644 --- a/pkg/baseline.go +++ b/pkg/baseline.go @@ -61,6 +61,8 @@ func NewBaseline(u, host string, resp *ihttp.Response) *Baseline { } } else { bl.IsValid = false + bl.Reason = ErrUrlError.Error() + bl.ErrString = err.Error() } bl.Unique = UniqueHash(bl) return bl diff --git a/pkg/types.go b/pkg/types.go new file mode 100644 index 0000000..1dd3575 --- /dev/null +++ b/pkg/types.go @@ -0,0 +1,39 @@ +package pkg + +type ErrorType uint + +const ( + NoErr ErrorType = iota + ErrBadStatus + ErrSameStatus + ErrRequestFailed + ErrWaf + ErrRedirect + ErrCompareFailed + ErrCustomCompareFailed + ErrCustomFilter + ErrFuzzyCompareFailed + ErrFuzzyRedirect + ErrFuzzyNotUnique + ErrUrlError +) + +var ErrMap = map[ErrorType]string{ + NoErr: "", + ErrBadStatus: "blacklist status", + ErrSameStatus: "same status with random baseline", + ErrRequestFailed: "request failed", + ErrWaf: "maybe banned by waf", + ErrRedirect: "duplicate redirect url", + ErrCompareFailed: "compare failed", + ErrCustomCompareFailed: "custom compare failed", + ErrCustomFilter: "custom filtered", + ErrFuzzyCompareFailed: "fuzzy compare failed", + ErrFuzzyRedirect: "fuzzy redirect", + ErrFuzzyNotUnique: "not unique", + ErrUrlError: "url parse error", +} + +func (e ErrorType) Error() string { + return ErrMap[e] +}