Information Security

[OverTheWire] NATAS13 본문

Web Hacking/NATAS 풀이

[OverTheWire] NATAS13

leeeeye321 2018. 1. 9. 23:23

[OverTheWire] NATAS13

 

else if (! exif_imagetype($_FILES['uploadedfile']['tmp_name'])) { 
        echo "File is not an image"; 
    } else { 
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
            echo "The file <a href=\"$target_path\">$target_path</a> has been uploaded"; 
        } 

NATAS12와 코드가 거의 유사하지만 다른 점은 exif_imagetype() 함수의 반환 값이 존재해야만 파일을 업로드할 수 있다는 것이다.

 

exif_imagetype() reads the first bytes of an image and checks its signature.

http://php.net/manual/en/function.exif-imagetype.php 참고

exif_imagetype() 함수는 이미지의 첫 번째 바이트를 읽고 signature를 확인한다.

 

exif_imagetype() 함수의 반환 값 목록의 일부이다.

해당 함수는 signature를 확인하여 파일의 type을 반환 한다.

 

★ 파일 시그니처(File Signature)

파일 시그니처는 파일의 가장 처음에 위치하는 특정 바이트들로 파일 포맷을 구분하기 위해서 사용한다.

자세한 설명은 http://forensic-proof.com/archives/300 참고

 

위의 사이트에서 GIF의 파일 시그니처를 확인했다.

 

NATAS12에서 사용했던 파일의 PHP 코드앞에 GIF의 파일 시그니처를 추가해주고 저장한다.

 

이 파일을 업로드한다.

 

이번에도 업로드한 파일을 jpg로 인식한다.

 

php로 인식하도록 확장자를 변경한다.

 

 

파일을 실행하면 PHP 코드가 실행되어 natas14의 패스워드가 출력된다. 

'Web Hacking > NATAS 풀이' 카테고리의 다른 글

[OverTheWire] NATAS15  (0) 2018.01.10
[OverTheWire] NATAS14  (0) 2018.01.09
[OverTheWire] NATAS12  (0) 2018.01.09
[OverTheWire] NATAS11  (0) 2018.01.08
[OverTheWire] NATAS10  (0) 2018.01.05