Permalink
Browse files

add the ability to send headers with the url

  • Loading branch information...
1 parent ff7a31c commit 91a9627656212e0f5f168befec50de1df81ba959 @jamesbloomer jamesbloomer committed with cosmin Feb 25, 2013
Showing with 16 additions and 4 deletions.
  1. +12 −3 beeswithmachineguns/bees.py
  2. +4 −1 beeswithmachineguns/main.py
@@ -191,7 +191,11 @@ def _attack(params):
print 'Bee %i is firing his machine gun. Bang bang!' % params['i']
- stdin, stdout, stderr = client.exec_command('ab -r -n %(num_requests)s -c %(concurrent_requests)s -C "sessionid=NotARealSessionID" "%(url)s"' % params)
+ params['header_string'] = '';
+ for h in params['headers'].split(';'):
+ params['header_string'] += ' -H ' + h
+
+ stdin, stdout, stderr = client.exec_command('ab -r -n %(num_requests)s -c %(concurrent_requests)s -C "sessionid=NotARealSessionID" %(header_string)s "%(url)s"' % params)
response = {}
@@ -275,7 +279,7 @@ def _print_results(results):
else:
print 'Mission Assessment: Swarm annihilated target.'
-def attack(url, n, c):
+def attack(url, n, c, headers):
"""
Test the root url of this site.
"""
@@ -324,12 +328,17 @@ def attack(url, n, c):
'num_requests': requests_per_instance,
'username': username,
'key_name': key_name,
+ 'headers': headers,
})
print 'Stinging URL so it will be cached for the attack.'
# Ping url so it will be cached for testing
- urllib2.urlopen(url)
+ dict_headers = {}
+ if headers is not '':
+ dict_headers = headers = dict(h.split(':') for h in headers.split(';'))
+ request = urllib2.Request(url, headers=dict_headers)
+ urllib2.urlopen(request).read()
print 'Organizing the swarm.'
@@ -91,6 +91,9 @@ def parse_options():
attack_group.add_option('-c', '--concurrent', metavar="CONCURRENT", nargs=1,
action='store', dest='concurrent', type='int', default=100,
help="The number of concurrent connections to make to the target (default: 100).")
+ attack_group.add_option('-H', '--headers', metavar="HEADERS", nargs=1,
+ action='store', dest='headers', type='string', default='',
+ help="HTTP headers to send to the target to attack. Multiple headers should be separated by semi-colons, e.g header1:value1;header2:value2")
parser.add_option_group(attack_group)
@@ -120,7 +123,7 @@ def parse_options():
if not parsed.path:
parser.error('It appears your URL lacks a trailing slash, this will disorient the bees. Please try again with a trailing slash.')
- bees.attack(options.url, options.number, options.concurrent)
+ bees.attack(options.url, options.number, options.concurrent, options.headers)
elif command == 'down':
bees.down()
elif command == 'report':

0 comments on commit 91a9627

Please sign in to comment.