• 카테고리

    질문 & 답변
  • 세부 분야

    보안

  • 해결 여부

    미해결

%00 사용하면 오류 발생

21.08.28 00:25 작성 조회수 298

1

<?
header("Content-Type: text/html; charset=UTF-8");

$gubun = $_GET["gubun"];
if(empty($_FILES["userfile"]["name"])){#클라이언트에 존재하는 파일의 원래 이름
    echo "<script>alert('파일을 업로드 하세요!');history.back(-1);</script>";
    exit();
}

$path = "./upload/";
$filename = $gubun."_".$_FILES["userfile"]["name"];#서버에 저장된 업로드된 파일의 임시 파일 이름



$file_info = pathinfo($path.$filename);
$ext = strtolower($file_info["extension"]);

$ext_arr = array("php""html""");

if(in_array($ext$ext_arr)){#파일 이름에 "php", "php3", "php5", "html", "htm" 확장자가 포함되어 있으면 예외처리(블랙리스트) 
    echo "<script>alert('허용되지 않은 확장자 입니다1.');history.back(-1);</script>";
    exit();
}

if(!move_uploaded_file($_FILES["userfile"]["tmp_name"], $path.$filename)){#$_FILES["userfile"]["tmp_name"](서버에 저장된 임시 파일)을 $path.$filename(업로드될 경로:upload/$filename)에 저장
    echo "<script>alert('파일 업로드에 실패하였습니다.');history.back(-1);</script>";
    exit();
}
?>

<li>업로드 성공 : <?=$path.$filename?></li>

------------------------------------------------------------------------------------------------------------

POST /null_ex1/upload.php?gubun=aa.php%00 HTTP/1.1

Host: 127.0.0.1:81

Content-Length: 1588436

Cache-Control: max-age=0

sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"

sec-ch-ua-mobile: ?0

Upgrade-Insecure-Requests: 1

Origin: http://127.0.0.1:81

Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryFJAvtYdjVBOAe0Td

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9

Sec-Fetch-Site: same-origin

Sec-Fetch-Mode: navigate

Sec-Fetch-User: ?1

Sec-Fetch-Dest: document

Referer: http://127.0.0.1:81/null_ex1/index.php

Accept-Encoding: gzip, deflate

Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7

Connection: close

------WebKitFormBoundaryFJAvtYdjVBOAe0Td

Content-Disposition: form-data; name="userfile"; filename="test.jpg"

Content-Type: image/jpeg

---------------------------------------------------------------------------------------------------------------

HTTP/1.1 200 OK

Date: Fri, 27 Aug 2021 15:23:45 GMT

Server: Apache

X-Frame-Options: SAMEORIGIN

X-Powered-By: PHP/7.4.7

Vary: Accept-Encoding

Content-Length: 282

Connection: close

Content-Type: text/html; charset=UTF-8

<br />

<b>Warning</b>:  move_uploaded_file() expects parameter 2 to be a valid path, string given in <b>C:\Bitnami\wampstack-7.4.7-0\apache2\htdocs\null_ex1\upload.php</b> on line <b>25</b><br />

<script>alert('파일 업로드에 실패하였습니다.');history.back(-1);</script>

답변 3

·

답변을 작성해보세요.

0

dhwns5555님의 프로필

dhwns5555

질문자

2021.08.30

이렇게 됩니다.

0

혹시 업로드 기능은 정상적으로 잘되나요? %00 없이 그냥 업로드 할 경우 파일 업로드는 잘 되나요?

0

dhwns5555님의 프로필

dhwns5555

질문자

2021.08.28

php.ini 파일에

; Magic quotes for incoming GET/POST/Cookie data.

magic_quotes_gpc = Off

도 설정해주었습니다.