diff --git a/cmd/blazehttp/main.go b/cmd/blazehttp/main.go index 18587c24..b3467636 100644 --- a/cmd/blazehttp/main.go +++ b/cmd/blazehttp/main.go @@ -26,6 +26,7 @@ var ( glob string // use glob expression to select multi files timeout = 1000 // default 1000 ms c = 10 // default 10 concurrent workers + s = 0 // default 0 sleep second mHost string // modify host header requestPerSession bool // send request per session ) @@ -37,6 +38,7 @@ func init() { } flag.StringVar(&target, "t", "", "target website, example: http://192.168.0.1:8080") flag.IntVar(&c, "c", 10, "concurrent workers, default 10") + flag.IntVar(&s, "s", 0, "sleep second, default 0") flag.StringVar(&glob, "g", "", "glob expression, example: *.http") flag.IntVar(&timeout, "timeout", 1000, "connection timeout, default 1000 ms") flag.StringVar(&mHost, "H", "", "modify host header") @@ -118,6 +120,7 @@ func main() { fileList, blockStatusCode, worker.WithConcurrence(c), + worker.WithSleep(s), worker.WithReqHost(mHost), worker.WithReqPerSession(requestPerSession), worker.WithTimeout(timeout), diff --git a/gui/main.go b/gui/main.go index 61c2148d..76de6a55 100644 --- a/gui/main.go +++ b/gui/main.go @@ -242,6 +242,11 @@ func MakeRunForm(w fyne.Window, outputCh chan string, resultCh chan *worker.Resu workers := widget.NewEntry() workers.SetText("10") workers.Validator = validation.NewRegexp(`^\d+$`, "工作线程必须是数字") + + sleep := widget.NewEntry() + sleep.SetText("0") + sleep.Validator = validation.NewRegexp(`^\d+$`, "请求间隔必须是数字") + // modify host header reqHost := widget.NewEntry() // timeout @@ -272,6 +277,7 @@ func MakeRunForm(w fyne.Window, outputCh chan string, resultCh chan *worker.Resu Items: []*widget.FormItem{ {Text: "目标网站", Widget: target, HintText: ""}, {Text: "工作线程", Widget: workers, HintText: ""}, + {Text: "请求间隔(秒)", Widget: sleep, HintText: "注:请求间隔用于外部waf频率过高会封ip时候选择,使用时结合工作线程计算频率"}, }, } // cancel @@ -304,10 +310,13 @@ func MakeRunForm(w fyne.Window, outputCh chan string, resultCh chan *worker.Resu workersText := strings.TrimSpace(workers.Text) worksNum, _ := strconv.Atoi(workersText) + sleepText := strings.TrimSpace(sleep.Text) + sleepNum, _ := strconv.Atoi(sleepText) + statusCode := strings.TrimSpace(statusCode.Text) statusCodeI, _ := strconv.Atoi(statusCode) - err := run(target.Text, reqHost.Text, worksNum, statusCodeI, resultCh, stopCh) + err := run(target.Text, reqHost.Text, worksNum,sleepNum, statusCodeI, resultCh, stopCh) if err != nil { outputCh <- err.Error() } @@ -460,7 +469,7 @@ func MakeTestCaseTab(w fyne.Window) fyne.CanvasObject { return container.NewBorder(tableFilterForm, nil, nil, exportBtn, table) } -func run(target, mHost string, c, statusCode int, resultCh chan *worker.Result, stopCh chan struct{}) error { +func run(target, mHost string, c,sleepNum, statusCode int, resultCh chan *worker.Result, stopCh chan struct{}) error { var addr string var isHttps bool @@ -489,6 +498,7 @@ func run(target, mHost string, c, statusCode int, resultCh chan *worker.Result, allTestData, blockStatusCode, worker.WithConcurrence(c), + worker.WithSleep(sleepNum), worker.WithReqHost(mHost), worker.WithUseEmbedFS(true), // use embed test case fs when glob is empty worker.WithResultCh(resultCh), diff --git a/worker/worker.go b/worker/worker.go index d11dd56f..557b6274 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -21,6 +21,7 @@ type Worker struct { cancel context.CancelFunc concurrence int // concurrent connections + sleep int // concurrent connections fileList []string jobs chan *Job jobResult chan *Job @@ -70,6 +71,12 @@ func WithConcurrence(c int) WorkerOption { } } +func WithSleep(c int) WorkerOption { + return func(w *Worker) { + w.sleep = c + } +} + func WithResultCh(ch chan *Result) WorkerOption { return func(w *Worker) { w.resultCh = ch @@ -95,6 +102,7 @@ func NewWorker( ) *Worker { w := &Worker{ concurrence: 10, // default 10 + sleep: 0, // default 10 // payloads fileList: fileList, @@ -185,6 +193,9 @@ func (w *Worker) runWorker() { defer func() { w.jobResult <- job }() + if w.sleep >0 { + time.Sleep(time.Duration(w.sleep) * time.Second) // 这里可以选择在工作中间或之前添加 sleep + } filePath := job.FilePath req := new(blazehttp.Request) if w.useEmbedFS {