Skip to content
Memory corruption Write-up Advanced

XORtigate: Pre-authentication Remote Code Execution on Fortigate VPN (CVE-2023-27997)

A heap overflow in Fortigate SSL VPN's pre-authentication web interface allows an attacker to XOR bytes beyond an allocated buffer with a partially controlled MD5 keystream, leading to remote code execution. The bug is reachable without authentication and can be exploited to overwrite function pointers in an SSL structure.

Charles Fol Follow

Published on blog.lexfo.fr

During a redteam assessment for one of our client, we had the opportunity to look into Fortigate SSL VPN, one of the most used VPN solution worldwide. We discovered a heap overflow bug on the internet-facing interface of the VPN.

Charles Fol (@cfreal_), on blog.lexfo.fr

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

The code compares the hexadecimal length of the input to the decrypted length in raw bytes, allowing the decrypted length to be twice as large as the buffer size.

Impact

An unauthenticated attacker could achieve remote code execution on the VPN appliance, potentially leading to full compromise.

What the attacker needed

Network access to the VPN interface; no authentication required

How it was found

  1. Send a request to /remote/hostcheck_validate with an enc parameter containing a seed, size, and data.
  2. The server decrypts the size and data using a keystream derived from the seed and salt.
  3. Due to the length mismatch, the decryption XORs bytes beyond the allocated buffer.
  4. By repeating the request with carefully chosen seeds and lengths, an attacker can set specific bytes in memory to desired values.
  5. The attacker targets an SSL structure allocated near the buffer and overwrites a function pointer (handshake_func).
  6. Triggering the function pointer leads to code execution.

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 write-up has not been written yet. The Original tab links to the source.

The VPN's login page has a bug where it trusts a length value that is twice as large as it should be, so it writes past the end of a buffer. An attacker can send special requests to change bytes in memory and eventually run their own code on the device.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Charles Fol

View all

8 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.