Method: WASP::Wasp#_rangeattack

Defined in:
lib/wasp/wasp.rb

#_rangeattack(wasps, to, time, urls, keep = false) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/wasp/wasp.rb', line 321

def _rangeattack(wasps, to, time, urls, keep=false)
  count = time / WASP::Const::DEFAULT_WAVE_TIME
  awave = to / count
  wasp_count = wasps.count
  increase = awave / wasp_count
  
  coopwasps = []
  sum = increase
  
  count.times do 
    coopwasps.push(sum)
    sum += increase
  end
     
  print "Get communication channel for wasps..\n"
  threads = []
  wasps.each do |b|
    threads << Thread.new(b) { |wasp|
      begin
        wasp[:ssh] = Net::SSH.start(wasp[:instance_name], wasp[:login], 
                     :keys => ENV['HOME'] + '/.ssh/' + wasp[:key_name] + '.pem')
        print "Wasp " + "#{wasp[:instance_id]}".yellow + " is joining the wasp.\n"                       
      rescue => ex
        puts "[Error] ".red + "#{ex.message}"
        puts "Cannot reach to " + "#{wasp[:instance_id]}".yellow
      end
    }
  end      
  threads.each { |aThread| aThread.join }

  wave = 1
  if keep then
    per_wave = to
  else
    per_wave = awave
  end
  print "Total " + "#{count}".green + " waves(per *#{per_wave}/#{WASP::Const::DEFAULT_WAVE_TIME}secs) are coming..\n"
  while wave <= count do
    if keep then
      swarm = to
    else
      swarm = awave * wave
    end
    puts "#{wave}".yellow + " wave of swarm is coming (" + "#{swarm}".yellow + " wasps).."
    threads = []
    i = 0
    wasps.each do |b|
      url = urls[i%urls.count]
      i += 1
      #puts "Attack the target : #{url}"
      threads << Thread.new(b) { |wasp|
        begin                                    
        weapon = get_weapon
        if weapon.check(wasp[:ssh]) then     
          if keep then
            coop = to / wasp_count
          else
            coop = coopwasps[wave-1]
           end
            wasp[:wavereport] = weapon.wavefire(coop, url, wasp[:instance_id], wave, @keepalive, @without_cookie, @header)
          else
            puts "Wasp " + "#{wasp[:instance_id]}".yellow + " has no weapon."
          end
        rescue => ex
          print "[WARN]".yellow + " #{ex.message}.\n"
        end
      }
    end
    threads.each { |aThread| aThread.join }

    partial_report(wasps, wave)

    wave += 1
    if wave <= count then
      print "Waiting " + "#{WASP::Const::DEFAULT_COOLDOWN}".yellow + " seconds for cooling down\n"
      sleep WASP::Const::DEFAULT_COOLDOWN
    else
      cool = WASP::Const::DEFAULT_COOLDOWN / 5
      print "Waiting " + "#{cool}".yellow + " seconds for cooling down\n"
      sleep cool
    end
  end
  
  wasps.each do |wasp|
    begin
      wasp[:ssh].close
    rescue => ex
      puts "[WARN]".yellow + "#{ex.message}"
    end
  end
  
  return wasps, count
end