Project

General

Profile

Actions

Bug #3134

closed

mod_extforward plugin has out-of-bounds (OOB) write of 4-byte -1

Added by povcfe-bug about 3 years ago. Updated about 3 years ago.

Status:
Fixed
Priority:
Normal
Category:
mod_extforward
Target version:
ASK QUESTIONS IN Forums:
No

Description

1. OOB write reproduce(lighttpd-1.4.46-1.4.63)

The OOB write covers lighttpd-1.4.46-1.4.63

1.1 lighttpd configuration

server.document-root = "/var/www/html/" 
server.port = 8080

server.modules += ("mod_extforward")
extforward.headers = ("Forwarded")
extforward.forwarder = ("all" => "trust")

mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
)

1.2 compilation

wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.63.tar.gz
./configure CFLAGS="-m32" 
make
make install

1.3 remote denial of service

2. analysis of the causes of vulnerabilities

The mod_extforward_Forwarded() function of the mod_extforward plugin has a four-byte stack overflow

static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_data *p, buffer *forwarded) {

    int offsets[256];/*(~50 params is more than reasonably expected to handle)*/
    ...
    while (i < used) {
        ...
        // When "j = 255", "offsets[++j] = -1" means "offsets[256] = -1", causing a stack overflow

        if (s[i] == ',') {
            if (j >= (int)(sizeof(offsets)/sizeof(int))) break;
            offsets[++j] = -1; /*("offset" separating params from next proxy)*/
            ++i;
            continue;
        }

3. patch

diff --git a/mod_extforward.c b/mod_extforward-patch.c
index ba957e0..f0a38d4 100644
--- a/mod_extforward.c
+++ b/mod_extforward-patch.c
@@ -715,7 +715,7 @@ static handler_t mod_extforward_Forwarded (request_st * const r, plugin_data * c
         while (s[i] == ' ' || s[i] == '\t') ++i;
         if (s[i] == ';') { ++i; continue; }
         if (s[i] == ',') {
-            if (j >= (int)(sizeof(offsets)/sizeof(int))) break;
+            if (j >= (int)((sizeof(offsets)/sizeof(int)) - 1)) break;
             offsets[++j] = -1; /*("offset" separating params from next proxy)*/
             ++i;
             continue;

Files

1.png (227 KB) 1.png povcfe-bug, 2022-01-05 05:01
lighttpd.conf (314 Bytes) lighttpd.conf povcfe-bug, 2022-01-05 05:09
header.png (105 KB) header.png povcfe-bug, 2022-01-05 09:00
0001-mod_extforward-fix-out-of-bounds-OOB-write-of-4-byte.patch (937 Bytes) 0001-mod_extforward-fix-out-of-bounds-OOB-write-of-4-byte.patch povcfe-bug, 2022-01-05 11:14
#2

Updated by gstrauss about 3 years ago

  • File deleted (exp.py)
#3

Updated by gstrauss about 3 years ago

  • Subject changed from Security - lighttpd mod_extforward plugin has stack overflow vulnerability to lighttpd mod_extforward plugin has out-of-bounds (OOB) write of 4-byte -1
  • Description updated (diff)
  • Status changed from New to Patch Pending
  • Target version changed from 1.4.xx to 1.4.64
#4

Updated by gstrauss about 3 years ago

  • Subject changed from lighttpd mod_extforward plugin has out-of-bounds (OOB) write of 4-byte -1 to mod_extforward plugin has out-of-bounds (OOB) write of 4-byte -1
#10

Updated by povcfe-bug about 3 years ago

#20

Updated by povcfe-bug about 3 years ago

#31

Updated by about 3 years ago

  • Status changed from Patch Pending to Fixed
Actions

Also available in: Atom