STARTTLS protocol injection via MITM
Project curl Security Advisory, September 15th 2021 - Permalink
When curl connects to an IMAP, POP3, SMTP or FTP server to exchange data securely using STARTTLS to upgrade the connection to TLS level, the server can still respond and send back multiple responses before the TLS upgrade. Such multiple "pipelined" responses are cached by curl. curl would then upgrade to TLS but not flush the in-queue of cached responses and instead use and trust the responses it got before the TLS handshake as if they were authenticated.
Using this flaw, it allows a Man-In-The-Middle attacker to first inject the fake responses, then pass-through the TLS traffic from the legitimate server and trick curl into sending data back to the user thinking the attacker's injected data comes from the TLS-protected server.
Over POP3 and IMAP an attacker can inject fake response data.
We are not aware of any case of this flaw having been exploited in the wild.
This flaw was first introduced in commit ec3bb8f727405.
The Common Vulnerabilities and Exposures (CVE) project has assigned the name CVE-2021-22947 to this issue.
CWE-349: Acceptance of Extraneous Untrusted Data With Trusted Data
- Affected versions: curl 7.20.0 to and including 7.78.0
- Not affected versions: curl < 7.20.0 and curl >= 7.79.0
Also note that libcurl is used by many applications, and not always advertised as such.
A - Upgrade curl to version 7.79.0
B - Apply the patch to your local version
C - Use IMAPS://, POP3S://, SMTPS:// or FTPS:// with implicit TLS instead of using STARTTLS
This issue was reported to the curl project on September 7, 2021.
This advisory was posted on September 15, 2021.
This issue was reported and patched by Patrick Monnerat.
Thanks a lot!