Land #10394, Cleanup aws_ec2_instance_metadata

GSoC/Meterpreter_Web_Console
Adam Cammack 2018-08-15 14:51:12 -05:00
commit 79736406b2
No known key found for this signature in database
GPG Key ID: C9378BA088092D66
1 changed files with 6 additions and 5 deletions

View File

@ -36,7 +36,7 @@ class MetasploitModule < Msf::Post
def check_aws_metadata
resp = simple_get(@target_uri)
unless resp =~ /^instance-id.$/m
unless resp =~ /^instance-id$/
fail_with(Failure::BadConfig, "Session does not appear to be on an AWS EC2 instance")
end
resp
@ -50,14 +50,15 @@ class MetasploitModule < Msf::Post
def get_aws_metadata(base_uri, base_resp)
r = {}
base_resp.split(/\r\n/).each do |l|
new_uri = base_uri.merge("./#{l}")
base_resp.split(/\r?\n/).each do |l|
new_uri = "#{base_uri}#{l}"
if l =~ %r{/$}
# handle a directory
r[l.gsub(%r{/$}, '')] = get_aws_metadata(new_uri, simple_get(new_uri))
elsif new_uri.to_s =~ %r{/public-keys/} && /^(?<key_id>\d+)=/ =~ l
# special case handling of the public-keys endpoint
key_uri = new_uri.merge("./#{key_id}/")
new_uri = new_uri.slice(0..(new_uri.index(%r{/public-keys/})+'/public-keys'.length))
key_uri = "#{new_uri}#{key_id}/"
key_resp = simple_get(key_uri)
r[key_id] = get_aws_metadata(key_uri, key_resp)
else
@ -94,6 +95,6 @@ class MetasploitModule < Msf::Post
def simple_get(url)
vprint_status("Fetching #{url}")
cmd_exec("curl #{url}")
cmd_exec("curl -s #{url}")
end
end