Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/blazehttp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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")
Expand Down Expand Up @@ -118,6 +120,7 @@ func main() {
fileList,
blockStatusCode,
worker.WithConcurrence(c),
worker.WithSleep(s),
worker.WithReqHost(mHost),
worker.WithReqPerSession(requestPerSession),
worker.WithTimeout(timeout),
Expand Down
14 changes: 12 additions & 2 deletions gui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -95,6 +102,7 @@ func NewWorker(
) *Worker {
w := &Worker{
concurrence: 10, // default 10
sleep: 0, // default 10

// payloads
fileList: fileList,
Expand Down Expand Up @@ -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 {
Expand Down