コード例 #1
0
def test_listBucket():
    """
    Scenario listBucket.1 - Public read enabled
        Expected: Listing bucket flaws.cloud will create the directory, create flaws.cloud.txt, and write the listing to file
    Scenario listBucket.2 - Public read disabled

    """
    test_setup()

    # listBucket.1

    listFile = './list-buckets/flaws.cloud.txt'

    s3.listBucket('flaws.cloud')

    assert os.path.exists(
        listFile)  # Assert file was created in the correct location

    lines = []
    with open(listFile, 'r') as g:
        for line in g:
            lines.append(line)

    assert lines[0][
        26:41] == '2575 hint1.html'  # Assert the first line is correct
    assert len(lines) == 7  # Assert number of lines in the file is correct

    # listBucket.2
    assert s3.listBucket('app-dev') == "AccessDenied"
コード例 #2
0
def test_listBucket():
    """
    Scenario listBucket.1 - Public read enabled
        Expected: Listing bucket flaws.cloud will create the directory, create flaws.cloud.txt, and write the listing to file
    Scenario listBucket.2 - Public read disabled

    """
    test_setup()

    # listBucket.1

    listFile = './list-buckets/s3scanner-bucketsize.txt'

    s3.listBucket('s3scanner-bucketsize')

    assert os.path.exists(
        listFile)  # Assert file was created in the correct location

    lines = []
    with open(listFile, 'r') as g:
        for line in g:
            lines.append(line)

    assert lines[0].rstrip().endswith(
        'test-file.txt')  # Assert the first line is correct
    assert len(lines) == 1  # Assert number of lines in the file is correct

    # listBucket.2
    assert s3.listBucket('s3scanner-private') == "AccessDenied"
コード例 #3
0
def test_listBucket():
    """
    Verify that listBucket() function: creates the directory, creates the list file, writes to file correctly

    Expected:
        Listing bucket flaws.cloud will create the directory, create flaws.cloud.txt, and write the listing to file
    """
    test_setup()

    listFile = './list-buckets/flaws.cloud.txt'

    s3.listBucket('flaws.cloud', 'us-west-2')

    assert os.path.exists(
        listFile)  # Assert file was created in the correct location

    lines = []
    with open(listFile, 'r') as g:
        for line in g:
            lines.append(line)

    assert lines[0][
        26:41] == '2575 hint1.html'  # Assert the first line is correct
    assert len(lines) == 6  # Assert number of lines in the file is correct
コード例 #4
0
        result = s3.checkBucket(bucket, region)

        if result[0] == 301:
            result = s3.checkBucket(bucket, result[1])

        if result[0] in [900, 404]:     # These are our 'bucket not found' codes
            slog.error(result[1])

        elif result[0] == 403:          # Found but closed bucket. Only log if user says to.
            message = "{0:>15} : {1}".format("[found] [closed]", result[1] + ":" + result[2])
            slog.warning(message)
            if args.includeClosed:      # If user supplied '--include-closed' flag, log this bucket to file
                flog.debug(result[1] + ":" + result[2])

        elif result[0] == 200:          # The only 'bucket found and open' codes
            message = "{0:<7}{1:>9} : {2}".format("[found]", "[open]", result[1] + ":" + result[2] + " - " + result[3])
            slog.info(message)
            flog.debug(result[1] + ":" + result[2])
            if args.dump:
                s3.dumpBucket(bucket, result[2])
            if args.list:
                s3.listBucket(bucket, result[2])

        elif result[0] == 999:
            message = "{0:>16} : {1}".format("[invalid]", result[1])
            slog.error(message)

        else:
            raise ValueError("Got back unknown code from checkBucket(): " + str(result[0]))
コード例 #5
0
ファイル: s3scanner.py プロジェクト: sanelez/S3Scanner
        if not valid:
            message = "{0:>11} : {1}".format("[invalid]", bucket)
            slog.error(message)
            continue

        if s3.awsCredsConfigured:
            b = s3.checkAcl(bucket)
        else:
            a = s3.checkBucketWithoutCreds(bucket)
            b = {"found": a, "acls": "unknown - no aws creds"}

        if b["found"]:

            size = s3.getBucketSize(
                bucket)  # Try to get the size of the bucket

            message = "{0:>11} : {1}".format(
                "[found]",
                bucket + " | " + size + " | ACLs: " + str(b["acls"]))
            slog.info(message)
            flog.debug(bucket)

            if args.dump:
                s3.dumpBucket(bucket)
            if args.list:
                if str(b["acls"]) not in ["AccessDenied", "AllAccessDisabled"]:
                    s3.listBucket(bucket)
        else:
            message = "{0:>11} : {1}".format("[not found]", bucket)
            slog.error(message)