Translated ['src/pentesting-cloud/aws-security/aws-post-exploitation/aws

This commit is contained in:
Translator
2026-02-12 12:47:03 +00:00
parent ae514e5df3
commit 0ee4a8767f
3 changed files with 150 additions and 50 deletions

View File

@@ -4,7 +4,7 @@
## SES
更多信息请参见
更多信息,请查看
{{#ref}}
../../aws-services/aws-ses-enum.md
@@ -25,7 +25,7 @@ aws sesv2 send-email --from sender@example.com --destination file://emails.json
```bash
aws ses send-raw-email --raw-message file://message.json
```
待测试。
待测试。
### `ses:SendTemplatedEmail`
@@ -37,33 +37,45 @@ aws ses send-templated-email --source <value> --destination <value> --template
### `ses:SendBulkTemplatedEmail`
向多个目的地发送电子邮件
向多个收件人发送电子邮件
```bash
aws ses send-bulk-templated-email --source <value> --template <value>
```
待测试。
待测试。
### `ses:SendBulkEmail`
向多个目标发送电子邮件。
向多个目标发送邮件。
```
aws sesv2 send-bulk-email --default-content <value> --bulk-email-entries <value>
```
### `ses:SendBounce`
对已接收的邮件发送一封**退信**(表示该邮件无法投递)。这只能在收邮件后**最多24小时内**完成。
对已接收的邮件发送**退信**(表示该邮件无法被接收)。这只能在收邮件后**24 小时内**完成。
```bash
aws ses send-bounce --original-message-id <value> --bounce-sender <value> --bounced-recipient-info-list <value>
```
仍需测试。
尚待测试。
### `ses:SendCustomVerificationEmail`
这将发送一自定义的验证电子邮件。你可能还需要权限来创建模板电子邮件。
这将发送一自定义的验证邮件。你可能还需要权限来创建邮件模板
```bash
aws ses send-custom-verification-email --email-address <value> --template-name <value>
aws sesv2 send-custom-verification-email --email-address <value> --template-name <value>
```
待测试。
待测试。
## WorkMail pivot 绕过 SES sandbox
`ses:GetAccount` 显示账户仍在 SES sandbox 中且 `ses:ListIdentities` 未返回任何已验证的发件人时,攻击者可以 **pivot to WorkMail** 来立即发送(不受 sandbox 限制且默认配额更高方法是创建组织orgs、验证域名并注册邮箱。
{{#ref}}
../aws-workmail-post-exploitation/README.md
{{#endref}}
## 参考资料
- [Threat Actors Using AWS WorkMail in Phishing Campaigns](https://www.rapid7.com/blog/post/dr-threat-actors-aws-workmail-phishing-campaigns)
{{#include ../../../../banners/hacktricks-training.md}}

View File

@@ -0,0 +1,76 @@
# AWS - WorkMail Post Exploitation
{{#include ../../../../banners/hacktricks-training.md}}
## 利用 WorkMail 绕过 SES sandbox
Even if SES is stuck in the **sandbox** (verified-recipient only, ~200 msgs/24h, 1 msg/s), WorkMail has no equivalent restriction. 攻击者如果拥有长期密钥,可以快速部署一次性邮件基础设施并立即开始发送:
1. **创建一个 WorkMail 组织(按区域)**
```bash
aws workmail create-organization --region us-east-1 --alias temp-mail --directory-id <dir-id-if-reusing>
```
2. **验证攻击者控制的域名** (WorkMail invokes SES APIs as `workmail.amazonaws.com`):
```bash
aws ses verify-domain-identity --domain attacker-domain.com
aws ses verify-domain-dkim --domain attacker-domain.com
```
3. **配置邮箱用户并注册它们:**
```bash
aws workmail create-user --organization-id <org-id> --name marketing --display-name "Marketing"
aws workmail register-to-work-mail --organization-id <org-id> --entity-id <user-id> --email marketing@attacker-domain.com
```
注意:
- 默认由 AWS 文档记录的 **接收者上限****每个组织每天 100,000 个外部接收者**(跨用户汇总)。
- 域名验证活动会在 CloudTrail 中以 SES 类别出现,但带有 **`invokedBy`: `workmail.<region>.amazonaws.com`**,因此 SES 验证事件可能属于 WorkMail 的设置活动,而不是直接的 SES 活动。
- WorkMail 的邮箱用户成为与 IAM 用户独立的 **application-layer persistence**
## 发送路径与遥测盲点
### Web client (WorkMail UI)
- 会在 CloudTrail 中以 **`ses:SendRawEmail`** 事件表现出来。
- `userIdentity.type` = `AWSService`, `invokedBy/sourceIPAddress/userAgent` = `workmail.<region>.amazonaws.com`,因此 **真实的客户端 IP 被隐藏**
- `requestParameters` 仍会 leak 发件人(`source`, `fromArn`, `sourceArn`, configuration set可用于与新验证的域名/邮箱进行关联。
### SMTP (stealthiest)
- Endpoint: `smtp.mail.<region>.awsapps.com:465` (SMTP over SSL) with the mailbox password.
- **No CloudTrail data events** are generated for SMTP delivery, even when SES data events are enabled.
- 理想的检测点是 **组织/域/用户 的配置** 以及随后 Web 发送的 `SendRawEmail` 事件中引用的 SES identity ARNs。
<details>
<summary>通过 WorkMail 的 SMTP 示例发送</summary>
```python
import smtplib
from email.message import EmailMessage
SMTP_SERVER = "smtp.mail.us-east-1.awsapps.com"
SMTP_PORT = 465
EMAIL_ADDRESS = "marketing@attacker-domain.com"
EMAIL_PASSWORD = "SuperSecretPassword!"
target = "victim@example.com" # can be unverified/external
msg = EmailMessage()
msg["Subject"] = "WorkMail SMTP"
msg["From"] = EMAIL_ADDRESS
msg["To"] = target
msg.set_content("Delivered via WorkMail SMTP")
with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
```
</details>
## 检测注意事项
- 如果不需要 WorkMail 在组织级别通过 **SCPs** (`workmail:*` deny) 阻止它。
- 对预配活动发出警报:`workmail:CreateOrganization`, `workmail:CreateUser`, `workmail:RegisterToWorkMail`,以及带有 `invokedBy=workmail.amazonaws.com` 的 SES 验证(`ses:VerifyDomainIdentity`, `ses:VerifyDomainDkim`)。
- 监控异常的 **`ses:SendRawEmail`** 事件,当 identity ARNs 引用新域且源 IP/UA 等于 `workmail.<region>.amazonaws.com` 时。
## References
- [Threat Actors Using AWS WorkMail in Phishing Campaigns](https://www.rapid7.com/blog/post/dr-threat-actors-aws-workmail-phishing-campaigns)
- [AWS WorkMail limits](https://docs.aws.amazon.com/workmail/latest/adminguide/limits.html)
{{#include ../../../../banners/hacktricks-training.md}}

View File

@@ -1,10 +1,10 @@
# AWS - IAM, 身份中心与 SSO 枚举
# AWS - IAM, Identity Center & SSO Enum
{{#include ../../../banners/hacktricks-training.md}}
## IAM
可以在以下位置找到 **IAM 的描述**
可以在以下位置找到 **IAM 的描述**
{{#ref}}
../aws-basic-information/
@@ -12,9 +12,9 @@
### 枚举
需的主要权限:
的主要权限:
- `iam:ListPolicies`, `iam:GetPolicy` `iam:GetPolicyVersion`
- `iam:ListPolicies`, `iam:GetPolicy` and `iam:GetPolicyVersion`
- `iam:ListRoles`
- `iam:ListUsers`
- `iam:ListGroups`
@@ -22,9 +22,9 @@
- `iam:ListAttachedUserPolicies`
- `iam:ListAttachedRolePolicies`
- `iam:ListAttachedGroupPolicies`
- `iam:ListUserPolicies` `iam:GetUserPolicy`
- `iam:ListGroupPolicies` `iam:GetGroupPolicy`
- `iam:ListRolePolicies` `iam:GetRolePolicy`
- `iam:ListUserPolicies` and `iam:GetUserPolicy`
- `iam:ListGroupPolicies` and `iam:GetGroupPolicy`
- `iam:ListRolePolicies` and `iam:GetRolePolicy`
```bash
# All IAMs
## Retrieves information about all IAM users, groups, roles, and policies
@@ -88,37 +88,49 @@ aws iam get-account-password-policy
aws iam list-mfa-devices
aws iam list-virtual-mfa-devices
```
### 通过故意触发失败进行隐蔽权限确认
`List*` 或 模拟器 APIs 被阻止时,你可以通过触发可预测的验证错误来**在不创建持久性资源的情况下确认修改权限**。AWS 在返回这些错误之前仍会评估 IAM因此看到该错误就证明调用者具有该操作权限
```bash
# Confirm iam:CreateUser without creating a new principal (fails only after authz)
aws iam create-user --user-name <existing_user> # -> EntityAlreadyExistsException
# Confirm iam:CreateLoginProfile while learning password policy requirements
aws iam create-login-profile --user-name <target_user> --password lower --password-reset-required # -> PasswordPolicyViolationException
```
这些尝试仍然会生成 CloudTrail 事件(带有 `errorCode` 设置),但会避免留下新的 IAM 工件,因此在交互式侦察期间对于**低噪声权限验证**很有用。
### 权限暴力破解
如果您对自己的权限感兴趣,但没有访问查询 IAM 的权限,您可以尝试暴力破解它们
如果你想了解自己的权限,但无法访问查询 IAM,你可以始终对其进行暴力破解。
#### bf-aws-permissions
工具 [**bf-aws-permissions**](https://github.com/carlospolop/bf-aws-permissions) 只是一个 bash 脚本,它使用指定的配置文件运行所有可以通过 `aws` cli 帮助信息找到的 **`list*``describe*``get*`** 操作,并 **返回成功执行结果**
工具 [**bf-aws-permissions**](https://github.com/carlospolop/bf-aws-permissions) 只是一个 bash 脚本,它使用指定的 profile 运行所有从 `aws` cli 帮助信息找到的 **`list*``describe*``get*`** 操作,并**返回成功执行的操作**。
```bash
# Bruteforce permissions
bash bf-aws-permissions.sh -p default > /tmp/bf-permissions-verbose.txt
```
#### bf-aws-perms-simulate
工具 [**bf-aws-perms-simulate**](https://github.com/carlospolop/bf-aws-perms-simulate) 可以找到您当前的权限(或其他主体的权限),前提是拥有权限 **`iam:SimulatePrincipalPolicy`**
工具 [**bf-aws-perms-simulate**](https://github.com/carlospolop/bf-aws-perms-simulate) 可以找出你当前的权限(或其他主体的权限),前提是拥有权限 **`iam:SimulatePrincipalPolicy`**
```bash
# Ask for permissions
python3 aws_permissions_checker.py --profile <AWS_PROFILE> [--arn <USER_ARN>]
```
#### Perms2ManagedPolicies
如果你发现**你的用户拥有的一些权限**,并且你认为这些权限是由**托管的 AWS 角色**授予的(而不是自定义角色)你可以使用工具 [**aws-Perms2ManagedRoles**](https://github.com/carlospolop/aws-Perms2ManagedPolicies) 来检查所有**授予你发现权限的 AWS 托管角色**。
如果你发现 **你的用户拥有的一些权限**,并且你认为这些权限是由 **AWS 托管角色**(而不是自定义角色)授予的,你可以使用工具 [**aws-Perms2ManagedRoles**](https://github.com/carlospolop/aws-Perms2ManagedPolicies) 来检查所有授予你发现权限的 **AWS 托管角色**
```bash
# Run example with my profile
python3 aws-Perms2ManagedPolicies.py --profile myadmin --permissions-file example-permissions.txt
```
> [!WARNING]
> 如果您看到**您对未使用的服务拥有权限**则可以“知道”您拥有的权限是由AWS托管角色授予的
> 有时你可以“判断”你所拥有的权限是否由 AWS 管理的角色授予,例如当你发现 **你对未使用的服务拥有权限**
#### Cloudtrail2IAM
[**CloudTrail2IAM**](https://github.com/carlospolop/Cloudtrail2IAM) 是一个Python工具分析**AWS CloudTrail日志提取和总结所有人或特定用户或角色所做的操作**。该工具**解析来自指定存储桶的每个cloudtrail日志**。
[**CloudTrail2IAM**](https://github.com/carlospolop/Cloudtrail2IAM) 是一个 Python 工具,用来分析 **从 AWS CloudTrail 日志提取并汇总操作**,可以针对所有人或仅针对某个特定用户或角色。该工具**解析指定 bucket 中的每个 cloudtrail 日志**
```bash
git clone https://github.com/carlospolop/Cloudtrail2IAM
cd Cloudtrail2IAM
@@ -126,16 +138,16 @@ pip install -r requirements.txt
python3 cloudtrail2IAM.py --prefix PREFIX --bucket_name BUCKET_NAME --profile PROFILE [--filter-name FILTER_NAME] [--threads THREADS]
```
> [!WARNING]
> 如果你找到 .tfstateTerraform 状态文件)或 CloudFormation 文件(这些通常是位于以 cf-templates 为前缀的中的 yaml 文件),你也可以读取它们以查找 aws 配置并找出哪些权限分配给谁。
> 如果你发现 .tfstateTerraform 状态文件)或 CloudFormation 文件(这些通常是位于以 cf-templates 为前缀的 bucket 中的 yaml 文件),你也可以读取它们以查找 aws 配置并确定哪些权限分配给谁。
#### enumerate-iam
要使用工具 [**https://github.com/andresriancho/enumerate-iam**](https://github.com/andresriancho/enumerate-iam),你首先需要下载所有的 API AWS 端点,从中脚本 **`generate_bruteforce_tests.py`** 将获取所有的 **"list\_", "describe\_", "get\_" 端点。** 最后,它将尝试 **使用给定的凭据访问它们****指示是否成功**
To use the tool [**https://github.com/andresriancho/enumerate-iam**](https://github.com/andresriancho/enumerate-iam) you first need to download all the API AWS endpoints, from those the script **`generate_bruteforce_tests.py`** will get all the **"list\_", "describe\_", and "get\_" endpoints.** And finally, it will try to **access them** with the given credentials and **indicate if it worked**.
(根据我的经验,**工具在某个时刻会挂起** [**查看此修复**](https://github.com/andresriancho/enumerate-iam/pull/15/commits/77ad5b41216e3b5f1511d0c385da8cd5984c2d3c) 尝试修复这个问题)。
(In my experience the **tool hangs at some point**, [**checkout this fix**](https://github.com/andresriancho/enumerate-iam/pull/15/commits/77ad5b41216e3b5f1511d0c385da8cd5984c2d3c) to try to fix that).
> [!WARNING]
> 根据我的经验,这个工具与之前的工具类似,但工作效果更差,检查的权限更少
> 根据我的经验,这个工具类似于前一个,但表现更差并且检查的权限更少
```bash
# Install tool
git clone git@github.com:andresriancho/enumerate-iam.git
@@ -154,7 +166,7 @@ python3 enumerate-iam.py --access-key ACCESS_KEY --secret-key SECRET_KEY [--sess
```
#### weirdAAL
您还可以使用工具 [**weirdAAL**](https://github.com/carnal0wnage/weirdAAL/wiki)。该工具检查 **多个常见服务上的多个常见操作**(将检查一些枚举权限和一些特权提升权限)。但它只会检查编码的检查(检查更多内容唯一方法是编写更多测试)。
你也可以使用工具 [**weirdAAL**](https://github.com/carnal0wnage/weirdAAL/wiki)。该工具检查**多个常见服务上若干常见操作**(会检查一些枚举权限,也会检查一些 privesc 权限)。但它只会检查编码的检测(要检查更多内容唯一方法是编写更多测试)。
```bash
# Install
git clone https://github.com/carnal0wnage/weirdAAL.git
@@ -178,7 +190,7 @@ python3 weirdAAL.py -m recon_all -t MyTarget # Check all permissions
# [+] elbv2 Actions allowed are [+]
# ['DescribeLoadBalancers', 'DescribeAccountLimits', 'DescribeTargetGroups']
```
#### 加固工具以暴力破解权限
#### 针对 BF permissions 的加固工具
{{#tabs }}
{{#tab name="CloudSploit" }}
@@ -208,9 +220,9 @@ steampipe dashboard
#### \<YourTool>
之前的工具都无法检查所有权限,因此如果你知道更好的工具,请发送 PR
Neither of the previous tools is capable of checking close to all permissions, so if you know a better tool send a PR!
### 未经身份验证的访问
### 未认证访问
{{#ref}}
../aws-unauthenticated-enum-access/aws-iam-and-sts-unauthenticated-enum/README.md
@@ -218,27 +230,27 @@ steampipe dashboard
### 权限提升
下页面中,你可以查看如何 **滥用 IAM 权限以提升权限**
在下面的页面中,你可以查看如何 **滥用 IAM 权限 来进行权限提升**
{{#ref}}
../aws-privilege-escalation/aws-iam-privesc/README.md
{{#endref}}
### IAM 后利用
### IAM 后利用
{{#ref}}
../aws-post-exploitation/aws-iam-post-exploitation/README.md
{{#endref}}
### IAM 持久
### IAM 持久
{{#ref}}
../aws-persistence/aws-iam-persistence/README.md
{{#endref}}
## IAM 身份中心
## IAM Identity Center
你可以在以下位置找到 **IAM 身份中心的描述**
关于 **IAM Identity Center** 的描述可在以下位置找到
{{#ref}}
../aws-basic-information/
@@ -257,16 +269,16 @@ sso_region = us-east-1
```
### 枚举
身份中心的主要元素
Identity Center 的主要元素
- 用户和组
- 权限集:附加了策略
- AWS 账户
- Permission Sets:附加了策略
- AWS Accounts
然后创建关系,使用户/组 AWS 账户拥有权限集
然后创建关系,使用户/组 AWS Account 上拥有 Permission Sets
> [!NOTE]
> 注意有三种方法可以将策略附加到权限集。附加 AWS 管理的策略、客户管理的策略(这些策略需要在所有受权限集影响的账户中创建)和内联策略(在此定义)。
> 注意有三种方法可以将策略附加到 Permission Set附加 AWS managed policies、Customer managed policies这些策略需要在 Permission Set 所影响的所有账户中创建),以及 inline policies在其中定义)。
```bash
# Check if IAM Identity Center is used
aws sso-admin list-instances
@@ -302,7 +314,7 @@ aws identitystore list-group-memberships-for-member --identity-store-id <store-i
```
### 本地枚举
可以在文件夹 `$HOME/.aws` 创建配置文件,以配置可以通过 SSO 访问的配置文件,例如:
可以在文件夹 `$HOME/.aws` 创建名为 config 的文件,以配置通过 SSO 访问的 profiles,例如:
```ini
[default]
region = us-west-2
@@ -327,9 +339,9 @@ aws sso login --profile my-sso-profile
# Use dependent-profile
aws s3 ls --profile dependent-profile
```
使用 **SSO 的配置文件** 访问某些信息时,凭会被 **缓存** 在文件中,位于文件夹 **`$HOME/.aws/sso/cache`** 内。因此它们可以 **从那里读取使用**
**使用来自 SSO 的 profile**来访问某些信息时,凭会被**缓存**在位于文件夹 **`$HOME/.aws/sso/cache`** 内的文件中。因此它们可以**从那里读取使用**。
此外,**更多凭** 可以存储在文件夹 **`$HOME/.aws/cli/cache`** 中。缓存目录主要在**使用 AWS CLI 配置文件** 时使用,这些配置文件使用 IAM 用户凭或通过 IAM **假设** 角色不使用 SSO。配置示例
此外,**更多凭**可以存储在文件夹 **`$HOME/.aws/cli/cache`** 中。缓存目录主要在**使用 AWS CLI profiles**(这些 profiles 使用 IAM 用户凭证,或通过 IAM **assume** 角色,且不使用 SSO时使用。配置示例:
```ini
[profile crossaccountrole]
role_arn = arn:aws:iam::234567890123:role/SomeRole
@@ -337,7 +349,7 @@ source_profile = default
mfa_serial = arn:aws:iam::123456789012:mfa/saanvi
external_id = 123456
```
### 未经身份验证的访问
### 未认证访问
{{#ref}}
../aws-unauthenticated-enum-access/aws-identity-center-and-sso-unauthenticated-enum/README.md
@@ -349,7 +361,7 @@ external_id = 123456
../aws-privilege-escalation/aws-sso-and-identitystore-privesc/README.md
{{#endref}}
### 后期利用
### 利用后操作
{{#ref}}
../aws-post-exploitation/aws-sso-and-identitystore-post-exploitation/README.md
@@ -357,16 +369,16 @@ external_id = 123456
### 持久性
#### 创建用户并分配权限
#### 创建一个用户并为其分配权限
```bash
# Create user identitystore:CreateUser
aws identitystore create-user --identity-store-id <store-id> --user-name privesc --display-name privesc --emails Value=sdkabflvwsljyclpma@tmmbt.net,Type=Work,Primary=True --name Formatted=privesc,FamilyName=privesc,GivenName=privesc
## After creating it try to login in the console using the selected username, you will receive an email with the code and then you will be able to select a password
```
- 创建一个组并分配权限,并设置一个受控用户
- 受控用户或组额外权限
- 默认情况下,只有来自管理账户的用户才能访问和控制 IAM 身份中心
- 创建一个组并为其分配权限,并在其上设置一个受控用户
- 受控用户或组授予额外权限
- 默认情况下,只有来自 Management Account 并具有权限的用户才能访问和控制 IAM Identity Center
然而,可以通过委派管理员允许来自不同账户的用户进行管理。他们将没有完全相同的权限,但他们将能够执行 [**管理活动**](https://docs.aws.amazon.com/singlesignon/latest/userguide/delegated-admin.html)。
不过,可以通过 Delegate Administrator 允许来自不同账户的用户进行管理。他们不会拥有完全相同的权限,但他们将能够执行 [**management activities**](https://docs.aws.amazon.com/singlesignon/latest/userguide/delegated-admin.html)。
{{#include ../../../banners/hacktricks-training.md}}