Skip to content

Commit

Permalink
enhance: skip not same host redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
M09Ic committed Oct 30, 2024
1 parent 5cb9aa1 commit 0ca5c02
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
32 changes: 20 additions & 12 deletions internal/pool/brutepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (pool *BrutePool) Invoke(v interface{}) {

// 手动处理重定向
if bl.IsValid && unit.source != parsers.CheckSource && bl.RedirectURL != "" {
//pool.wg.Add(1)
bl.SameDomain = pool.checkHost(bl.RedirectURL)
pool.doRedirect(bl, unit.depth)
}

Expand Down Expand Up @@ -508,7 +508,7 @@ func (pool *BrutePool) Handler() {

func (pool *BrutePool) checkRedirect(redirectURL string) bool {
if pool.random.RedirectURL == "" {
// 如果random的redirectURL为空, 此时该项
// 如果random的redirectURL为空, 忽略
return true
}

Expand Down Expand Up @@ -562,7 +562,9 @@ func (pool *BrutePool) PreCompare(resp *ihttp.Response) error {
return nil
}

func (pool *BrutePool) checkHostname(u string) bool {
// same host return true
// diff host return false
func (pool *BrutePool) checkHost(u string) bool {
if v, err := url.Parse(u); err == nil {
if v.Host == "" {
return true
Expand All @@ -582,8 +584,19 @@ func (pool *BrutePool) BaseCompare(bl *pkg.Baseline) bool {
}
var status = -1

// 30x状态码的特殊处理
if bl.RedirectURL != "" {
if bl.SameDomain && strings.HasSuffix(bl.RedirectURL, bl.Url.Path+"/") {
bl.Reason = pkg.ErrFuzzyRedirect.Error()
return false
}
}

// 使用与baseline相同状态码, 需要在fuzzystatus中提前配置
base, ok := pool.baselines[bl.Status] // 挑选对应状态码的baseline进行compare
if bl.IsBaseline {
ok = false
}
if !ok {
if pool.random.Status == bl.Status {
// 当other的状态码与base相同时, 会使用base
Expand All @@ -596,15 +609,7 @@ func (pool *BrutePool) BaseCompare(bl *pkg.Baseline) bool {
}
}

// 30x状态码的特殊处理
if bl.RedirectURL != "" {
if pool.checkHostname(bl.RedirectURL) && strings.HasSuffix(bl.RedirectURL, bl.Url.Path+"/") {
bl.Reason = pkg.ErrFuzzyRedirect.Error()
return false
}
}

if ok && !bl.IsBaseline {
if ok {
if status = base.Compare(bl); status == 1 {
bl.Reason = pkg.ErrCompareFailed.Error()
return false
Expand Down Expand Up @@ -704,6 +709,9 @@ func (pool *BrutePool) doRedirect(bl *pkg.Baseline, depth int) {
if depth >= pool.MaxRedirect {
return
}
if !bl.SameDomain {
return // 不同域名的重定向不处理
}
reURL := pkg.FormatURL(bl.Url.Path, bl.RedirectURL)
pool.wg.Add(1)
go func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/baseline.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type Baseline struct {
URLs []string `json:"-"`
Collected bool `json:"-"`
Retry int `json:"-"`
SameDomain bool `json:"-"`
IsBaseline bool `json:"-"`
}

Expand Down

0 comments on commit 0ca5c02

Please sign in to comment.