Refactor progress functionality to correct modules (#33)

This commit is contained in:
Joona Hoikkala 2019-04-28 01:08:09 +03:00 committed by GitHub
parent 5264d85fc6
commit 45bffbffca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 45 deletions

View File

@ -16,32 +16,33 @@ type optRange struct {
}
type Config struct {
StaticHeaders map[string]string
FuzzHeaders map[string]string
Extensions []string
DirSearchCompat bool
Method string
Url string
TLSVerify bool
Data string
Quiet bool
Colors bool
Wordlist string
OutputFile string
OutputFormat string
StopOn403 bool
StopOnErrors bool
StopOnAll bool
FollowRedirects bool
AutoCalibration bool
Timeout int
Delay optRange
Filters []FilterProvider
Matchers []FilterProvider
Threads int
Context context.Context
ProxyURL func(*http.Request) (*url.URL, error)
CommandLine string
StaticHeaders map[string]string
FuzzHeaders map[string]string
Extensions []string
DirSearchCompat bool
Method string
Url string
TLSVerify bool
Data string
Quiet bool
Colors bool
Wordlist string
OutputFile string
OutputFormat string
StopOn403 bool
StopOnErrors bool
StopOnAll bool
FollowRedirects bool
AutoCalibration bool
Timeout int
ProgressFrequency int
Delay optRange
Filters []FilterProvider
Matchers []FilterProvider
Threads int
Context context.Context
ProxyURL func(*http.Request) (*url.URL, error)
CommandLine string
}
func NewConfig(ctx context.Context) Config {
@ -63,6 +64,8 @@ func NewConfig(ctx context.Context) Config {
conf.Delay = optRange{0, 0, false, false}
conf.Extensions = make([]string, 0)
conf.Timeout = 10
// Progress update frequency, in milliseconds
conf.ProgressFrequency = 100
conf.DirSearchCompat = false
return conf
}

View File

@ -23,7 +23,7 @@ type InputProvider interface {
type OutputProvider interface {
Banner() error
Finalize() error
Progress(status string)
Progress(status Progress)
Error(errstring string)
Warning(warnstring string)
Result(resp Response)

View File

@ -115,26 +115,18 @@ func (j *Job) runProgress(wg *sync.WaitGroup) {
if j.Counter == totalProgress {
return
}
time.Sleep(time.Millisecond * 100)
time.Sleep(time.Millisecond * time.Duration(j.Config.ProgressFrequency))
}
}
func (j *Job) updateProgress() {
runningSecs := int((time.Now().Sub(j.startTime)) / time.Second)
var reqRate int
if runningSecs > 0 {
reqRate = int(j.Counter / runningSecs)
} else {
reqRate = 0
prog := Progress{
StartedAt: j.startTime,
ReqCount: j.Counter,
ReqTotal: j.Input.Total(),
ErrorCount: j.ErrorCounter,
}
dur := time.Now().Sub(j.startTime)
hours := dur / time.Hour
dur -= hours * time.Hour
mins := dur / time.Minute
dur -= mins * time.Minute
secs := dur / time.Second
progString := fmt.Sprintf(":: Progress: [%d/%d] :: %d req/sec :: Duration: [%d:%02d:%02d] :: Errors: %d ::", j.Counter, j.Total, int(reqRate), hours, mins, secs, j.ErrorCounter)
j.Output.Progress(progString)
j.Output.Progress(prog)
}
//Calibrate runs a self-calibration task for filtering options, requesting random resources and acting accordingly

12
pkg/ffuf/progress.go Normal file
View File

@ -0,0 +1,12 @@
package ffuf
import (
"time"
)
type Progress struct {
StartedAt time.Time
ReqCount int
ReqTotal int
ErrorCount int
}

View File

@ -3,6 +3,7 @@ package output
import (
"fmt"
"os"
"time"
"github.com/ffuf/ffuf/pkg/ffuf"
)
@ -52,13 +53,28 @@ func (s *Stdoutput) Banner() error {
return nil
}
func (s *Stdoutput) Progress(status string) {
func (s *Stdoutput) Progress(status ffuf.Progress) {
if s.config.Quiet {
// No progress for quiet mode
return
} else {
fmt.Fprintf(os.Stderr, "%s%s", TERMINAL_CLEAR_LINE, status)
}
dur := time.Now().Sub(status.StartedAt)
runningSecs := int(dur / time.Second)
var reqRate int
if runningSecs > 0 {
reqRate = int(status.ReqCount / runningSecs)
} else {
reqRate = 0
}
hours := dur / time.Hour
dur -= hours * time.Hour
mins := dur / time.Minute
dur -= mins * time.Minute
secs := dur / time.Second
fmt.Fprintf(os.Stderr, "%s:: Progress: [%d/%d] :: %d req/sec :: Duration: [%d:%02d:%02d] :: Errors: %d ::", TERMINAL_CLEAR_LINE, status.ReqCount, status.ReqTotal, reqRate, hours, mins, secs, status.ErrorCount)
}
func (s *Stdoutput) Error(errstring string) {