Application Security

MySQL Authentication Bypass Offers Lesson for Developers

Last month, a spotlight was put on a MySQL authentication bypass vulnerability that gave hackers a one out of 256 chance to gain access to the database regardless of whether or not they entered the wrong password. Versions of MariaDB were also affected by the bug, which Rapid7’s HD Moore at the time called “tragically comedic.” However, application firm Coverity said the situation also presents a learning opportunity for developers.

<p>Last month, a <a href="https://www.securityweek.com/mysql-authentication-flaw-easy-exploit-researchers-say">spotlight was put</a> on a MySQL authentication bypass vulnerability that gave hackers a one out of 256 chance to gain access to the database regardless of whether or not they entered the wrong password. Versions of MariaDB were also affected by the bug, which Rapid7's HD Moore at the time called "tragically comedic." However, application firm <strong>Coverity</strong> said the situation also presents a learning opportunity for developers.</p>

Last month, a spotlight was put on a MySQL authentication bypass vulnerability that gave hackers a one out of 256 chance to gain access to the database regardless of whether or not they entered the wrong password. Versions of MariaDB were also affected by the bug, which Rapid7’s HD Moore at the time called “tragically comedic.” However, application firm Coverity said the situation also presents a learning opportunity for developers.

According to Coverity CTO Andy Chou, one of the company’s engineers wrote a static analysis checker to find truncation of memcmp, strcmp and stmcmp return values or cases whether the return value was tested against constraints other than zero. After running the checker over 6,286 open source projects totaling more than 330 million lines of code, they found 15 other defects along the same lines of the one found in MySQL.

The packages examined by Coverity were versions of: Nmap, Nawm, Olsrd, Ncbi-tools, OpenBabel, Wine, Yersinia and Gambas. Each of the packages was from a Debian 5.0 distribution, and many of the issues have either been fixed or have a patch on the way. Still, developers can avoid these types of bugs altogether by not truncating the return value when it comes to using comparison functions like memcmp and strcmp, Chou argued in a blog post detailing the findings.

“These bugs are all caused by misunderstanding the behavior of functions that compare memory regions or strings,” he explained to SecurityWeek. “The problem is that the value returned from these comparison functions is sometimes misunderstood by developers, so they make mistakes like thinking these functions can return only -1, 0, or 1.  Or, they might think the return value can be safely cast to a smaller type such as char, but they don’t realize that the truncation of the value might result in two memory regions being considered equal when they aren’t.”

“If these memory regions represent password hashes, this can lead to a vulnerability like the one in MySQL (CVE-2012-2122),” he said.

Some of the bugs could be classified as integer truncation issues that result in authentication bypass, but the effect from a security standpoint depends on where the defect occurs in the code, he said. In most cases, Coverity found potential for program logic errors, but not actual security vulnerabilities.

The good news is these bugs are very rare, he said.

” We only found 16 defect instances in 330 million lines of code – that’s only one bug per 20 million lines of code,” Chou noted. “When they do make mistakes, they often think that these functions might only return -1, 0, or 1 because that’s actually true on some platforms. Unfortunately, it’s not true everywhere.”

Advertisement. Scroll to continue reading.

Related Content

Copyright © 2024 SecurityWeek ®, a Wired Business Media Publication. All Rights Reserved.

Exit mobile version