Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create flag --start #133

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
11 changes: 8 additions & 3 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Options struct {

type runner func(ctx context.Context, t terminalapi.Terminal, c *container.Container, opts ...termdash.Option) error

func Run(targetURL string, storage storage.Reader, attacker attacker.Attacker, opts Options) error {
func Run(targetURL string, storage storage.Reader, attacker attacker.Attacker, opts Options, start bool) error {
var (
t terminalapi.Terminal
err error
Expand All @@ -48,10 +48,10 @@ func Run(targetURL string, storage storage.Reader, attacker attacker.Attacker, o
return fmt.Errorf("failed to generate terminal interface: %w", err)
}
defer t.Close()
return run(t, termdash.Run, targetURL, storage, attacker, opts)
return run(t, termdash.Run, targetURL, storage, attacker, opts, start)
}

func run(t terminalapi.Terminal, r runner, targetURL string, storage storage.Reader, a attacker.Attacker, opts Options) error {
func run(t terminalapi.Terminal, r runner, targetURL string, storage storage.Reader, a attacker.Attacker, opts Options, start bool) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -96,6 +96,11 @@ func run(t terminalapi.Terminal, r runner, targetURL string, storage storage.Rea

k := keybinds(ctx, cancel, c, d, a)

// Start the attack immediately if the start flag is set
if start {
attack(ctx, d, a)
}

return r(ctx, t, c, termdash.KeyboardSubscriber(k), termdash.RedrawInterval(opts.RedrawInternal))
}

Expand Down
2 changes: 1 addition & 1 deletion gui/gui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRun(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := run(&termbox.Terminal{}, tt.runner, "", &storage.FakeStorage{}, &attacker.FakeAttacker{}, Options{})
err := run(&termbox.Terminal{}, tt.runner, "", &storage.FakeStorage{}, &attacker.FakeAttacker{}, Options{}, false)
assert.Equal(t, tt.wantErr, err != nil)
})
}
Expand Down
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type cli struct {
tlsCertFile string
tlsKeyFile string
caCert string
start bool

//options for gui
queryRange time.Duration
Expand Down Expand Up @@ -100,6 +101,7 @@ func parseFlags(stdout, stderr io.Writer) (*cli, error) {
flagSet.StringVar(&c.localAddress, "local-addr", "0.0.0.0", "Local IP address.")
flagSet.BoolVar(&c.insecureSkipVerify, "insecure", false, "Skip TLS verification")
flagSet.StringVar(&c.caCert, "cacert", "", "PEM ca certificate file")
flagSet.BoolVar(&c.start, "start", false, "Start the attack immediately")
flagSet.StringVar(&c.tlsCertFile, "cert", "", "PEM encoded tls certificate file to use")
flagSet.StringVar(&c.tlsKeyFile, "key", "", "PEM encoded tls private key file to use")
// TODO: Re-enable when making it capable of drawing histogram bar chart.
Expand Down Expand Up @@ -155,12 +157,12 @@ func (c *cli) run(args []string) int {
}
setDebug(nil, c.debug)

if err := gui.Run(target, s, a,
gui.Options{
QueryRange: c.queryRange,
RedrawInternal: c.redrawInterval,
},
); err != nil {
guiOptions := gui.Options{
QueryRange: c.queryRange,
RedrawInternal: c.redrawInterval,
}

if err := gui.Run(target, s, a, guiOptions, c.start); err != nil {
fmt.Fprintf(c.stderr, "failed to start application: %s\n", err.Error())
c.usage()
return 1
Expand Down