Skip to content
SQL injection Disclosed report Intermediate CVE-2021-3850

Authentication Bypass in ADOdb/ADOdb

ADOdb's PostgreSQL driver failed to properly escape connection string parameters that were already surrounded by single quotes, allowing an attacker to inject additional connection parameters. This could let an attacker bypass login or access the server's IP address, depending on how the library is used.

ADOdb/ADOdb

Originally disclosed on huntr

Critical View original

Impact

An attacker can inject values into a PostgreSQL connection string by providing a parameter surrounded by single quotes.

Depending on how the library is used in the client software, this may allow an attacker to bypass the login process, gain access to the server's IP address, etc.

Patches

The vulnerability is fixed in ADOdb versions 5.20.21 (952de6c4273d9b1e91c2b838044f8c2111150c29) and 5.21.4 or later (b4d5ce70034c5aac3a1d51d317d93c037a0938d2).

The simplest patch is to delete line 29 in drivers/adodb-postgres64.inc.php:

PHP
diff --git a/drivers/adodb-postgres64.inc.php b/drivers/adodb-postgres64.inc.php
index d04b7f67..729d7141 100644
--- a/drivers/adodb-postgres64.inc.php
+++ b/drivers/adodb-postgres64.inc.php
@@ -26,7 +26,6 @@ function adodb_addslashes($s)
 {
    $len = strlen($s);
    if ($len == 0) return "''";
-   if (strncmp($s,"'",1) === 0 && substr($s,$len-1) == "'") return $s; // already quoted
 
    return "'".addslashes($s)."'";
 }

Workarounds

Ensure the parameters passed to ADOConnection::connect() or related functions (nConnect(), pConnect()) are not surrounded by single quotes.

Credits

Thanks to Emmet Leahy (@meme-lord) of Sorcery Ltd for reporting this vulnerability, and to the huntr team for their support.

References

For more information

If you have any questions or comments about this advisory:

  • Add a note in issue #793
  • Contact the maintainers on Gitter

From the GitHub Advisory Database (GHSA-65mj-7c86-79jf, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The adodb_addslashes function returned the input unchanged if it already started and ended with a single quote, instead of escaping it.

Impact

Depending on how the library is used, an attacker could bypass the login process or gain access to the server's IP address.

What the attacker needed

Attacker controls a connection parameter; parameter is surrounded by single quotes

The fix

The vulnerability was fixed in ADOdb versions 5.20.21 and 5.21.4 by removing the check that skipped escaping for already-quoted strings.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When software connects to a database, it builds a connection string from pieces of text. If a piece of text is not properly cleaned, an attacker can sneak in extra instructions. Here, the library trusted text that already had quotes around it, so an attacker could add their own settings to the connection.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.