Permalink
Browse files

Merge pull request #18 from gamespy-tech/develop

Adding the ability to POST via an uploaded post document.
  • Loading branch information...
1 parent 1c93f61 commit 6cab5399fbc93aae072bf951722f134036bf6800 @cosmin cosmin committed Apr 13, 2013
Showing with 27 additions and 9 deletions.
  1. +13 −6 beeswithmachineguns/bees.py
  2. +14 −3 beeswithmachineguns/main.py
@@ -191,12 +191,17 @@ def _attack(params):
print 'Bee %i is firing his machine gun. Bang bang!' % params['i']
- params['header_string'] = '';
+ options = ''
if params['headers'] is not '':
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)
+ options += ' -H ' + h
+
+ if params['post_file']:
+ os.system("scp -q -o 'StrictHostKeyChecking=no' %s %s@%s:/tmp/honeycomb" % (params['post_file'], params['username'], params['instance_name']))
+ options += ' -k -T "%(mime_type)s; charset=UTF-8" -p /tmp/honeycomb' % params
+
+ benchmark_command = 'ab -r -n %(num_requests)s -c %(concurrent_requests)s -C "sessionid=NotARealSessionID" %(options) "%(url)s"' % params
+ stdin, stdout, stderr = client.exec_command(benchmark_command)
response = {}
@@ -280,7 +285,7 @@ def _print_results(results):
else:
print 'Mission Assessment: Swarm annihilated target.'
-def attack(url, n, c, headers):
+def attack(url, n, c, **options):
"""
Test the root url of this site.
"""
@@ -329,7 +334,9 @@ def attack(url, n, c, headers):
'num_requests': requests_per_instance,
'username': username,
'key_name': key_name,
- 'headers': headers,
+ 'headers': options.get('headers', ''),
+ 'post_file': options.get('post_file'),
+ 'mime_type': options.get('mime_type', ''),
})
print 'Stinging URL so it will be cached for the attack.'
@@ -77,14 +77,19 @@ def parse_options():
parser.add_option_group(up_group)
- attack_group = OptionGroup(parser, "attack",
+ attack_group = OptionGroup(parser, "attack",
"""Beginning an attack requires only that you specify the -u option with the URL you wish to target.""")
# Required
attack_group.add_option('-u', '--url', metavar="URL", nargs=1,
action='store', dest='url', type='string',
help="URL of the target to attack.")
-
+ attack_group.add_option('-p', '--post-file', metavar="POST_FILE", nargs=1,
+ action='store', dest='post_file', type='string', default=False,
+ help="The POST file to deliver with the bee's payload.")
+ attack_group.add_option('-m', '--mime-type', metavar="MIME_TYPE", nargs=1,
+ action='store', dest='mime_type', type='string', default='text/plain',
+ help="The MIME type to send with the request.")
attack_group.add_option('-n', '--number', metavar="NUMBER", nargs=1,
action='store', dest='number', type='int', default=1000,
help="The number of total connections to make to the target (default: 1000).")
@@ -123,7 +128,13 @@ 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, options.headers)
+ additional_options = dict(
+ headers=options.headers,
+ post_file=options.post_file,
+ mime_type=options.mime_type,
+ )
+
+ bees.attack(options.url, options.number, options.concurrent, **additional_options)
elif command == 'down':
bees.down()
elif command == 'report':

0 comments on commit 6cab539

Please sign in to comment.