Wargame/websec.fr

Websec.fr babysteps level 06

JeonYoungSin 2018. 3. 8. 13:40

들어가보면 소스를 제공해주고 있고 ssrf로 서버내 flag.php를 읽어오면 된다.

 

source

 

<?php

if (isset ($_POST['submit'
])) {
    
$url $_POST['url'
];

    
/* People tends to do funny things with curl. */
    
if (preg_match ('/[https?|[st]?ftp|dict|gopher|scp|telnet|ldaps?]\:\/\/.*(\d+|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/i'$url
)) {
        die(
'Please do not access by IP.'
);
    } elseif (
preg_match ('/localhost/i'$url
)) {
        die (
'Please do not access localhost.'
); 
    }

    if (
stripos ($url'/', -1) !== '/') { $url .= '/'
; }
    
$url .= 'index.php'
;

    try {
        
$ch curl_init ($url
);
    
        if (
FALSE === $ch
) {
            throw new 
Exception('failed to initialize'
);    
        } elseif (
defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4'
)){
            
curl_setopt($chCURLOPT_IPRESOLVECURL_IPRESOLVE_V4
);
        }       
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue
);
        
curl_setopt($chCURLOPT_FOLLOWLOCATIONfalse
);
        
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse
);
        
$result curl_exec($ch
);
        
curl_close($ch
);
    } catch (
Exception $e
) {
        
trigger_error (sprintf ('Curl failed with #%d: %s'$e->getCode(), $e->getMessage()), E_USER_ERROR
);
    }
}
?>

 

일단 http를 사용할 수 있고 내가 입력한 값뒤에 /index.php가 붙게 된다.

http://websec.fr/level06/flag.php? 요런식으로 index.php 날려주고 접근해보면 해당파일에 접근이 불가능하고 로컬에서 접근을 하라고한다. file://로 접근해주면 될 것 같은데 처음에 file Wrapper는 http처럼 ?나 #이 적용이 안될거라고 생각해서 시도안하고 다른방법 생각해보다가 도저히 안떠올라서 그냥한번 해볼까 하고 요렇게 file:///flag.php?index.php , file:///flag.php#index.php 시도했는데 파일이 읽혔다. 이게지금 http처럼 파라미터나 #이후 무시되는 현상이 똑같이 일어나서 되는건지  이문제자체를 그렇게 만든건진 모르겠지만 일단 가능성이 존재한다는걸 알았고 앞으로도 한번씩 시도해보면 좋을것 같다.