mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-23 15:37:53 -08:00
93 lines
5.3 KiB
Markdown
93 lines
5.3 KiB
Markdown
# AWS - EMR Privesc
|
|
|
|
{% hint style="success" %}
|
|
Learn & practice AWS Hacking:<img src="../../../.gitbook/assets/image (1) (1) (1) (1).png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../.gitbook/assets/image (1) (1) (1) (1).png" alt="" data-size="line">\
|
|
Learn & practice GCP Hacking: <img src="../../../.gitbook/assets/image (2) (1).png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="../../../.gitbook/assets/image (2) (1).png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Support HackTricks</summary>
|
|
|
|
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
|
|
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.**
|
|
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
|
|
|
</details>
|
|
{% endhint %}
|
|
|
|
## EMR
|
|
|
|
More **info about EMR** in:
|
|
|
|
{% content-ref url="../aws-services/aws-emr-enum.md" %}
|
|
[aws-emr-enum.md](../aws-services/aws-emr-enum.md)
|
|
{% endcontent-ref %}
|
|
|
|
### `iam:PassRole`, `elasticmapreduce:RunJobFlow`
|
|
|
|
An attacker with these permissions can **run a new EMR cluster attaching EC2 roles** and try to steal its credentials.\
|
|
Note that in order to do this you would need to **know some ssh priv key imported in the account** or to import one, and be able to **open port 22 in the master node** (you might be able to do this with the attributes `EmrManagedMasterSecurityGroup` and/or `ServiceAccessSecurityGroup` inside `--ec2-attributes`).
|
|
|
|
```bash
|
|
# Import EC2 ssh key (you will need extra permissions for this)
|
|
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N ""
|
|
chmod 400 /tmp/sshkey
|
|
base64 /tmp/sshkey.pub > /tmp/pub.key
|
|
aws ec2 import-key-pair \
|
|
--key-name "privesc" \
|
|
--public-key-material file:///tmp/pub.key
|
|
|
|
|
|
aws emr create-cluster \
|
|
--release-label emr-5.15.0 \
|
|
--instance-type m4.large \
|
|
--instance-count 1 \
|
|
--service-role EMR_DefaultRole \
|
|
--ec2-attributes InstanceProfile=EMR_EC2_DefaultRole,KeyName=privesc
|
|
|
|
# Wait 1min and connect via ssh to an EC2 instance of the cluster)
|
|
aws emr describe-cluster --cluster-id <id>
|
|
# In MasterPublicDnsName you can find the DNS to connect to the master instance
|
|
## You cna also get this info listing EC2 instances
|
|
```
|
|
|
|
Note how an **EMR role** is specified in `--service-role` and a **ec2 role** is specified in `--ec2-attributes` inside `InstanceProfile`. However, this technique only allows to steal the EC2 role credentials (as you will connect via ssh) but no the EMR IAM Role.
|
|
|
|
**Potential Impact:** Privesc to the EC2 service role specified.
|
|
|
|
### `elasticmapreduce:CreateEditor`, `iam:ListRoles`, `elasticmapreduce:ListClusters`, `iam:PassRole`, `elasticmapreduce:DescribeEditor`, `elasticmapreduce:OpenEditorInConsole`
|
|
|
|
With these permissions an attacker can go to the **AWS console**, create a Notebook and access it to steal the IAM Role.
|
|
|
|
{% hint style="danger" %}
|
|
Even if you attach an IAM role to the notebook instance in my tests I noticed that I was able to steal AWS managed credentials and not creds related to the IAM role related.
|
|
{% endhint %}
|
|
|
|
**Potential Impact:** Privesc to AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile
|
|
|
|
### `elasticmapreduce:OpenEditorInConsole`
|
|
|
|
Just with this permission an attacker will be able to access the **Jupyter Notebook and steal the IAM role** associated to it.\
|
|
The URL of the notebook is `https://<notebook-id>.emrnotebooks-prod.eu-west-1.amazonaws.com/<notebook-id>/lab/`
|
|
|
|
{% hint style="danger" %}
|
|
Even if you attach an IAM role to the notebook instance in my tests I noticed that I was able to steal AWS managed credentials and not creds related to the IAM role related`.`
|
|
{% endhint %}
|
|
|
|
**Potential Impact:** Privesc to AWS managed role arn:aws:iam::420254708011:instance-profile/prod-EditorInstanceProfile
|
|
|
|
{% hint style="success" %}
|
|
Learn & practice AWS Hacking:<img src="../../../.gitbook/assets/image (1) (1) (1) (1).png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../.gitbook/assets/image (1) (1) (1) (1).png" alt="" data-size="line">\
|
|
Learn & practice GCP Hacking: <img src="../../../.gitbook/assets/image (2) (1).png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="../../../.gitbook/assets/image (2) (1).png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Support HackTricks</summary>
|
|
|
|
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
|
|
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.**
|
|
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
|
|
|
</details>
|
|
{% endhint %}
|