Refactor progress functionality to correct modules (#33)
This commit is contained in:
parent
5264d85fc6
commit
45bffbffca
@ -16,32 +16,33 @@ type optRange struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
StaticHeaders map[string]string
|
StaticHeaders map[string]string
|
||||||
FuzzHeaders map[string]string
|
FuzzHeaders map[string]string
|
||||||
Extensions []string
|
Extensions []string
|
||||||
DirSearchCompat bool
|
DirSearchCompat bool
|
||||||
Method string
|
Method string
|
||||||
Url string
|
Url string
|
||||||
TLSVerify bool
|
TLSVerify bool
|
||||||
Data string
|
Data string
|
||||||
Quiet bool
|
Quiet bool
|
||||||
Colors bool
|
Colors bool
|
||||||
Wordlist string
|
Wordlist string
|
||||||
OutputFile string
|
OutputFile string
|
||||||
OutputFormat string
|
OutputFormat string
|
||||||
StopOn403 bool
|
StopOn403 bool
|
||||||
StopOnErrors bool
|
StopOnErrors bool
|
||||||
StopOnAll bool
|
StopOnAll bool
|
||||||
FollowRedirects bool
|
FollowRedirects bool
|
||||||
AutoCalibration bool
|
AutoCalibration bool
|
||||||
Timeout int
|
Timeout int
|
||||||
Delay optRange
|
ProgressFrequency int
|
||||||
Filters []FilterProvider
|
Delay optRange
|
||||||
Matchers []FilterProvider
|
Filters []FilterProvider
|
||||||
Threads int
|
Matchers []FilterProvider
|
||||||
Context context.Context
|
Threads int
|
||||||
ProxyURL func(*http.Request) (*url.URL, error)
|
Context context.Context
|
||||||
CommandLine string
|
ProxyURL func(*http.Request) (*url.URL, error)
|
||||||
|
CommandLine string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(ctx context.Context) Config {
|
func NewConfig(ctx context.Context) Config {
|
||||||
@ -63,6 +64,8 @@ func NewConfig(ctx context.Context) Config {
|
|||||||
conf.Delay = optRange{0, 0, false, false}
|
conf.Delay = optRange{0, 0, false, false}
|
||||||
conf.Extensions = make([]string, 0)
|
conf.Extensions = make([]string, 0)
|
||||||
conf.Timeout = 10
|
conf.Timeout = 10
|
||||||
|
// Progress update frequency, in milliseconds
|
||||||
|
conf.ProgressFrequency = 100
|
||||||
conf.DirSearchCompat = false
|
conf.DirSearchCompat = false
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ type InputProvider interface {
|
|||||||
type OutputProvider interface {
|
type OutputProvider interface {
|
||||||
Banner() error
|
Banner() error
|
||||||
Finalize() error
|
Finalize() error
|
||||||
Progress(status string)
|
Progress(status Progress)
|
||||||
Error(errstring string)
|
Error(errstring string)
|
||||||
Warning(warnstring string)
|
Warning(warnstring string)
|
||||||
Result(resp Response)
|
Result(resp Response)
|
||||||
|
|||||||
@ -115,26 +115,18 @@ func (j *Job) runProgress(wg *sync.WaitGroup) {
|
|||||||
if j.Counter == totalProgress {
|
if j.Counter == totalProgress {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * time.Duration(j.Config.ProgressFrequency))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Job) updateProgress() {
|
func (j *Job) updateProgress() {
|
||||||
runningSecs := int((time.Now().Sub(j.startTime)) / time.Second)
|
prog := Progress{
|
||||||
var reqRate int
|
StartedAt: j.startTime,
|
||||||
if runningSecs > 0 {
|
ReqCount: j.Counter,
|
||||||
reqRate = int(j.Counter / runningSecs)
|
ReqTotal: j.Input.Total(),
|
||||||
} else {
|
ErrorCount: j.ErrorCounter,
|
||||||
reqRate = 0
|
|
||||||
}
|
}
|
||||||
dur := time.Now().Sub(j.startTime)
|
j.Output.Progress(prog)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calibrate runs a self-calibration task for filtering options, requesting random resources and acting accordingly
|
//Calibrate runs a self-calibration task for filtering options, requesting random resources and acting accordingly
|
||||||
|
|||||||
12
pkg/ffuf/progress.go
Normal file
12
pkg/ffuf/progress.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package ffuf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Progress struct {
|
||||||
|
StartedAt time.Time
|
||||||
|
ReqCount int
|
||||||
|
ReqTotal int
|
||||||
|
ErrorCount int
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ package output
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ffuf/ffuf/pkg/ffuf"
|
"github.com/ffuf/ffuf/pkg/ffuf"
|
||||||
)
|
)
|
||||||
@ -52,13 +53,28 @@ func (s *Stdoutput) Banner() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stdoutput) Progress(status string) {
|
func (s *Stdoutput) Progress(status ffuf.Progress) {
|
||||||
if s.config.Quiet {
|
if s.config.Quiet {
|
||||||
// No progress for quiet mode
|
// No progress for quiet mode
|
||||||
return
|
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) {
|
func (s *Stdoutput) Error(errstring string) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user