自动判断协议升级

This commit is contained in:
M09Ic 2022-11-29 20:50:00 +08:00
parent 35fbb1a3c0
commit 0233c3017b
4 changed files with 34 additions and 18 deletions

View File

@ -51,7 +51,7 @@ func NewCheckPool(ctx context.Context, config *pkg.Config) (*CheckPool, error) {
if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge { if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge {
pool.failedCount++ pool.failedCount++
bl = &pkg.Baseline{Url: pool.BaseURL + unit.path, IsValid: false, ErrString: reqerr.Error(), Reason: ErrRequestFailed.Error()} bl = &pkg.Baseline{UrlString: pool.BaseURL + unit.path, IsValid: false, ErrString: reqerr.Error(), Reason: ErrRequestFailed.Error()}
} else { } else {
bl = pkg.NewBaseline(req.URI(), req.Host(), resp) bl = pkg.NewBaseline(req.URI(), req.Host(), resp)
bl.Collect() bl.Collect()

View File

@ -117,7 +117,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
r.Progress.Start() r.Progress.Start()
logs.Log.Writer = r.Progress.Bypass() logs.Log.Writer = r.Progress.Bypass()
} else { } else {
logs.Log.Level = 100 logs.Log.Quiet = true
} }
if opt.SimhashDistance != 0 { if opt.SimhashDistance != 0 {
@ -315,10 +315,12 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
} }
} }
if opt.FuzzyFile != "" {
r.FuzzyFile, err = files.NewFile(opt.FuzzyFile, false, false, true) r.FuzzyFile, err = files.NewFile(opt.FuzzyFile, false, false, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
r.StatFile, err = files.NewFile("stat.json", false, false, true) r.StatFile, err = files.NewFile("stat.json", false, false, true)
if err != nil { if err != nil {

View File

@ -11,7 +11,9 @@ import (
"github.com/chainreactors/words" "github.com/chainreactors/words"
"github.com/panjf2000/ants/v2" "github.com/panjf2000/ants/v2"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
"net/url"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
) )
@ -87,7 +89,7 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) {
if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge { if reqerr != nil && reqerr != fasthttp.ErrBodyTooLarge {
pool.failedCount++ pool.failedCount++
pool.Statistor.FailedNumber++ pool.Statistor.FailedNumber++
bl = &pkg.Baseline{Url: pool.BaseURL + unit.path, IsValid: false, ErrString: reqerr.Error(), Reason: ErrRequestFailed.Error()} bl = &pkg.Baseline{UrlString: pool.BaseURL + unit.path, IsValid: false, ErrString: reqerr.Error(), Reason: ErrRequestFailed.Error()}
pool.failedBaselines = append(pool.failedBaselines, bl) pool.failedBaselines = append(pool.failedBaselines, bl)
} else { } else {
if unit.source != WordSource { if unit.source != WordSource {
@ -228,6 +230,15 @@ func (p *Pool) Init() error {
return fmt.Errorf(p.index.String()) return fmt.Errorf(p.index.String())
} }
if p.base.RedirectURL != "" {
// 自定协议升级
// 某些网站http会重定向到https, 如果发现随机目录出现这种情况, 则自定将baseurl升级为https
rurl, err := url.Parse(p.base.RedirectURL)
if err == nil && rurl.Host == p.base.Url.Host && p.base.Url.Scheme == "http" && rurl.Scheme == "https" {
logs.Log.Importantf("baseurl %s upgrade http to https", p.BaseURL)
p.BaseURL = strings.Replace(p.BaseURL, "http", "https", 1)
}
}
p.base.Collect() p.base.Collect()
p.index.Collect() p.index.Collect()
@ -341,7 +352,7 @@ func (p *Pool) BaseCompare(bl *pkg.Baseline) bool {
bl.Collect() bl.Collect()
for _, f := range bl.Frameworks { for _, f := range bl.Frameworks {
if f.Tag == "waf/cdn" { if f.Tag == "waf" || f.Tag == "cdn" {
p.Statistor.WafedNumber++ p.Statistor.WafedNumber++
bl.Reason = ErrWaf.Error() bl.Reason = ErrWaf.Error()
return false return false

View File

@ -11,13 +11,14 @@ import (
func NewBaseline(u, host string, resp *ihttp.Response) *Baseline { func NewBaseline(u, host string, resp *ihttp.Response) *Baseline {
bl := &Baseline{ bl := &Baseline{
Url: u, UrlString: u,
Status: resp.StatusCode(), Status: resp.StatusCode(),
IsValid: true, IsValid: true,
} }
uu, err := url.Parse(u) uu, err := url.Parse(u)
if err == nil { if err == nil {
bl.Path = uu.Path bl.Path = uu.Path
bl.Url = uu
} }
if resp.ClientType == ihttp.STANDARD { if resp.ClientType == ihttp.STANDARD {
bl.Host = host bl.Host = host
@ -34,7 +35,7 @@ func NewBaseline(u, host string, resp *ihttp.Response) *Baseline {
func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Baseline { func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Baseline {
bl := &Baseline{ bl := &Baseline{
Url: u, UrlString: u,
Status: resp.StatusCode(), Status: resp.StatusCode(),
IsValid: false, IsValid: false,
Reason: reason, Reason: reason,
@ -43,6 +44,7 @@ func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Ba
uu, err := url.Parse(u) uu, err := url.Parse(u)
if err == nil { if err == nil {
bl.Path = uu.Path bl.Path = uu.Path
bl.Url = uu
} }
if resp.ClientType == ihttp.STANDARD { if resp.ClientType == ihttp.STANDARD {
@ -57,7 +59,8 @@ func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Ba
} }
type Baseline struct { type Baseline struct {
Url string `json:"url"` Url *url.URL `json:"-"`
UrlString string `json:"url"`
Path string `json:"path"` Path string `json:"path"`
Host string `json:"host"` Host string `json:"host"`
Body []byte `json:"-"` Body []byte `json:"-"`
@ -132,7 +135,7 @@ func (bl *Baseline) FuzzyCompare(other *Baseline) bool {
func (bl *Baseline) Get(key string) string { func (bl *Baseline) Get(key string) string {
switch key { switch key {
case "url": case "url":
return bl.Url return bl.UrlString
case "host": case "host":
return bl.Host return bl.Host
case "title": case "title":
@ -180,7 +183,7 @@ func (bl *Baseline) Additional(key string) string {
func (bl *Baseline) Format(probes []string) string { func (bl *Baseline) Format(probes []string) string {
var line strings.Builder var line strings.Builder
line.WriteString(bl.Url) line.WriteString(bl.UrlString)
if bl.Host != "" { if bl.Host != "" {
line.WriteString(" (" + bl.Host + ")") line.WriteString(" (" + bl.Host + ")")
} }
@ -206,7 +209,7 @@ func (bl *Baseline) Format(probes []string) string {
func (bl *Baseline) String() string { func (bl *Baseline) String() string {
var line strings.Builder var line strings.Builder
//line.WriteString("[+] ") //line.WriteString("[+] ")
line.WriteString(bl.Url) line.WriteString(bl.UrlString)
if bl.Host != "" { if bl.Host != "" {
line.WriteString(" (" + bl.Host + ")") line.WriteString(" (" + bl.Host + ")")
} }