打开连接发现页面上提示了flag.php,那么flag应该就放在这里了,点开intersting challenge

 出现源码,审计代码

 <?php 
highlight_file(__FILE__);
function check_inner_ip($url) 
{ 
    $match_result=preg_match('/^(http|https)?:\/\/.*(\/)?.*$/',$url); 
    if (!$match_result) 
    { 
        die('url fomat error'); 
    } 
    try 
    { 
        $url_parse=parse_url($url); 
    } 
    catch(Exception $e) 
    { 
        die('url fomat error'); 
        return false; 
    } 
    $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; 
} 

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); 
} 

?> 

首先GET方式传入url赋值给$url,检测url是否为空,不为空则执行safe_request_url函数,

safe_request_url函数在一开始就调用了check_inner_ip()函数,check_inner_ip()函数对url进行正则匹配,判断url是否为正确格式,若正确则继续执行safe_request_url函数,

我们是需要访问127.0.0.1/flag.php来拿到flag

但如果我们直接传入此地址我们是拿不到flag的

因为ip2long()这个函数将地址转化为了整形

我们是无法成功读取的,因此我们需要绕过此关

<?php $url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url,PHP_URL_PATH);
?>

分析url的解析,因为$ip取的是hostname

 这里我们将hostname随便改成非inner ip的地址,以此来绕过

payload:http://Ezpop:@127.0.0.1:80@blog.csdn.net/flag.php

拿到flag

Logo

鸿蒙生态一站式服务平台。

更多推荐