Skip to content
Memory corruption Advisory Advanced CVE-2017-2891

Cesanta Mongoose HTTP Server CGI Remote Code Execcution Vulnerability

A use-after-free exists in Cesanta Mongoose's HTTP server when a POST request targets a CGI script: the original connection structure is freed while the CGI handler still holds a pointer to it. An attacker could send such a request over the network to cause a crash and potentially remote code execution.

Aleksandar Nikolic Follow

Originally disclosed on Cisco Talos

Critical 9.8 View original

An exploitable use-after-free vulnerability exists in the HTTP server implementation of Cesanta Mongoose 6.8. An ordinary HTTP POST request with a CGI target can cause a reuse of previously freed pointer potentially resulting in remote code execution.

Aleksandar Nikolic, on Cisco Talos

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

How it worked

Root cause

The CGI handler stores the original client connection as user_data, but that connection is closed and freed before the CGI event handler later dereferences the stale pointer.

Impact

The freed memory is read and written, which can crash the server and potentially allow remote code execution if multiple carefully controlled POST requests are sent at the right time.

What the attacker needed

CGI support compiled in (default); network access to the server; request target ends with .cgi

How it was found

  1. Send an HTTP POST request whose target ends with the CGI extension to the server.
  2. The server invokes the CGI handler, which allocates a new connection and stores the original connection as user_data.
  3. The original client connection is closed and its structure freed.
  4. When the CGI event handler runs, it dereferences the freed pointer, causing invalid reads and writes.

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 a program finishes with a piece of memory it hands it back to the system, and using it afterwards is a 'use-after-free'. Here the server keeps a pointer to a connection object it has already released, so later code reads and writes memory that may now belong to something else. That can crash the server and, with careful timing and extra requests, may let an attacker run their own code.

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 Aleksandar Nikolic

View all

147 more disclosed reports, best first.

More from Cisco Talos

View all

The newest disclosed reports for this program.

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.