Skip to content

Instantly share code, notes, and snippets.

@vanhoefm
Created June 11, 2012 11:15
Show Gist options
  • Save vanhoefm/2909627 to your computer and use it in GitHub Desktop.
Save vanhoefm/2909627 to your computer and use it in GitHub Desktop.
Security vulnerability in MySQL/MariaDB sql/password.c
typedef char my_bool;
/*
Check that scrambled message corresponds to the password; the function
is used by server to check that recieved reply is authentic.
RETURN VALUE
0 password is correct
!0 password is invalid
*/
my_bool
check_scramble(const char *scramble_arg, const char *message,
const uint8 *hash_stage2)
{
SHA1_CONTEXT sha1_context;
uint8 buf[SHA1_HASH_SIZE];
uint8 hash_stage2_reassured[SHA1_HASH_SIZE];
mysql_sha1_reset(&sha1_context);
/* create key to encrypt scramble */
mysql_sha1_input(&sha1_context, (const uint8*)message, SCRAMBLE_LENGTH);
mysql_sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE);
mysql_sha1_result(&sha1_context, buf);
/* encrypt scramble */
my_crypt((char*)buf, buf, (const uchar*)scramble_arg, SCRAMBLE_LENGTH);
/* now buf supposedly contains hash_stage1: so we can get hash_stage2 */
mysql_sha1_reset(&sha1_context);
mysql_sha1_input(&sha1_context, buf, SHA1_HASH_SIZE);
mysql_sha1_result(&sha1_context, hash_stage2_reassured);
return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment