[ctfshow]Web5

Web5

题目描述

题目解析

image-20220623121928520

打开题目发现给了一堆php代码,根据代码的描述可以发现,需要传入两个变量v1和v2,再判断如果v1和v2的md5值相等,则输出flag。下面对出现的函数进行解释。

  • isset:用于检测变量是否已经设置并且非NULL
  • ctype_alpha:用于检测是否为纯字符串
  • is_numeric:用于检测变量是否为数字或者数字字符串
  • md5:计算字符串的MD5散列值

首先明确,v1必须试一个字符串,v2必须是一个纯数字,所以要找到一个md5值相等的字符串和纯数字字符串,在https://www.php.net/manual/zh/function.md5.php中发现这样的一个解释:

md5('240610708') == md5('QNKCDZO')

This comparison is true because both md5() hashes start '0e' so PHP type juggling understands these strings to be scientific notation. By definition, zero raised to any power is zero.

我理解为MD5值以0e开头,php在判断的时候判断为了浮点型,比如1e6就表示为1*10^6,也即1000000.0,所以在比较时,因为0的任何次方都为0,所以两个数相等。但是如果判断时使用===结果就为false,这是因为在php中,==在判断一个数字和一个字符串或者一个包含数字的字符串时,会将字符串转化为数字类型进行比较。

If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.

https://stackoverflow.com/questions/12598407/why-does-php-convert-a-string-with-the-letter-e-into-a-number/12598484#12598484

https://stackoverflow.com/questions/22140204/why-md5240610708-is-equal-to-md5qnkcdzo

https://www.php.net/manual/zh/function.md5.php

所以当v1=QNKCDZO,v2=240610708时,两个的md5值均为0e开头,并且使用的是==,则会将两个值转化为数字类型,进行比较返回true,即可得到flag~

posted @ 2022-06-23 13:05  alm0st  阅读(56)  评论(0编辑  收藏  举报