mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 11:40:13 +00:00
实装random useragent
This commit is contained in:
parent
bdc793c75b
commit
4a12286beb
@ -126,29 +126,30 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
|
|||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
r := &Runner{
|
r := &Runner{
|
||||||
Progress: uiprogress.New(),
|
Progress: uiprogress.New(),
|
||||||
Threads: opt.Threads,
|
Threads: opt.Threads,
|
||||||
PoolSize: opt.PoolSize,
|
PoolSize: opt.PoolSize,
|
||||||
Mod: opt.Mod,
|
Mod: opt.Mod,
|
||||||
Timeout: opt.Timeout,
|
Timeout: opt.Timeout,
|
||||||
RateLimit: opt.RateLimit,
|
RateLimit: opt.RateLimit,
|
||||||
Deadline: opt.Deadline,
|
Deadline: opt.Deadline,
|
||||||
Headers: make(map[string]string),
|
Headers: make(map[string]string),
|
||||||
Offset: opt.Offset,
|
Offset: opt.Offset,
|
||||||
Total: opt.Limit,
|
Total: opt.Limit,
|
||||||
taskCh: make(chan *Task),
|
taskCh: make(chan *Task),
|
||||||
OutputCh: make(chan *pkg.Baseline, 100),
|
OutputCh: make(chan *pkg.Baseline, 100),
|
||||||
FuzzyCh: make(chan *pkg.Baseline, 100),
|
FuzzyCh: make(chan *pkg.Baseline, 100),
|
||||||
Fuzzy: opt.Fuzzy,
|
Fuzzy: opt.Fuzzy,
|
||||||
Force: opt.Force,
|
Force: opt.Force,
|
||||||
CheckOnly: opt.CheckOnly,
|
CheckOnly: opt.CheckOnly,
|
||||||
CheckPeriod: opt.CheckPeriod,
|
CheckPeriod: opt.CheckPeriod,
|
||||||
ErrPeriod: opt.ErrPeriod,
|
ErrPeriod: opt.ErrPeriod,
|
||||||
BreakThreshold: opt.BreakThreshold,
|
BreakThreshold: opt.BreakThreshold,
|
||||||
Crawl: opt.Crawl,
|
Crawl: opt.Crawl,
|
||||||
Active: opt.Active,
|
Active: opt.Active,
|
||||||
Bak: opt.Bak,
|
Bak: opt.Bak,
|
||||||
Common: opt.Common,
|
Common: opt.Common,
|
||||||
|
RandomUserAgent: opt.RandomUserAgent,
|
||||||
}
|
}
|
||||||
|
|
||||||
// log and bar
|
// log and bar
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -61,7 +62,7 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) {
|
|||||||
limiter: rate.NewLimiter(rate.Limit(config.RateLimit), 1),
|
limiter: rate.NewLimiter(rate.Limit(config.RateLimit), 1),
|
||||||
failedCount: 1,
|
failedCount: 1,
|
||||||
}
|
}
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
// 格式化dir, 保证至少有一个"/"
|
// 格式化dir, 保证至少有一个"/"
|
||||||
if strings.HasSuffix(config.BaseURL, "/") {
|
if strings.HasSuffix(config.BaseURL, "/") {
|
||||||
pool.dir = pool.url.Path
|
pool.dir = pool.url.Path
|
||||||
@ -257,7 +258,10 @@ func (pool *Pool) Invoke(v interface{}) {
|
|||||||
logs.Log.Error(err.Error())
|
logs.Log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
req.SetHeaders(pool.Headers)
|
req.SetHeaders(pool.Headers)
|
||||||
|
req.SetHeader("User-Agent", RandomUA())
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
resp, reqerr := pool.client.Do(pool.ctx, req)
|
resp, reqerr := pool.client.Do(pool.ctx, req)
|
||||||
if pool.ClientType == ihttp.FAST {
|
if pool.ClientType == ihttp.FAST {
|
||||||
|
@ -36,74 +36,76 @@ type Runner struct {
|
|||||||
bar *uiprogress.Bar
|
bar *uiprogress.Bar
|
||||||
finished int
|
finished int
|
||||||
|
|
||||||
Tasks []*Task
|
Tasks []*Task
|
||||||
URLList []string
|
URLList []string
|
||||||
Wordlist []string
|
Wordlist []string
|
||||||
Rules *rule.Program
|
Rules *rule.Program
|
||||||
AppendRules *rule.Program
|
AppendRules *rule.Program
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
Fns []func(string) string
|
Fns []func(string) string
|
||||||
FilterExpr *vm.Program
|
FilterExpr *vm.Program
|
||||||
MatchExpr *vm.Program
|
MatchExpr *vm.Program
|
||||||
RecursiveExpr *vm.Program
|
RecursiveExpr *vm.Program
|
||||||
RecuDepth int
|
RecuDepth int
|
||||||
Threads int
|
Threads int
|
||||||
PoolSize int
|
PoolSize int
|
||||||
ClientType int
|
ClientType int
|
||||||
Pools *ants.PoolWithFunc
|
Pools *ants.PoolWithFunc
|
||||||
PoolName map[string]bool
|
PoolName map[string]bool
|
||||||
Timeout int
|
Timeout int
|
||||||
Mod string
|
Mod string
|
||||||
Probes []string
|
Probes []string
|
||||||
OutputCh chan *pkg.Baseline
|
OutputCh chan *pkg.Baseline
|
||||||
FuzzyCh chan *pkg.Baseline
|
FuzzyCh chan *pkg.Baseline
|
||||||
Fuzzy bool
|
Fuzzy bool
|
||||||
OutputFile *files.File
|
OutputFile *files.File
|
||||||
FuzzyFile *files.File
|
FuzzyFile *files.File
|
||||||
DumpFile *files.File
|
DumpFile *files.File
|
||||||
StatFile *files.File
|
StatFile *files.File
|
||||||
Progress *uiprogress.Progress
|
Progress *uiprogress.Progress
|
||||||
Offset int
|
Offset int
|
||||||
Limit int
|
Limit int
|
||||||
RateLimit int
|
RateLimit int
|
||||||
Total int
|
Total int
|
||||||
Deadline int
|
Deadline int
|
||||||
CheckPeriod int
|
CheckPeriod int
|
||||||
ErrPeriod int
|
ErrPeriod int
|
||||||
BreakThreshold int
|
BreakThreshold int
|
||||||
Color bool
|
Color bool
|
||||||
CheckOnly bool
|
CheckOnly bool
|
||||||
Force bool
|
Force bool
|
||||||
IgnoreWaf bool
|
IgnoreWaf bool
|
||||||
Crawl bool
|
Crawl bool
|
||||||
Active bool
|
Active bool
|
||||||
Bak bool
|
Bak bool
|
||||||
Common bool
|
Common bool
|
||||||
|
RandomUserAgent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) PrepareConfig() *pkg.Config {
|
func (r *Runner) PrepareConfig() *pkg.Config {
|
||||||
config := &pkg.Config{
|
config := &pkg.Config{
|
||||||
Thread: r.Threads,
|
Thread: r.Threads,
|
||||||
Timeout: r.Timeout,
|
Timeout: r.Timeout,
|
||||||
RateLimit: r.RateLimit,
|
RateLimit: r.RateLimit,
|
||||||
Headers: r.Headers,
|
Headers: r.Headers,
|
||||||
Mod: pkg.ModMap[r.Mod],
|
Mod: pkg.ModMap[r.Mod],
|
||||||
OutputCh: r.OutputCh,
|
OutputCh: r.OutputCh,
|
||||||
FuzzyCh: r.FuzzyCh,
|
FuzzyCh: r.FuzzyCh,
|
||||||
Fuzzy: r.Fuzzy,
|
Fuzzy: r.Fuzzy,
|
||||||
CheckPeriod: r.CheckPeriod,
|
CheckPeriod: r.CheckPeriod,
|
||||||
ErrPeriod: int32(r.ErrPeriod),
|
ErrPeriod: int32(r.ErrPeriod),
|
||||||
BreakThreshold: int32(r.BreakThreshold),
|
BreakThreshold: int32(r.BreakThreshold),
|
||||||
MatchExpr: r.MatchExpr,
|
MatchExpr: r.MatchExpr,
|
||||||
FilterExpr: r.FilterExpr,
|
FilterExpr: r.FilterExpr,
|
||||||
RecuExpr: r.RecursiveExpr,
|
RecuExpr: r.RecursiveExpr,
|
||||||
AppendRule: r.AppendRules,
|
AppendRule: r.AppendRules,
|
||||||
IgnoreWaf: r.IgnoreWaf,
|
IgnoreWaf: r.IgnoreWaf,
|
||||||
Crawl: r.Crawl,
|
Crawl: r.Crawl,
|
||||||
Active: r.Active,
|
Active: r.Active,
|
||||||
Bak: r.Bak,
|
Bak: r.Bak,
|
||||||
Common: r.Common,
|
Common: r.Common,
|
||||||
ClientType: r.ClientType,
|
ClientType: r.ClientType,
|
||||||
|
RandomUserAgent: r.RandomUserAgent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ClientType == 0 {
|
if config.ClientType == 0 {
|
||||||
|
@ -6,12 +6,31 @@ import (
|
|||||||
"github.com/chainreactors/words/mask"
|
"github.com/chainreactors/words/mask"
|
||||||
"github.com/chainreactors/words/rule"
|
"github.com/chainreactors/words/rule"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
randomUserAgent = []string{
|
||||||
|
"Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36",
|
||||||
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1",
|
||||||
|
"Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; RM-1152) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15254",
|
||||||
|
"Mozilla/5.0 (Linux; Android 7.0; Pixel C Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Safari/537.36",
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246",
|
||||||
|
"Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36",
|
||||||
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9",
|
||||||
|
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
|
||||||
|
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1",
|
||||||
|
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
||||||
|
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
|
||||||
|
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
|
||||||
|
}
|
||||||
|
uacount = len(randomUserAgent)
|
||||||
|
)
|
||||||
|
|
||||||
func parseExtension(s string) string {
|
func parseExtension(s string) string {
|
||||||
if i := strings.Index(s, "."); i != -1 {
|
if i := strings.Index(s, "."); i != -1 {
|
||||||
return s[i+1:]
|
return s[i+1:]
|
||||||
@ -232,3 +251,7 @@ func FormatURL(base, u string) string {
|
|||||||
return relaPath(base, u)
|
return relaPath(base, u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandomUA() string {
|
||||||
|
return randomUserAgent[rand.Intn(uacount)]
|
||||||
|
}
|
||||||
|
@ -20,28 +20,29 @@ var ModMap = map[string]SprayMod{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
Thread int
|
Thread int
|
||||||
Wordlist []string
|
Wordlist []string
|
||||||
Timeout int
|
Timeout int
|
||||||
RateLimit int
|
RateLimit int
|
||||||
CheckPeriod int
|
CheckPeriod int
|
||||||
ErrPeriod int32
|
ErrPeriod int32
|
||||||
BreakThreshold int32
|
BreakThreshold int32
|
||||||
Method string
|
Method string
|
||||||
Mod SprayMod
|
Mod SprayMod
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
ClientType int
|
ClientType int
|
||||||
MatchExpr *vm.Program
|
MatchExpr *vm.Program
|
||||||
FilterExpr *vm.Program
|
FilterExpr *vm.Program
|
||||||
RecuExpr *vm.Program
|
RecuExpr *vm.Program
|
||||||
AppendRule *rule.Program
|
AppendRule *rule.Program
|
||||||
OutputCh chan *Baseline
|
OutputCh chan *Baseline
|
||||||
FuzzyCh chan *Baseline
|
FuzzyCh chan *Baseline
|
||||||
Fuzzy bool
|
Fuzzy bool
|
||||||
IgnoreWaf bool
|
IgnoreWaf bool
|
||||||
Crawl bool
|
Crawl bool
|
||||||
Active bool
|
Active bool
|
||||||
Bak bool
|
Bak bool
|
||||||
Common bool
|
Common bool
|
||||||
|
RandomUserAgent bool
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user