start:
set:
garbage:
- - {random 10-3000 printable}
- - {random 10-1000 binary}
+ - '{random 10-3000 printable}'
+ - '{random 10-1000 binary}'
choices:
- bucket
bucket:
set:
- urlpath: /{bucket}
+ urlpath: '/{bucket}'
choices:
- 13 bucket_get
- 8 bucket_put
garbage_method:
set:
method:
- - {random 1-100 printable}
- - {random 10-100 binary}
+ - '{random 1-100 printable}'
+ - '{random 10-100 binary}'
urlpath:
- - /{bucket}
- - /{bucket}/{object}
- - {random 10-1000 binary}
+ - '/{bucket}'
+ - '/{bucket}/{object}'
+ - '{random 10-1000 binary}'
choices:
- bucket_get_simple
- bucket_get_filtered
set:
method: DELETE
bucket:
- - {bucket_writable}
- - {bucket_not_writable}
- - 2 {garbage}
+ - '{bucket_writable}'
+ - '{bucket_not_writable}'
+ - '2 {garbage}'
query:
- null
- policy
- website
- - 2 {garbage}
+ - '2 {garbage}'
choices: []
bucket_get:
set:
method: GET
bucket:
- - {bucket_readable}
- - {bucket_not_readable}
- - 2 {garbage}
+ - '{bucket_readable}'
+ - '{bucket_not_readable}'
+ - '2 {garbage}'
choices:
- 11 bucket_get_simple
- bucket_get_filtered
- requestPayment
- versioning
- website
- - 2 {garbage}
+ - '2 {garbage}'
choices: []
bucket_get_uploads:
set:
delimiter:
- null
- - 3 'delimiter={garbage}'
+ - '3 delimiter={garbage}'
prefix:
- null
- - 3 'prefix={garbage}'
+ - '3 prefix={garbage}'
key_marker:
- null
- 'key-marker={object_readable}'
- 'max-uploads={random 1-1000 digits}'
upload_id_marker:
- null
- - 3 'upload-id-marker={random}'
+ - '3 upload-id-marker={random}'
query:
- 'uploads'
- 'uploads&{delimiter}&{prefix}'
- 'uploads&{max_uploads}&{key_marker}&{upload_id_marker}'
- - 2 {garbage}
+ - '2 {garbage}'
choices: []
bucket_get_filtered:
- null
- '{delimiter}&{prefix}'
- '{max-keys}&{marker}'
- - 2 {garbage}
+ - '2 {garbage}'
choices: []
bucket_put:
set:
bucket:
- - {bucket_writable}
- - {bucket_not_writable}
- - 2 {garbage}
+ - '{bucket_writable}'
+ - '{bucket_not_writable}'
+ - '2 {garbage}'
method: PUT
choices:
- bucket_put_simple
bucket_put_create:
set:
body:
- - 2 {garbage}
+ - '2 {garbage}'
- '<CreateBucketConfiguration><LocationConstraint>{random 2-10 binary}</LocationConstraint></CreateBucketConfiguration>'
acl:
- private
- - {random 3000 letters}
- - {random 100-1000 binary}
+ - '{random 3000 letters}'
+ - '{random 100-1000 binary}'
headers:
- ['0-1', 'x-amz-acl', '{acl}']
choices: []
bucket_put_versioning:
set:
body:
- - {garbage}
- - 4 '<VersioningConfiguration>{versioning_status}{mfa_delete_body}</VersioningConfiguration>'
+ - '{garbage}'
+ - '4 <VersioningConfiguration>{versioning_status}{mfa_delete_body}</VersioningConfiguration>'
mfa_delete_body:
- null
- '<Status>{random 2-10 binary}</Status>'
bucket_put_simple:
set:
body:
- - {acl_body}
- - {policy_body}
- - {logging_body}
- - {notification_body}
- - {request_payment_body}
- - {website_body}
+ - '{acl_body}'
+ - '{policy_body}'
+ - '{logging_body}'
+ - '{notification_body}'
+ - '{request_payment_body}'
+ - '{website_body}'
acl_body:
- null
- '<AccessControlPolicy>{owner}{acl}</AccessControlPolicy>'
owner:
- null
- - 7 '<Owner>{id}{display_name}</Owner>'
+ - '7 <Owner>{id}{display_name}</Owner>'
id:
- null
- '<ID>{random 10-200 binary}</ID>'
- '<ID>{random 1000-3000 printable}</ID>'
display_name:
- null
- - 2 '<DisplayName>{random 10-200 binary}</DisplayName>'
- - 2 '<DisplayName>{random 1000-3000 printable}</DisplayName>'
- - 2 '<DisplayName>{random 10-300 letters}@{random 10-300 letters}.{random 2-4 letters}</DisplayName>'
+ - '2 <DisplayName>{random 10-200 binary}</DisplayName>'
+ - '2 <DisplayName>{random 1000-3000 printable}</DisplayName>'
+ - '2 <DisplayName>{random 10-300 letters}@{random 10-300 letters}.{random 2-4 letters}</DisplayName>'
acl:
- null
- - 10 '<AccessControlList><Grant>{grantee}{permission}</Grant></AccessControlList>'
+ - '10 <AccessControlList><Grant>{grantee}{permission}</Grant></AccessControlList>'
grantee:
- null
- - 7 '<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">{id}{display_name}</Grantee>'
+ - '7 <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">{id}{display_name}</Grantee>'
permission:
- null
- - 7 '<Permission>{permission_value}</Permission>'
+ - '7 <Permission>{permission_value}</Permission>'
permission_value:
- - 2 {garbage}
+ - '2 {garbage}'
- FULL_CONTROL
- WRITE
- WRITE_ACP
- READ_ACP
policy_body:
- null
- - 2 {garbage}
+ - '2 {garbage}'
logging_body:
- null
- '<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" />'
- '<TargetPrefix>{random 10-1000 binary}</TargetPrefix>'
target_grants:
- null
- - 10 '<TargetGrants><Grant>{grantee}{permission}</Grant></TargetGrants>'
+ - '10 <TargetGrants><Grant>{grantee}{permission}</Grant></TargetGrants>'
notification_body:
- null
- '<NotificationConfiguration />'
- - 2 '<NotificationConfiguration><TopicConfiguration>{topic}{event}</TopicConfiguration}</NotificationConfiguration>'
+ - '2 <NotificationConfiguration><TopicConfiguration>{topic}{event}</TopicConfiguration}</NotificationConfiguration>'
topic:
- null
- - 2 '<Topic>{garbage}</Topic>'
+ - '2 <Topic>{garbage}</Topic>'
event:
- null
- '<Event>s3:ReducedRedundancyLostObject</Event>'
- - 2 '<Event>{garbage}</Event>'
+ - '2 <Event>{garbage}</Event>'
request_payment_body:
- null
- '<RequestPaymentConfiguration xlmns="http://s3.amazonaws.com/doc/2006-03-01/"><Payer>{payer}</Payer></RequestPaymentConfiguration>'
payer:
- Requester
- BucketOwner
- - 2 {garbage}
+ - '2 {garbage}'
website_body:
- null
- '<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><IndexDocument><Suffix>{suffix}</Suffix><IndexDocument>{error_doc}<WebsiteConfiguration/>'
suffix:
- null
- - 2 {garbage}
+ - '2 {garbage}'
- '{random 2-10 printable}.html'
error_doc:
- null
from boto.s3.connection import S3Connection
+from boto.s3.key import Key
from optparse import OptionParser
from boto import UserAgent
from . import common
continue
try:
(weight, value) = option.split(None, 1)
+ weight = int(weight)
except ValueError:
- weight = '1'
+ weight = 1
value = option
- weight = int(weight)
if value == 'null' or value == 'None':
value = ''
def expand_headers(decision, prng):
- expanded_headers = []
+ expanded_headers = {}
for header in decision['headers']:
h = expand(decision, header[0], prng)
v = expand(decision, header[1], prng)
- expanded_headers.append([h, v])
+ expanded_headers[h] = v
return expanded_headers
parser.add_option('--seed', dest='seed', type='int', help='initial seed for the random number generator', metavar='SEED')
parser.add_option('--seed-file', dest='seedfile', help='read seeds for specific requests from FILE', metavar='FILE')
parser.add_option('-n', dest='num_requests', type='int', help='issue NUM requests before stopping', metavar='NUM')
+ parser.add_option('-v', '--verbose', dest='verbose', action="store_true", help='turn on verbose output')
+ parser.add_option('-d', '--debug', dest='debug', action="store_true", help='turn on debugging (very verbose) output')
parser.add_option('--decision-graph', dest='graph_filename', help='file in which to find the request decision graph', metavar='NUM')
parser.set_defaults(num_requests=5)
yield rng.random()
+def populate_buckets(conn, alt):
+ """ Creates buckets and keys for fuzz testing and sets appropriate
+ permissions. Returns a dictionary of the bucket and key names.
+ """
+ breadable = common.get_new_bucket(alt)
+ bwritable = common.get_new_bucket(alt)
+ bnonreadable = common.get_new_bucket(alt)
+
+ oreadable = Key(breadable)
+ owritable = Key(bwritable)
+ ononreadable = Key(breadable)
+ oreadable.set_contents_from_string('oreadable body')
+ owritable.set_contents_from_string('owritable body')
+ ononreadable.set_contents_from_string('ononreadable body')
+
+ breadable.set_acl('public-read')
+ bwritable.set_acl('public-read-write')
+ bnonreadable.set_acl('private')
+ oreadable.set_acl('public-read')
+ owritable.set_acl('public-read-write')
+ ononreadable.set_acl('private')
+
+ return dict(
+ bucket_readable=breadable.name,
+ bucket_writable=bwritable.name,
+ bucket_not_readable=bnonreadable.name,
+ bucket_not_writable=breadable.name,
+ object_readable=oreadable.key,
+ object_writable=owritable.key,
+ object_not_readable=ononreadable.key,
+ object_not_writable=oreadable.key,
+ )
+
+
def _main():
""" The main script
"""
(options, args) = parse_options()
random.seed(options.seed if options.seed else None)
s3_connection = common.s3.main
+ alt_connection = common.s3.alt
+
+ if options.outfile:
+ OUT = open(options.outfile, 'w')
+ else:
+ OUT = sys.stderr
+
+ VERBOSE = DEBUG = open('/dev/null', 'w')
+ if options.verbose:
+ VERBOSE = OUT
+ if options.debug:
+ DEBUG = OUT
+ VERBOSE = OUT
request_seeds = None
if options.seedfile:
FH = open(options.seedfile, 'r')
- request_seeds = FH.readlines()
+ request_seeds = [float(line) for line in FH.readlines()]
+ print>>OUT, 'Seedfile: %s' %options.seedfile
+ print>>OUT, 'Number of requests: %d' %len(request_seeds)
else:
+ if options.seed:
+ print>>OUT, 'Initial Seed: %d' %options.seed
+ print>>OUT, 'Number of requests: %d' %options.num_requests
random_list = randomlist(options.seed)
request_seeds = itertools.islice(random_list, options.num_requests)
+ print>>OUT, 'Decision Graph: %s' %options.graph_filename
graph_file = open(options.graph_filename, 'r')
decision_graph = yaml.safe_load(graph_file)
- constants = dict(
- bucket_readable='TODO-breadable',
- bucket_not_readable='TODO-bnonreadable',
- bucket_writable='TODO-bwritable',
- bucket_not_writable='TODO-bnonwritable',
- object_readable='TODO-oreadable',
- object_not_readable='TODO-ononreadable',
- object_writable='TODO-owritable',
- object_not_writable='TODO-ononwritable',
- )
+ constants = populate_buckets(s3_connection, alt_connection)
+ print>>VERBOSE, "Test Buckets/Objects:"
+ for key, value in constants.iteritems():
+ print>>VERBOSE, "\t%s: %s" %(key, value)
+ print>>OUT, "Begin Fuzzing..."
+ print>>VERBOSE, '='*80
for request_seed in request_seeds:
+ print>>OUT, request_seed
+
prng = random.Random(request_seed)
decision = assemble_decision(decision_graph, prng)
decision.update(constants)
method = expand(decision, decision['method'], prng)
- path = expand(decision, decision['path'], prng)
- body = expand(decision, decision['body'], prng)
- headers = expand_headers(decision, prng)
+ path = expand(decision, decision['urlpath'], prng)
- print "Method: %s" % method
- print "Path: %s" % path
- print "Headers: %s" % headers
- print ""
- print "Body: %s" % body
- #response = s3_connection.make_request(method, path, data=body, headers=headers, override_num_retries=0)
+ try:
+ body = expand(decision, decision['body'], prng)
+ except KeyError:
+ body = ''
+ try:
+ headers = expand_headers(decision, prng)
+ except KeyError:
+ headers = {}
+
+ response = s3_connection.make_request(method, path, data=body, headers=headers, override_num_retries=0)
+
+ print>>VERBOSE, "%s %s" %(method[:100], path[:100])
+ for h, v in headers.iteritems():
+ print>>VERBOSE, "%s: %s" %(h[:50], v[:50])
+ print>>VERBOSE, "%s\n" % body[:100]
+
+ print>>DEBUG, 'FULL REQUEST'
+ print>>DEBUG, 'Method: %r' %method
+ print>>DEBUG, 'Path: %r' %path
+ print>>DEBUG, 'Headers:'
+ for h, v in headers.iteritems():
+ print>>DEBUG, "\t%r: %r" %(h, v)
+ print>>DEBUG, 'Body: %r' %body
+
+ print>>VERBOSE, 'Response status code: %d %s' %(response.status, response.reason)
+ print>>DEBUG, 'Body:\n%s' %response.read()
if response.status == 500 or response.status == 503:
- print 'Request generated with seed %d failed:\n%s' % (request_seed, request)
- pass
+ print>>OUT, 'FAILED:\n%s' %request
+ print>>VERBOSE, '='*80
+ print>>OUT, '...done fuzzing'
+ common.teardown()
def main():