|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CWE-307: Improper Restriction of Excessive Authentication Attempts
Description Summary The software does not implement sufficient measures to prevent multiple failed authentication attempts within in a short time frame, making it more susceptible to brute force attacks.
Example 1 In January 2009, an attacker was able to gain administrator access to a Twitter server because the server did not restrict the number of login attempts. The attacker targeted a member of Twitter's support team and was able to successfully guess the member's password using a brute force attack by guessing a large number of common words. Once the attacker gained access as the member of the support staff, he used the administrator panel to gain access to 33 accounts that belonged to celebrities and politicians. Ultimately, fake Twitter messages were sent that appeared to come from the compromised accounts. Example 1 References:
Example 2 The following code, extracted from a servlet's doPost() method, performs an authentication lookup every time the servlet is invoked. (Bad Code) Example
Language: Java String username = request.getParameter("username"); String password = request.getParameter("password"); int authResult = authenticateUser(username, password); However, the software makes no attempt to restrict excessive authentication attempts. Example 3 This code attempts to limit the number of login attempts by causing the process to sleep before completing the authentication. (Bad Code) Example
Language: PHP $username = $_POST['username']; $password = $_POST['password']; sleep(2000); $isAuthenticated = authenticateUser($username, $password); However, there is no limit on parallel connections, so this does not increase the amount of time an attacker needs to complete an attack. Example 4 In the following C/C++ example the validateUser method opens a socket connection, reads a username and password from the socket and attempts to authenticate the username and password. (Bad Code) Example Languages: C and C++ int validateUser(char *host, int port) { int socket = openSocketConnection(host, port);
if (socket < 0) {
printf("Unable to open socket connection");
return(FAIL);
}
int isValidUser = 0;
char username[USERNAME_SIZE];
char password[PASSWORD_SIZE];
while (isValidUser == 0) {
if (getNextMessage(socket, username, USERNAME_SIZE)
> 0) {
if (getNextMessage(socket, password, PASSWORD_SIZE)
> 0) {
isValidUser = AuthenticateUser(username,
password);
}
}
}
return(SUCCESS);
} The validateUser method will continuously check for a valid username and password without any restriction on the number of authentication attempts made. The method should limit the number of authentication attempts made to prevent brute force attacks as in the following example code. (Good Code) Example Languages: C and C++ int validateUser(char *host, int port) { ...
int count = 0;
while ((isValidUser == 0) && (count <
MAX_ATTEMPTS)) {
if (getNextMessage(socket, username, USERNAME_SIZE)
> 0) {
if (getNextMessage(socket, password, PASSWORD_SIZE)
> 0) {
isValidUser = AuthenticateUser(username,
password);
}
}
count++;
}
if (isValidUser) {
return(SUCCESS);
}
else {
return(FAIL);
}
}
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Page Last Updated:
February 20, 2013
|
|
CWE is co-sponsored by the office of Cybersecurity and Communications at the U.S. Department of Homeland Security. This Web site is sponsored and managed by The MITRE Corporation to enable stakeholder collaboration. Copyright © 2006-2013, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. Contact cwe@mitre.org for more information. |
|||



