Verification codes are mainly used to prevent brute-force cracking, malicious bumping, and automatic submission. I will not describe them here. The types of verification codes include numbers, letters, and even Chinese characters. However, no matter how powerful your verification code is, as long as you make the following mistakes in Form Verification, your verification code will be useless!
The general idea of a Verification Code is to access a script file at the place where you log in each time. This file generates an image containing the verification code and writes the value to the Session, when submitting the verification code, verify the login script to determine whether the submitted verification code is consistent with that in the Session.
The problem arises. After the login password is incorrect, we will not access the file that generates the verification image. If the verification code in the Session is not cleared, the verification code will be the same as the previous one, the verification code mechanism, which has been hard-built, is just a false one.
Next let's take a look at the problematic code:
Logon part:
CODE: <tr>
<Td> Administrator name: Td>
<Td> <input type = "text" name = "username"/> Td>
Tr>
<Tr>
<Td> administrator password: Td>
<Td> <input type = "password" name = "password"/> Td>
Tr>
<Tr>
<Td> Verification Code: Td>
<Td> <input type = "text" name = "captcha" onkeyup = "pressCaptcha (this)"/> Td>
Tr>
<Tr>
<Td colspan = "2" align = "right">
Td>
Tr>
?> There is no problem here. Let's look at the login verification code (I think this verification idea is also used by most people ):
CODE :/*------------------------------------------------------*/
// -- Verify the login information
/*------------------------------------------------------*/
If ($ _ REQUEST ['ac'] = 'signature ')
{
Include ('../includes/cls_captcha.php ');
/* Check whether the verification code is correct */
$ Validator = new captcha ();
If (! $ Validator-> check_word ($ _ POST ['captcha '])
{
Sys_msg ($ _ LANG ['captcha _ error'], 1 );
}
/* Check whether the password is correct */
$ SQL = "SELECT user_id, user_name, password, action_list FROM". $ ecs-> table ('admin _ user ').
"WHERE user_name = '$ _ POST [username]' AND password = '". md5 ($ _ POST ['Password']). "'";
$ Row = $ db-> GetRow ($ SQL );
If ($ row)
{
// Login successful
Set_admin_session ($ row ['user _ id'], $ row ['user _ name'], $ row ['Action _ list']);
// Update the Last Logon Time and IP address
$ Db-> Execute ("UPDATE". $ ecs-> table ('admin _ user ').
"SET last_time = '". date ('Y-m-d H: I: s', time ()). "', last_ip = '". real_ip (). "'".
"WHERE user_id = $ _ SESSION [admin_id]") OR die ($ db-> ErrorMsg ());
If (isset ($ _ POST ['member'])
{
Setcookie ('ecscp [admin_id] ', $ row [0], time () + 3600*24*360 );
Setcookie ('ecscp [admin_pass] ', md5 ($ row ['Password']. $ _ CFG ['hash _ Code']), time () + 3600*24*360 );
}
Header ('location :./');
}
Else
{
Sys_msg ($ _ LANG ['login _ faild'], 1 );
}
}
?> The problem lies in the above Code. After checking the incorrect password, the verification code is not updated, so that we can remove the verification code image on the login page, if you use a URL to access the verification code page, you can submit the user name, password, and the verification code you just obtained to implement brute-force cracking. Using this method, you can also implement irrigation and ticket flushing.
You can see the following picture to enhance your understanding.
= 700) window. open ('HTTP: // www.bkjia.com/uploads/alliance131016/05251961k-0.gif'); "src =" http://www.bkjia.com/uploads/allimg/131016/05251961K-0.gif "onload =" if (this. width> '200') this. width = '000000'; if (this. height> '20140901') this. height = '000000'; "border = 0>
Solution: We need to update the verification code after checking the incorrect password. For messages and other types, we also need to update the verification code after the submission is successful.
Security is like this. We always want to make our programs safer, but in general, we can't jump out of the conventional thinking, as a result, many "unconventional vulnerabilities" or "defects" occur in our programs. In short, they are not perfect. In addition to pointing out the problem above, I also hope that everyone can take action and re-examine their programs with an "unconventional" vision, post more small issues that have not been found before, so that everyone can improve them together!