NGA

parse_url

 

parse_url('http://a@b@c') => ( [scheme] => http [host] => c [user] => a@b )

parse_url('http://a@b@c@d@e@f@g') => ( [scheme] => http [host] => g [user] => a@b@c@d@e@f )

parse_url('http://a:10@b:20@c:30') => ( [scheme] => http [host] => c [port] => 30 [user] => a [pass] => 10@b:20 )

parse_url('http://a@b:80@c') => ( [scheme] => http [host] => c [user] => a@b [pass] => 80 )

parse_url('http://a@b:80cdefg123') => return False

 

parse_url 은 항상 "@" 후에 오는 문자열을 host 로 인식

그리고 port 에 문자가 오게되면 False 를 반환

 

Curl

 

curl http://a@b@c => ( [host] => b@c [user] => a )

curl http://a@b@c@d@e@f@g => ( [host] => b@c@d@e@f@g [user] => a )

curl http://a:10@b:20@c:30 => ( [host] => b:20@c [port] => 30 [user] => a [pass] => 10 )

curl http://a:10@b:80@c => ( [host] => b [port] => 80 [user] => a [pass] => 10 )    ?!

curl http://a@b:80@c => ( [host] => b [port] => 80 [user] => a )    ???!

curl http://a@b:80cdefg123 => ( [host] => b [port] => 80 [user] => a )    ????!!

 

curl 은 첫 "@" 부터 마지막 (":" or EOL ) 까지 host 로 인식

port 에 80aas@asd 처럼 문자가 들어가도 숫자 다음으로 오는 문자를 무시해버린다.

 

parse_url 과 curl 을 같이 사용하게 된다면 parsing 과정이 달라 의도치 않은 요청이 가능하게 된다.

 

www.google.com 에 요청을 보내는 코드

<?php
  		
        $url = $_GET['url'];
        $host = parse_url($url)['host'];
        if($host !== "www.google.com")
                exit('only google.com');

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        echo $output;
?>

 

parse_url 과 curl 의 차이를 통해서 url = https://a@localhost:80@www.google.com 와 같이 다른 요청을 보낼수 있게 된다.

'WEB > PHP' 카테고리의 다른 글

PHP Array Trick  (0) 2020.02.12
HTTP HEAD method trick in PHP 5.3.5  (0) 2020.02.12
PHP system command functions  (0) 2019.09.24
PHP Sandbox TIP!!  (0) 2019.07.10
Read file with PHP Display Error  (0) 2019.07.10

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band