Use of uninitialized value of in req_parsebody method of lua_request.c
The req_parsebody function in mod_lua left a data pointer uninitialised when an HTTP request carried no body, then passed that pointer to a string search function. A crafted request could make the server read an invalid memory address and crash the process.
- Fixed in 1 hour
- Paid in 1 hour
- Disclosed after 1 hour
Summary by the program
moderate: mod_lua Use of uninitialized value of in r:parsebody (CVE-2022-22719)
A carefully crafted request body can cause a read to a random memory area which could cause the process to crash.
This issue affects Apache HTTP Server 2.4.52 and earlier.
Acknowledgements: Chamal De Silva
Reported to security team: 2021-12-18 fixed by r1898694 in 2.4.x: 2022-03-07 Update 2.4.53 released: 2022-03-14 Affects: <=2.4.52
https://httpd.apache.org/security/vulnerabilities_24.html
The report
###Software Versions Ubuntu - 18.04 64-bit Apache 2.4.51 - 64 bit
Cause of Bug
This bug is present in the req_parsebody method of lua_request.c file.
Below mentioned lines of code cause this bug.
const char *data;
int i;
size_t vlen = 0;
size_t len = 0;
if (lua_read_body(r, &data, (apr_off_t*) &size, max_post_size) != OK) {
return 2;
}
len = strlen(multipart);
i = 0;
for
(
start = strstr((char *) data, multipart);
Note that the const char *data pointer is not initialized with a value.
That pointer is passed to the lua_read_body method to store data sent by HTTP request.
If the HTTP request does not contain any data, then a value will not be set for const char *data pointer.
So const char *data pointer will remain uninitialized.
Then const char *data pointer is passed as a parameter to "strstr" function.
Segmentation fault will happen in "strstr" function, if it cannot access memory pointed by const char *data pointer.
I noticed a difference between Apache 64 bit build and 32 bit build.
64 bit build - Pointer value ofconst char *data pointer is 0x1.
So a Segmentation fault happens in strstr function.
32 bit build - Pointer value of const char *data pointer has a valid memory address.
So Segmentation fault does NOT happen in strstr function.
###Steps
-
Build Apache web server with Lua module
./configure --enable-lua=shared -
Enable Lua module with Apache web server. Add these lines to httpd.conf file.
LoadModule lua_module modules/mod_lua.so
<Files "*.lua">
SetHandler lua-script
</Files>
-
Copy attached F1658382 file to htdocs folder.
-
Start Apache web server in debug single worker mode.
./httpd -X -d /home/apache/install-directory/ -
Send this HTTP request with CURL.
curl -v -X POST -H 'content-type: multipart/form-data;boundary=-' http://127.0.0.1/test.luaApache web server will crash. Note that apache web server is started in single worker mode in step 4.
** I selected Denial of Service (CWE-400) as weakness type. But correct weakness type should be Improper Initialization(CWE-665). It was not available to select.**
Impact
May be used for a denial of service attack.
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 data pointer was declared without an initial value and only filled in when a request body existed, so an empty body left it uninitialised before it was used in a string search.
Impact
The crash could be used for a denial of service attack, though the report notes the fault appeared on a 64-bit build while a 32-bit build did not crash.
What the attacker needed
Mod_lua enabled with a Lua script handler; server running in single worker mode
The fix
The issue was fixed in the 2.4.x branch and released in version 2.4.53.
How it was found
- Build Apache with the Lua module enabled.
- Load the Lua module and map .lua files to the Lua script handler.
- Place the test Lua script in the document root.
- Start the server in single worker debug mode.
- Send a POST request with a multipart form content type and no body, which crashes the server.
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.
A pointer is a variable that holds a memory address. In this code the pointer was never given a value before being used, so it could point anywhere. When the server tried to read from that address it crashed, which means an attacker could knock the service offline.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.