Class: WASP::Nest
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#optionhelp ⇒ Object
readonly
Returns the value of attribute optionhelp.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#queenwasp ⇒ Object
readonly
Returns the value of attribute queenwasp.
-
#wasps ⇒ Object
readonly
Returns the value of attribute wasps.
Class Method Summary collapse
Instance Method Summary collapse
- #cleanup ⇒ Object
- #command_usage ⇒ Object
- #help(errcode = nil) ⇒ Object
- #info ⇒ Object
-
#initialize(args) ⇒ Nest
constructor
A new instance of Nest.
- #lost_wasps ⇒ Object
- #parse_command! ⇒ Object
- #parse_options! ⇒ Object
- #wakeup ⇒ Object
Constructor Details
#initialize(args) ⇒ Nest
Returns a new instance of Nest.
308 309 310 311 312 313 314 |
# File 'lib/wasp/nest.rb', line 308 def initialize(args) @args = args @options = { :colorize => true } @wasps = [] @queenwasp = nil @optionhelp = false end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
9 10 11 |
# File 'lib/wasp/nest.rb', line 9 def args @args end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/wasp/nest.rb', line 7 def key @key end |
#optionhelp ⇒ Object (readonly)
Returns the value of attribute optionhelp.
12 13 14 |
# File 'lib/wasp/nest.rb', line 12 def optionhelp @optionhelp end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/wasp/nest.rb', line 8 def @options end |
#queenwasp ⇒ Object (readonly)
Returns the value of attribute queenwasp.
11 12 13 |
# File 'lib/wasp/nest.rb', line 11 def queenwasp @queenwasp end |
#wasps ⇒ Object (readonly)
Returns the value of attribute wasps.
10 11 12 |
# File 'lib/wasp/nest.rb', line 10 def wasps @wasps end |
Class Method Details
.wakeup(args) ⇒ Object
316 317 318 |
# File 'lib/wasp/nest.rb', line 316 def self.wakeup(args) new(args).wakeup end |
Instance Method Details
#cleanup ⇒ Object
293 294 295 296 |
# File 'lib/wasp/nest.rb', line 293 def cleanup puts "Clean up.." exit(true) end |
#command_usage ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/wasp/nest.rb', line 101 def command_usage puts "Usage:".green + " wasps COMMAND [options]" <<-USAGE Wasps with Rain of Stings (ruby version of waspswithmachineguns) A utility for arming (creating) many wasps (small EC2 instances) to attack (load test) targets (web applications). commands: set Set credential file for AWS. up Start a batch of load testing servers. equip Check and install weapon to wasps. attack Begin the attack on a specific url. rattack Begin the attack incrementally growing up wasps during the period. down Shutdown and deactivate the load testing servers. status Report the status of the load testing servers. regions Get AWS regions for the wasps. help Show options. To set config file: $ wasp set aws.yml To launch 6 wasps: - launch 6 instances in us-east zone with private key named wasps $ wasp up -k wasps -s 6 - launch 5 instances in us-west-2 zone with ami-8cb33ebc AMI, username ubuntu and private key named wasps $ wasp up -k wasps -z us-west-2 -a ami-8cb33ebc -s 5 -l ubuntu To equip weapon(apachebench): $ wasp equip -w ab To attack target with 1000 requests and 100 concurrent wasps: $ wasp attack -n 1000 -c 100 -u http://target_site To attack target with incrementally increase wasps from 1 to 10000 during 60 seconds: $ wasp rattack -p 10000:60 -u http://target_site To sleep wasps: $ wasp down USAGE end |
#help(errcode = nil) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/wasp/nest.rb', line 272 def help (errcode = nil) case errcode when 'nokey' puts "[Error]".red + " : AWS private key is required.\n"; when 'nourl' puts "[Error]".red + " : Target url is required.\n"; when 'nofile' puts "[Error]".red + " : Config file not found.\n"; end puts command_usage if @optionhelp then @args = @args.unshift('--options') end exit(true) end |
#info ⇒ Object
14 15 16 |
# File 'lib/wasp/nest.rb', line 14 def info puts "be aware of me" end |
#lost_wasps ⇒ Object
147 148 149 150 |
# File 'lib/wasp/nest.rb', line 147 def lost_wasps File.exists?("#{ENV["HOME"]}/.nest") false end |
#parse_command! ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/wasp/nest.rb', line 152 def parse_command! verb = @args.shift case verb when 'set' file = @args.shift help('nofile') if file.nil? file = File.absolute_path(file) begin FileUtils.cp(file, ENV["HOME"] + "/.waspaws.yml") rescue => ex puts "#{ex.}" exit false end puts "AWS credential is set." when 'up' if lost_wasps then puts "[WARN]".yellow + " There are lost wasps in the air. They need to go home first. [./nest down]" exit(false) end if @options[:key].nil? then help("nokey") end puts 'Breeding wasps..' @wasps = WASP::Wasp.new(@options) @wasps.ready @wasps.breed #puts 'Breeding queen wasp..' #@queenwasp = WASP::QueenWasp.new(num_wasps) when 'equip' puts "Check wasps weapon.." @wasps = WASP::Wasp.new(@options) @wasps.equip when 'rattack' puts "Connecting to the nest" if @options[:url].nil? then help("nourl") end if @options[:pattern].nil? then @options[:pattern] = "5000:60" end pattern = @options[:pattern] to, time, keep = pattern.split(":") help if time.nil? or to.nil? if keep == 'keep' then keep = true else keep = false end @wasps = WASP::Wasp.new(@options) @wasps.rangeattack(to.to_i, time.to_i, @options[:url], keep) when 'attack' puts "Connecting to the nest" if @options[:url].nil? then help("nourl") end num = if @options[:num].nil? then WASP::Const::DEFAULT_NUMBER_OF_REQUESTS else @options[:num].to_i end time = @options[:time] # number of requests would be ignored if time parameter have given num = nil if not time.nil? conn = if @options[:conn].nil? then WASP::Const::DEFAULT_CONCURRENT_OF_CONNECTIONS else @options[:conn].to_i end @wasps = WASP::Wasp.new(@options) @wasps.attack(num, conn, @options[:url], time) when 'down' puts "Connecting to the nest." @wasps = WASP::Wasp.new(@options) @wasps.down when 'status' puts 'Report the wasp..' @wasps = WASP::Wasp.new(@options) @wasps.status when 'regions' puts 'Searching airfield..' @wasps = WASP::Wasp.new(@options) @wasps.airfield when 'help' @optionhelp = true help else help end end |
#parse_options! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wasp/nest.rb', line 18 def opts_parser = OptionParser.new do |opts| opts. = "\nAvailable options:\n\n" opts.on('-k', '--key PRIVATE-KEY', 'The ssh key pair name to use to connect to the new servers.') do |key| @options[:key] = key end opts.on('-s', '--servers NUM-SERVERS', 'The number of servers to start (default: 5).') do |server| @options[:server] = server end opts.on('-g', '--group SECURITY-GROUP', 'The security group to run the instances under (default: default).') do |group| @options[:group] = group end opts.on('-z', '--zone AVAILABILITY-ZONE', "The availability zone to start the instances in (default: us-east-1).") do |zone| @options[:zone] = zone end opts.on('-a', '--ami AMI', "The ami-id to use for each server from (default: ami-bfb473d6).") do |ami| @options[:ami] = ami end opts.on('-u', '--url URL', 'URL of the target to attack.') do |url| @options[:url] = url end opts.on('-p', '--pattern PATTERN', 'The pattern of concurrent wasps are growing and time (default: 5000(wasps):60(secs)).') do |pattern| @options[:pattern] = pattern end opts.on('-t', '--time TIME', 'The time to make to the target (seconds).') do |time| @options[:time] = time end opts.on('-i', '--cookie', 'The request doesn\'t include a cookie which have fake session id. (default: with sessionID).') do @options[:wo_cookie] = true end opts.on('-H', '--header HEADER', 'Append extra headers to the request. (i.e.: "Accep-Encoding: zip/zop;8bit").') do |header| @options[:header] = header end opts.on('-n', '--numreq NUM-REQUEST', 'The number of total connections to make to the target (default: 1000).') do |num| @options[:num] = num end opts.on('-c', '--concurrent CONCURRENT', 'The number of concurrent connections to make to the target (default: 100).') do |conn| @options[:conn] = conn end opts.on('-l', '--login LOGINID', 'The ssh username name to use to connect to the new servers (default: ubuntu).') do |login| @options[:login] = login end opts.on('-w', '--weapon WEAPON', 'The name of weapon to attack (default: ab).') do |weapon| @options[:weapon] = weapon end opts.on('-e', '--keepalive', 'Use keep-alive option for weapon.') do @options[:keepalive] = true end opts.on('-o', '--compact', 'Use compact version of results.') do @options[:compact] = true end opts.on('-v', '--version') { puts "wasp " + "#{WASP::Const::VERSION}\n".green; exit(true) } opts.on('-h', '--help') { @optionhelp = true; help } opts.on_tail('--options') { puts "#{opts}\n" } end begin @args = opts_parser.parse!(@args) rescue => ex print "[WARN]".yellow + " #{ex.}\n" @optionhelp = true help end self end |