Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LIMIT and adjust code logic #3

Merged
merged 2 commits into from Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/auxiliary/cloud/aws/enum_ec2.rb
Expand Up @@ -86,7 +86,7 @@ def run
end
rescue Seahorse::Client::NetworkingError => e
print_error e.message
print_error "Confirm region name (eg. us-west-2) is valid or blank before retrying"
print_error 'Confirm region name (eg. us-west-2) is valid or blank before retrying'
rescue ::Exception => e
handle_aws_errors(e)
end
Expand Down
21 changes: 10 additions & 11 deletions modules/auxiliary/cloud/aws/enum_iam.rb
Expand Up @@ -23,7 +23,6 @@ def initialize(info = {})

register_options(
[
OptInt.new('LIMIT', [false, 'Only return the specified number of results']),
OptString.new('ACCESS_KEY_ID', [true, 'AWS Access Key ID (eg. "AKIAXXXXXXXXXXXXXXXX")', '']),
OptString.new('SECRET_ACCESS_KEY', [true, 'AWS Secret Access Key (eg. "CA1+XXXXXXXXXXXXXXXXXXXXXX6aYDHHCBuLuV79")', ''])
]
Expand Down Expand Up @@ -85,17 +84,17 @@ def describe_iam_users(i)
end

begin
console_login = @iam.get_login_profile(user_name: user).empty? ? "Disabled" : "Enabled"
console_login = @iam.get_login_profile(user_name: user).empty? ? 'Disabled' : 'Enabled'
print_good " Console login: #{console_login}"
rescue Aws::IAM::Errors::NoSuchEntity
print_good " Console login: []"
end

mfa = @iam.list_mfa_devices(user_name: i.user_name).mfa_devices
mfa_enabled = mfa.empty? ? "Disabled" : "Enabled on #{mfa[0].enable_date}"
mfa_enabled = mfa.empty? ? 'Disabled' : "Enabled on #{mfa[0].enable_date}"
print_good " Two-factor auth: #{mfa_enabled}"

print_good ""
print_status ''
end

def run
Expand All @@ -109,14 +108,14 @@ def run
creds = @iam.get_account_authorization_details

users = creds.user_detail_list
print_good "Found #{users.count} users."
if users.empty?
print_status 'No users found.'
return
end

unless users.empty?
users.each do |i|
describe_iam_users(i)
end
else
print_status "No users found."
print_good "Found #{users.count} users."
users.each do |i|
describe_iam_users(i)
end
rescue ::Exception => e
handle_aws_errors(e)
Expand Down
57 changes: 26 additions & 31 deletions modules/auxiliary/cloud/aws/enum_s3.rb
Expand Up @@ -23,7 +23,6 @@ def initialize(info = {})

register_options(
[
OptInt.new('LIMIT', [false, 'Only return the specified number of results']),
OptString.new('REGION', [false, 'AWS Region (eg. "us-west-2")']),
OptString.new('ACCESS_KEY_ID', [true, 'AWS Access Key ID (eg. "AKIAXXXXXXXXXXXXXXXX")', '']),
OptString.new('SECRET_ACCESS_KEY', [true, 'AWS Secret Access Key (eg. "CA1+XXXXXXXXXXXXXXXXXXXXXX6aYDHHCBuLuV79")', ''])
Expand Down Expand Up @@ -61,44 +60,40 @@ def describe_s3_bucket(i)
grantee << " (#{i.grantee.uri})" unless i.grantee.uri.nil?
print_good " #{grantee} granted #{i.permission}"
end
print_status ""
print_status ''
end

def run
begin
region = datastore['REGION']
region = datastore['REGION']

@s3 = Aws::S3::Client.new(
region: "us-west-2", # This doesn't actually filter anything, but
# it's still required. Thanks AWS. :-(
access_key_id: datastore['ACCESS_KEY_ID'],
secret_access_key: datastore['SECRET_ACCESS_KEY']
)
@s3 = Aws::S3::Client.new(
region: "us-west-2", # This doesn't actually filter anything, but
# it's still required. Thanks AWS. :-(
access_key_id: datastore['ACCESS_KEY_ID'],
secret_access_key: datastore['SECRET_ACCESS_KEY']
)

buckets = @s3.list_buckets.buckets
print_good "Found #{buckets.count} buckets."
buckets = @s3.list_buckets.buckets
unless bucket.length > 0
print_status 'No buckets found.'
return
end

if buckets.length > 0
if region.nil?
buckets.each do |i|
describe_s3_bucket(i)
end
print_good "Done."
else
print_good "Listing buckets that match REGION '#{datastore['REGION']}':"
buckets.each do |i|
if @s3.get_bucket_location(bucket: i.name).location_constraint.starts_with? region
describe_s3_bucket(i)
end
print_good "Done."
end
print_good "Found #{buckets.count} buckets."
if region.nil?
buckets.each do |i|
describe_s3_bucket(i)
end
else
print_good "Listing buckets that match REGION '#{datastore['REGION']}':"
buckets.each do |i|
if @s3.get_bucket_location(bucket: i.name).location_constraint.starts_with? region
describe_s3_bucket(i)
end
else
print_status "No buckets found."
end
rescue ::Exception => e
handle_aws_errors(e)
end
print_status 'Done.'
rescue ::Exception => e
handle_aws_errors(e)
end
end