Skip to content

Commit 0d41160

Browse files
committed
Sanity checks, errors out with nil ptr if API call fails
1 parent a17d1a7 commit 0d41160

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modules/post/multi/escalate/aws_create_iam_user.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ def run
118118
action = 'CreateAccessKey'
119119
response = call_iam(creds, 'Action' => action, 'UserName' => username)
120120
doc = print_results(response, action)
121-
results['SecretAccessKey'] = doc['SecretAccessKey']
122-
results['AccessKeyId'] = doc['AccessKeyId']
121+
if doc
122+
results['SecretAccessKey'] = doc['SecretAccessKey']
123+
results['AccessKeyId'] = doc['AccessKeyId']
124+
end
123125
end
124126

125127
if datastore['CREATE_CONSOLE']
@@ -128,14 +130,15 @@ def run
128130
action = 'CreateLoginProfile'
129131
response = call_iam(creds, 'Action' => action, 'UserName' => username, 'Password' => password)
130132
doc = print_results(response, action)
131-
results['Password'] = password
133+
results['Password'] = password if doc
132134
end
133135

134136
action = 'GetUser'
135137
response = call_iam(creds, 'Action' => action, 'UserName' => username)
136138
doc = print_results(response, action)
139+
return if doc.nil?
137140
arn = doc['Arn']
138-
results['AccountId'] = arn[/^arn:aws:iam::(\d+):/,1]
141+
results['AccountId'] = arn[/^arn:aws:iam::(\d+):/, 1]
139142

140143
keys = results.keys
141144
table = Rex::Text::Table.new(

0 commit comments

Comments
 (0)