Computer Language/PHP
[PHP] 비교 연산자 취약점 (7.4.x)
Bull_
2023. 9. 27. 04:20
웹 컴파일러
PHP Sandbox - Execute PHP code online through your browser
onlinephp.io
해당 사이트에서 버전을 7.4.x로 바꿀 수 있다.
Type 비교 연산자 취약점
다음과 같이 문자열을 (int)를 사용해 강제 형변환을 해준다.

그러면 위와 같이 숫자가 끝날때 까지는 숫자를 반환하고 문자는 0을 반환한다.
따라서
if((int)"aaaa" == "rrr") # if(1)
의 반환값은 true가 된다.
이 취약점의 공식? 명칭은 Type juggling & casting이다.
7.4.x → 8.0.x 변경사항
https://www.php.net/manual/en/migration80.incompatible.php
PHP: Backward Incompatible Changes - Manual
In PHP 8, an empty string is less than any number, an English letter is always bigger than any number.More interesting are the punctuation marks and non-word characters, some bigger than numbers, some smaller than numbers$string = '`~!@#$%^&*()-_=+[]{};:\'
www.php.net

해당 취약점은 버전이 변경되면서 false가 나오도록 변경되었다.