Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/cloud/aws/enum_s3.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'aws-sdk-s3'67class MetasploitModule < Msf::Auxiliary8def initialize(info = {})9super(10update_info(11info,12'Name' => 'Amazon Web Services S3 instance enumeration',13'Description' => %q(14Provided AWS credentials, this module will call the authenticated15API of Amazon Web Services to list all S3 buckets associated16with the account17),18'Author' => ['Aaron Soto <[email protected]>'],19'License' => MSF_LICENSE20)21)2223register_options(24[25OptString.new('REGION', [false, 'AWS Region (eg. "us-west-2")']),26OptString.new('ACCESS_KEY_ID', [true, 'AWS Access Key ID (eg. "AKIAXXXXXXXXXXXXXXXX")', '']),27OptString.new('SECRET_ACCESS_KEY', [true, 'AWS Secret Access Key (eg. "CA1+XXXXXXXXXXXXXXXXXXXXXX6aYDHHCBuLuV79")', ''])28]29)30end3132def handle_aws_errors(e)33if e.class.module_parents.include?(Aws)34fail_with(Failure::UnexpectedReply, e.message)35else36raise e37end38end3940def describe_s3_bucket(i)41print_good " Name: #{i.name}"42print_good " Creation Date: #{i.creation_date}"43print_good " # of Objects: #{@s3.list_objects_v2(bucket: i.name).contents.length}"44print_good " Region: #{@s3.get_bucket_location(bucket: i.name).location_constraint}"4546begin47print_good " Website: /#{@s3.get_bucket_website(bucket: i.name).index_document.suffix}"48rescue Aws::S3::Errors::NoSuchWebsiteConfiguration49print_good " Website: (None)"50end5152acl = @s3.get_bucket_acl(bucket: i.name)53print_good " Owner: #{acl.owner.display_name}"54print_good " Permissions:"55acl.grants.each do |i|56grantee = i.grantee.type == "CanonicalUser" ? "User" : i.grantee.type57grantee << " '#{i.grantee.display_name}'"58grantee << " (#{i.grantee.email_address})" unless i.grantee.email_address.nil?59grantee << " (#{i.grantee.uri})" unless i.grantee.uri.nil?60print_good " #{grantee} granted #{i.permission}"61end62print_status ''63end6465def run66region = datastore['REGION']6768@s3 = Aws::S3::Client.new(69region: "us-west-2", # This doesn't actually filter anything, but70# it's still required. Thanks AWS. :-(71access_key_id: datastore['ACCESS_KEY_ID'],72secret_access_key: datastore['SECRET_ACCESS_KEY']73)7475buckets = @s3.list_buckets.buckets76unless buckets.length > 077print_status 'No buckets found.'78return79end8081print_good "Found #{buckets.count} buckets."82if region.nil?83buckets.each do |i|84describe_s3_bucket(i)85end86else87print_good "Listing buckets that match REGION '#{datastore['REGION']}':"88buckets.each do |i|89if @s3.get_bucket_location(bucket: i.name).location_constraint.starts_with? region90describe_s3_bucket(i)91end92end93end94print_status 'Done.'95rescue ::Exception => e96handle_aws_errors(e)97end98end99100101