# Level 4: Unencrypted Snapshots

### <mark style="color:purple;">Task</mark>

For the next level, you need to get access to the web page running on an EC2 at [4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud](http://4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud/)

It'll be useful to know that a snapshot was made of that EC2 shortly after nginx was setup on it.

### <mark style="color:purple;">Resolution</mark>

1. **Listing EC2 Snapshots:**

For this level, we need to list the EC2 snapshots.

First, we need to identify our user's account (from the previous level):

```bash
aws --profile default sts get-caller-identity
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdsWGkyUYbKijpB9xuyPQW-MzqD4vk-j7vcxvEXziPVj3KhiCEzBN9plAQbooVFsuJhECYOT__YoOXW8VEK6jf1N0gu8skL7WtHfIRphvVtnYJeC0EjAKm0qTAkuoLRYjxiA7nrPQ?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

Now, we list the snapshots:

```
aws --profile default ec2 describe-snapshots --owner-id <Account>
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfF_EoH5aQrz53hd6smWWZszdQfdP-jCAqTwLBrCIfWmD_0kMhz8gtb2pCjKMJdPtJ8oWDPaU8FZ3aCRno0T7RnXxWNInzWAQ_fQ-KUlPLcayZXMm42ToNDRg7O2MVFUKdKiskTeQ?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

2. **Creating a Volume:**

Once we have the snapshot listed, we can create a volume.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfd8n3I2SVG5rRAZEHkMwi4vOB5qqSs2iAIlAblECgyJi6cdkSy5CCFuhbH_gLdOBQtTTtvnL5D-tyFZHuAlG-D0bqnn2Uus8smr1X7D3oaGJt_-haJ4yqoq4wYFXt8Lq9JY_6_?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

However, with the user from the previous level, we don't have the necessary permissions. To fix this, we need to go back to **IAM** and add permissions. Since we don't have access to the previous user, we'll add the permissions to our own user and update our AWS configuration.

In the user's permissions, we need to create a new policy.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdQYQdUbY_1RXsrH_NLEfzkppaGLS9LjVXz9ayqwlk8Bou5MwPHLJeWwfFGbxzY4yZLYXpEOgE66AIg51h0aDAfoj0sQH1Jo84_acdPNqn6e7CPN-NVcKl6rwUKpLzArSPYNumyBw?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf-uBGG6-0Z3HseRgP8gTMVlBrPUesiQL5vhHKzr0oZNjH0ipPc07SDENbJkb7DdiXPRJZNowK5C_wbMz3pPhwBteO5vETSEoxF_Ekd_t_ZmR-nTKnrLUsjfxwKTRXm9fTnT_UUDw?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

3. **Creating the Volume:**

Now, we try creating the volume again.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcjUYggSFBmCttJ5ZganGLPli3Ws8QZX7tKRQQG7iqy2Iw2RfDTmZxxhlGjP-C8VWvVEnXepINPd9GZai-OR6WMCda_NMuc76V9aqaEC2Z6a0F9xSHh3pQ-W33-BYvt6daLfVxrww?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

**Perfect!**

4. **Launching an EC2 Instance:**

The next step is to create an EC2 instance. In the AWS console, search for **EC2**.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeZfP5XjZ4ldmlZSTYefCQ_AUxPcg18KG74MHL3ECt08q_-g0y781rZt4w_Ho3B87O9gDzVJ6yTKrkoXMJA4XV3gBOi8LahwbSIxfL-h8F6ps8IfSET2Yn-Kg7nIR803egQrxC0?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

Click on **Launch Instance**.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeK64Gd0DSMNBZlb2E9muYMHGlCrPNGiF8473BzReSzIqWT3V0mTE1KpAU53uiqLUmX3enSHB99yTQj4-OM51KuZI7S8zdVSGDEgWtj4vAH4tgHHOeA5fiqdzfXD4GFCh08G5d4?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdN1Mz221viu4DLewozT0lpJxGX5zxJ9oqDGfodgHzF0odi8xSSFpj5iOExRYQ2VzsYHofwQwKy45lOoGLZTmU_-3fzkERWp5BWges1PpenwaY5EFM_E6X827sIQFpmKIngKOTPvg?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

5. **Creating a Key Pair:**

Create a new key pair.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXctWhgtD4hamXmskBCeSARFbkOJFSEPTHC6HcxwawXzXrarqk3ospHJeynN-Tk82kXumehDp-3ZWfSYj4GmdGGKCHiylpH9Hg_rEXNBNQDs5ZVZKR4Wa-58xy4KFQO06WLLEUtYoA?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfsFZkS4Y8mmvru2_vh6pbzq96bjGeoD_IzC2hQM7V8YrAEyEXsBx6fvxknCB3j4j5IUxws8Y9_CTIK9CGtLTbNmD0LsmqSt_s3qYKf9sBgmRUat9IBIVcQND7e4oiDgPjbynt3Qg?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXewhfDud_hWLukVC2_515fl1c-6V7iKlZWQbaRKCJM13T4L64Afluu4Zr5Izi5xNMhQ4cB2XZ5WJeVr2lhWanP3D7_3YPV17aZWEM5gygoDx4UcMw_rBb5oowoH1XKvcNMXVsFRRg?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

6. **Attaching the Volume to the EC2 Instance:**

First, we connect to our EC2 instance via SSH:

```
ssh -i YOUR_KEY.pem ubuntu@<EC2_PublicIPv4DNS>
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf6S3dL_bW_fG6WhTSO04159ZSqvSzXBFyWWby_xccDsUtfA7PTjf8giaS97XAD4EDxIOhKfCv0I90reXWm44TgeaRIs4uG1MQ7-GkuztnjfiWDN61cb3G3KEMPrGKiw9Bl6AP_?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

Now, we mount the volume.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfoBE0yKLkGgoyKmqRpkYAP2clxKXMh9qd-Knb22Lvn4xNIPY4ye332y-IbFccIU85ByJao_ZbDuoM349r4748aoDKrIkmqPsjWsTVFvLspwz-RWuWIKXt3LbcjEmKuml5nHEFn?key=yZvDq_-uDN4B0M8iByv7S1s4)

While exploring, we find a file called **setupNginx.sh** located in **/mnt/home/ubuntu**. We use **cat** to view its contents:

```
cat setupNginx.sh
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdr8XimoWNDCx-X9hK6LGPLYIQ_DvXrFoRPsThWGQqt-4jyLz-oex7pSaHWI2_Oq2VMYNDQH64RGYLFnFvh9e2jqSQy7_d2T61K6XKtgL46YiJEou5XvF-H4qw8lmFkWtCwVnK3jA?key=yZvDq_-uDN4B0M8iByv7S1s4" alt=""><figcaption></figcaption></figure>

Finally, we go back to the URL mentioned in **Level 4** and enter the credentials.

### <mark style="color:purple;">Lesson Learned</mark>

AWS allows you to make snapshots of EC2's and databases (RDS). The main purpose for that is to make backups, but people sometimes use snapshots to get access back to their own EC2's when they forget the passwords. This also allows attackers to get access to things. Snapshots are normally restricted to your own account, so a possible attack would be an attacker getting access to an AWS key that allows them to start/stop and do other things with EC2's and then uses that to snapshot an EC2 and spin up an EC2 with that volume in your environment to get access to it. Like all backups, you need to be cautious about protecting them.
