伙计们,我认为上述方法引入了不需要存在的安全漏洞。
电子邮件验证的主要目标是,我们希望注册的人提供他们拥有或至少有权访问的真实电子邮件地址。我们不希望人们注册其他人拥有的随机电子邮件地址,例如您的电子邮件地址。
上述代码存在漏洞,使黑客能够注册其他人拥有的随机电子邮件地址,然后在您的电子邮件验证页面上相对轻松地强制使用$user\\u id值和$code值。
1st vulnerability
您使用的是$user\\u id。现在我知道这个值可以是任意数,但通常是一个整数,特别是如果使用wordpress,这大约占互联网上网站的30%,并且查看上面的php代码,它确实是基于wordpress的。黑客要么在注册过程中获得$user\\u id,要么通过暴力猜出$user\\u id,从数字1开始,然后继续2、3、4、5、6。。。。。如果你的网站没有那么多的成员,他们会在不到一天甚至不到一个小时内猜出他们的$user\\u id。
2nd vulnerability
您正在使用MD5哈希函数和注册时间创建一个$code。黑客知道他们什么时候注册的。假设黑客下午3点注册。现在,黑客所要做的就是MD5哈希时间从下午2.55点到下午3.05点,他们将在不到一小时的时间内强制执行$代码。
Looking at the above the hacker can just brute force the $user_id and $code in less than a day and verify an email address that they do not own
啧啧啧啧
更好的方法是使用rand()函数生成$代码,使用大写(A-Z)和小写(A-Z)、数字(0-9)和特殊字符,例如(!&;#)。MD5哈希函数只使用数字0-9和小写字母a-f,而ye根据注册时间使用它的方式使其非常容易缩小范围和暴力攻击。
我已经编写了下面的PHP代码,生成了一个随机的$代码,其中包含大写字母/小写字母/整数/特殊字符。不要让黑客们这么容易。
function generateRandomString($stringLength){
//specify characters to be used in generating random string, do not specify any characters that wordpress does not allow in the creation.
$characters = "0123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_[]{}!@$%^*().,>=-;|:?";
//get the total length of specified characters to be used in generating random string
$charactersLength = strlen($characters);
//declare a string that we will use to create the random string
$randomString = \'\';
for ($i = 0; $i < $stringLength; $i++) {
//generate random characters
$randomCharacter = $characters[rand(0, $charactersLength - 1)];
//add the random characters to the random string
$randomString .= $randomCharacter;
};
//sanitize_user, just in case
$sanRandomString = sanitize_user($randomString);
//check that random string contains Uppercase/Lowercase/Intergers/Special Char and that it is the correct length
if ( (preg_match(\'([a-zA-Z].*[0-9]|[0-9].*[a-zA-Z].*[_\\W])\', $sanRandomString)==1) && (strlen($sanRandomString)==$stringLength) )
{
//return the random string if it meets the complexity criteria
return $sanRandomString;
} else {
// if the random string does not meet minimium criteria call function again
return call_user_func("generateRandomString",($stringLength) );
}
}//end of generateRandomString function
//call the function to generate a random string with Uppercase Letters/Lowercase Letters/Intergers/Special Characters
//into the function we pass the length of string we require, in this exampe it will generate a string 32 characters long
$code = generateRandomString(32);
echo $code;