Skip to content

Commit a17d1a7

Browse files
committed
Added options for setting the PASSWORD and GROUPNAME
1 parent b9a7ed9 commit a17d1a7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

modules/post/multi/escalate/aws_create_iam_user.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def initialize(info = {})
3636
register_options(
3737
[
3838
OptString.new('IAM_USERNAME', [false, 'Name of the user to be created (leave empty or unset to use a random name)', '']),
39+
OptString.new('IAM_PASSWORD', [false, 'Password to set for the user to be created (leave empty or unset to use a random name)', '']),
40+
OptString.new('IAM_GROUPNAME', [false, 'Name of the group to be created (leave empty or unset to use a random name)', '']),
3941
OptBool.new('CREATE_API', [true, 'Add access key ID and secret access key to account (API, CLI, and SDK access)', true]),
4042
OptBool.new('CREATE_CONSOLE', [true, 'Create an account with a password for accessing the AWS management console', true]),
4143
OptString.new('AccessKeyId', [false, 'AWS access key', '']),
@@ -89,19 +91,18 @@ def run
8991
results['UserName'] = username
9092

9193
# create group
92-
groupname = username
94+
groupname = datastore['IAM_GROUPNAME'].blank? ? username : datastore['IAM_GROUPNAME']
9395
print_status("Creating group: #{groupname}")
9496
action = 'CreateGroup'
9597
doc = call_iam(creds, 'Action' => action, 'GroupName' => groupname)
9698
print_results(doc, action)
9799
results['GroupName'] = groupname
98100

99101
# create group policy
100-
policyname = username
101-
print_status("Creating group policy: #{policyname}")
102+
print_status("Creating group policy")
102103
pol_doc = datastore['IAM_GROUP_POL']
103104
action = 'PutGroupPolicy'
104-
doc = call_iam(creds, 'Action' => action, 'GroupName' => groupname, 'PolicyName' => policyname, 'PolicyDocument' => URI.encode(pol_doc))
105+
doc = call_iam(creds, 'Action' => action, 'GroupName' => groupname, 'PolicyName' => 'Policy', 'PolicyDocument' => URI.encode(pol_doc))
105106
print_results(doc, action)
106107

107108
# add user to group
@@ -123,7 +124,7 @@ def run
123124

124125
if datastore['CREATE_CONSOLE']
125126
print_status("Creating password for #{username}")
126-
password = username
127+
password = datastore['IAM_PASSWORD'].blank? ? Rex::Text.rand_text_alphanumeric(16) : datastore['IAM_PASSWORD']
127128
action = 'CreateLoginProfile'
128129
response = call_iam(creds, 'Action' => action, 'UserName' => username, 'Password' => password)
129130
doc = print_results(response, action)

0 commit comments

Comments
 (0)