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