# 枚举

**枚举 IAM 权限**

```
https://github.com/andresriancho/enumerate-iam
使用enumerate-iam 枚举与 AWS 凭证集关联的权限
>git clone git@github.com:andresriancho/enumerate-iam.git
>pip install -r requirements.txt
>./enumerate-iam.py --access-key AKIA... --secret-key StF0q...
2019-05-10 15:57:58,447 - 21345 - [INFO] Starting permission enumeration for access-key-id "AKIA..."
2019-05-10 15:58:01,532 - 21345 - [INFO] Run for the hills, get_account_authorization_details worked!
2019-05-10 15:58:01,537 - 21345 - [INFO] -- {
    "RoleDetailList": [
        {
            "Tags": [],
            "AssumeRolePolicyDocument": {
                "Version": "2008-10-17",
                "Statement": [
                    {
...
2019-05-10 15:58:26,709 - 21345 - [INFO] -- gamelift.list_builds() worked!
2019-05-10 15:58:26,850 - 21345 - [INFO] -- cloudformation.list_stack_sets() worked!
2019-05-10 15:58:26,982 - 21345 - [INFO] -- directconnect.describe_locations() worked!
2019-05-10 15:58:27,021 - 21345 - [INFO] -- gamelift.describe_matchmaking_rule_sets() worked!
2019-05-10 15:58:27,311 - 21345 - [INFO] -- sqs.list_queues() worked!
一旦您有权访问云帐户，您需要弄清楚您的用户有权与哪些资源进行交互。 AWS 有数百种服务，因此我们无法涵盖所有服务，但您至少应该熟悉基本服务
```

![image](https://raw.githubusercontent.com/xiaoy-sec/Pentest_Note/master/img/908.png)

**S3 存储桶**

```
我确定您听说过 S3 存储桶，但如果您没有听说过，它是一种用于存储文件和其他对象的公共云存储资源。 作为攻击者，这绝对是您想要寻找的东西，因为它有可能存储敏感数据。
列出云环境中的所有 S3 存储桶
> aws s3api list-buckets
在某些情况下，您可能有权访问 S3 存储桶，但缺少列出 S3 存储桶名称所需的权限或策略。在这种情况下，您必须能够猜测或暴力破解您有权访问的 S3 存储桶的名称。
知道 S3 存储桶的名称后，您可以通过发出以下 CLI 命令查看其内容：
> aws s3 ls YOUR_BUCKET
这将列出存储桶中的所有文件和文件夹。要下载文件，您可以发出“cp”命令，如下所示：
> aws s3 cp s3://YOUR_BUCKET/file.txt file.txt
如上所示，我们正在将文本文件“file.txt”下载到本地系统。
您还可以使用以下命令下载整个 S3 存储桶：
> aws s3 sync s3://YOUR_BUCKET
```

**虚拟机**

```
AWS 有多种类型的虚拟机，但最流行的一种是弹性计算云 (EC2)。您可以根据需要使用 Amazon EC2 启动任意数量的虚拟服务器、配置安全性和网络以及管理存储。
> aws ec2 describe-instances
此命令返回 EC2 实例列表及其相关信息，例如其 IP 地址、instanceid、名称等。 以上返回大量信息，但您可以使用内置 JSON 解析器通过 --query 参数过滤输出
> aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}"
```

**数据库**

```
作为攻击者获得公司数据库的访问权限是一座金矿。 数据库包含各种有趣的东西，例如用户名和密码。 根据技术要求，一个环境中可能运行多种不同类型的数据库
```

![image](https://raw.githubusercontent.com/xiaoy-sec/Pentest_Note/master/img/909.png)

```
AWS 提供处理一切的服务，但我们将专注于托管 MySql 数据库的“Amazon RDS”服务。 要获取正在运行的数据库的列表，请运行以下命令：
> aws rds describe-db-instances
返回的字段之一是地址和root用户。如果该地址可以外联，您可以将其与 root 用户一起使用来发起暴力攻击。
根据您的权限，您可能能够重置主密码。这可以通过以下命令完成：
> aws rds modify-db-instance --db-instance-identifier INSTANCE_NAME --master-user-password NEWPASSWORD --apply-immediately
重置主密码后，您可以登录数据库并下载所有内容。但是，更改 root 密码肯定会引发警报，并且您可能会破坏使用该帐户的任何应用程序，因此在这样做时要小心。
```

**Elastic BeanStalk**

```
AWS Elastic Beanstalk (EBS) 是一种易于使用的服务，用于部署和扩展使用 Java、. NET，PHP。在熟悉的服务器（如 Apache、Nginx、Passenger 和 IIS）上运行 Node.js、Python、Ruby、Go 和 Docker。这意味着我们可以使用 EBS 通过单击按钮或 shell 命令轻松部署应用程序。 AWS 自动化了整个部署过程。
通常，您会看到部署到 beanstalk 环境的前端或 API。可以通过发出以下 CLI 命令来定位这些环境：
> aws elasticbeanstalk describe-environments
注意返回的“EndpointURL”变量。 这将有一个指向 EBS 托管的应用程序的公共 url。 拥有此端点后，您可以对该应用程序发起进一步的攻击
```

![image](https://raw.githubusercontent.com/xiaoy-sec/Pentest_Note/master/img/910.png)

```
EBS 的另一个有趣之处在于，它将应用程序从 S3 存储桶中包含的源代码部署到 EC2 实例。 当我们按下部署按钮时，它会获取我们的源代码并将其保存到 S3 存储桶中，然后将其从该文件部署到虚拟机。 这意味着我们应该能够在 S3 存储桶中找到所有 EBS 应用程序的源代码。 任何有权访问该 S3 存储桶的人也将有权访问所有 EBS 应用程序的源代码
> aws s3 ls  可以查看是否存在名为 elasticbeanstalk 的 S3 存储桶
> aws s3 ls elasticbeanstalk-XXXX 
在该 s3 存储桶上发出 ls 命令，您应该会看到一堆 .zip 文件。
这些 zip 文件包含部署到 beanstalk 的应用程序的源代码。 下一步是下载这些文件并分析硬编码凭据和漏洞的源代码
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.heresecurity.wiki/yun-an-quan/aws/mei-ju.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
