https://dreamhack.io/wargame/challenges/328
if you can bypass the strcmp function, you get the flag.
view-source를 눌러 코드를 확인해 줍니다.$password = sha1(md5(rand().rand().rand()).rand());위 코드를 통해 패스워드가 랜덤으로 생성되고 있음을 확인할 수 있습니다. (rand() 함수는 PHP 내장 함수로, 호출할 때마다 임의의 정수값을 반환합니다.) if (strcmp($_POST['password'], $password) == 0) {
echo "Congratulations! Flag is <b>" . $FLAG ."</b>";strcmp()를 사용하였습니다.strcmp()함수는 두 문자열이 일치하면 0을 반환합니다.strcmp() 함수는 PHP 5.3 버전에서 배열을 인자로 받으면 null을 반환하는 특성이 있습니다.null == 0 이 참이므로, 조건을 우회할 수 있습니다.$_POST['password']에 배열을 전달하여 strcmp()가 null을 반환하게 만들면, null == 0이 참이 되어 플래그를 획득할 수 있습니다.name="password" 를 name="password[]"로 변경해줍니다. (name="password[]"는 폼 전송 시 해당 값을 배열로 만들어서 보내겠다는 의미입니다.)
chk를 클릭하면, strcmp()가 null을 반환하고 조건문을 통과하여 플래그를 획득할 수 있습니다.
strcmp() 함수에 대해 배울 수 있었습니다. 또한, 느슨한 비교를 이용한다면 취약점이 생겨, 이를 이용해 공격이 가능함을 배웠습니다.strcmp()의 배열 처리 방식이 다르다는 점을 통해, 서버의 환경과 언어 버전도 공격 설계에 중요한 요소가 될 수 있다는 걸 배웠습니다.strcmp() function to retrieve the flag.rand() and hashed with md5() and sha1(), making it impossible to guess the actual value.strcmp($_POST['password'], $password) == 0 condition is used to compare the input with the server-side password.strcmp() receives an array as input, it returns null.null == 0 evaluates to true in loose comparison, the condition can be bypassed by sending an array instead of a string.password[] using browser developer tools. PHP then treats the input as an array.strcmp() to return null, triggering the condition and printing the flag.strcmp() behavior, type juggling in PHP, version-specific behaviors (5.2 vs 5.3), and the importance of not trusting client-side inputs.