Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling to get_policy in systemsmanager__rce_ec2 #420

Conversation

h00die
Copy link
Contributor

@h00die h00die commented May 17, 2024

Gracefully handle an access denied error when get_policy fails (AccessDenied), and give the user a suggestion on how to fix it. I left the original bubbled up error message in there as it gives additional context that could help a user debug, but felt the suggestion of manually setting an ip-name is a good tip (it got the module to run for me).

Pre

Pacu (example:example) > run systemsmanager__rce_ec2 --target-instances "i-11a11a1a111111a11" --command "whoami" --ip-name "arn:aws:iam::1111111111:example"
  Running module systemsmanager__rce_ec2...

[2024-05-17 17:26:06] Pacu encountered an error while running the previous command. Check /home/cb7192/.local/share/pacu/thomas/error_log.txt for technical details. [LOG LEVEL: MINIMAL]

    <class 'botocore.exceptions.ClientError'>: An error occurred (AccessDenied) when calling the GetPolicy operation: User: arn:aws:iam::999143725571:user/tomas_sysadmin is not authorized to perform: iam:GetPolicy on resource: policy arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM because no identity-based policy allows the iam:GetPolicy action

Post

Pacu (example:example) > run systemsmanager__rce_ec2 --target-instances "i-11a11a1a111111a11" --command "whoami" --ip-name "arn:aws:iam::1111111111:example"
  Running module systemsmanager__rce_ec2...

[systemsmanager__rce_ec2]   Unable to retrieve policy (arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM). Try specifying the ip-name manually. Error: An error occurred (AccessDenied) when calling the GetPolicy operation: User: arn:aws:iam::1111111111:example is not authorized to perform: iam:GetPolicy on resource: policy arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM because no identity-based policy allows the iam:GetPolicy action

Gracefully handle an access denied error when `get_policy` fails, and give the user a suggestion on how to fix it.
@DaveYesland DaveYesland merged commit 75370ef into RhinoSecurityLabs:master May 17, 2024
3 checks passed
@h00die h00die deleted the get_policy_patch_systemsmanager__rce_ec2 branch May 17, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants