Repository navigation
Description
Describe the bug
Confused ModSecurity event message in the Windows Application Event Log.
To Reproduce
- Install ModSecurityIIS_2.9.7-64b-64.msi
- Configure ModSecurity for the website
- Open website in a browser
- Check events in the Windows Application Event Log
Actual result
Event message in the Windows Application Event Log:
Log Name: Application Source: ModSecurity Date: 6/23/2025 5:54:11 AM Event ID: 1 Task Category: None Level: Information Keywords: Classic User: N/A Computer: EC2AMAZ-UJ76N58 Description: Incorrect function. Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="ModSecurity" /> <EventID Qualifiers="0">1</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2025-06-23T05:54:11.1744601Z" /> <EventRecordID>42355</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>EC2AMAZ-UJ76N58</Computer> <Security /> </System> <EventData> <Data>ModSecurity for IIS (STABLE)/2.9.7 (http://www.modsecurity.org/) configured.</Data> </EventData> </Event>
Expected behavior
Event message in the Windows Application Event Log:
Log Name: Application Source: ModSecurity Date: 6/23/2025 5:54:11 AM Event ID: 1 Task Category: None Level: Information Keywords: Classic User: N/A Computer: EC2AMAZ-UJ76N58 Description: ModSecurity for IIS (STABLE)/2.9.7 (http://www.modsecurity.org/) configured. Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="ModSecurity" /> <EventID Qualifiers="0">1</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2025-06-23T05:54:11.1744601Z" /> <EventRecordID>42355</EventRecordID> <Correlation /> <Execution ProcessID="0" ThreadID="0" /> <Channel>Application</Channel> <Computer>EC2AMAZ-UJ76N58</Computer> <Security /> </System> <EventData> <Data>ModSecurity for IIS (STABLE)/2.9.7 (http://www.modsecurity.org/) configured.</Data> </EventData> </Event>
Server (please complete the following information):
- ModSecurity version (and connector): 2.9.7 MSI installer
- WebServer: IIS
- OS (and distro): Windows
Activity
[-]Event message with description "Invalid function" in Windows Application Event Log[/-][+]Event message with description "Invalid function" in the Windows Application Event Log[/+]airween commentedon Jun 23, 2025
Hi @skvoboo-gh,
thanks for reporting this issue. As you remember there was an issue with Windows module source code (#3399 - that was also reported by you), so first of all could you check which version you use? I mean the source version (perhaps 2.9.10?).
There was an issue (#3373) which was fixed in #3374 - there the logging mechanism was changed (more precisely: there was a change in logging mechanism in #3192, which was reported in #3373 and fixed in #3374).
May be we should apply this modification (#3374) for Windows too.
skvoboo-gh commentedon Jun 24, 2025
I am using ModSecurity 2.9.7, because this is a latest binary distribution (with MSI installer in assets).
I don't think all the issues you listed above are related to this issue.
I think the root cause of this issue is the lack of registration of the ModSecurity event source in the Windows registry.
airween commentedon Jun 24, 2025
Ah, thanks.
I can try to take a look at that.
A13501350 commentedon Aug 26, 2025
FYI, after testing, adding the following minimal message file in the
/iisfolder resolves the issue:ModSecurity.mc:
Compiled using MSVC with the following commands:
Then add the registry entry pointing to the compiled message file:
Test Results:
The event log now properly displays the messages instead of "Incorrect function":
airween commentedon Aug 26, 2025
Hi @A13501350,
Would you consider sending a PR?
Do you think it's possible to add a new test pipeline with Windows?
Merge pull request #3438 from A13501350/v2/master
A13501350 commentedon Sep 21, 2025
I implemented a CMake-based build system and GitHub Actions CI/CD pipeline for the ModSecurity IIS module on Windows. The CMake setup leverages vcpkg for dependency management, supports both x86 and x64 architectures. The GitHub Actions workflow provides automated packaging using WiX toolset, testing with OWASP Core Ruleset. While the implementation has shown working in initial testing, this pipeline has not undergone comprehensive testing.
1. CMake:
2. Windows CI/CD
See:
https://github.com/A13501350/ModSecurity/actions/runs/17894429285
airween commentedon Sep 21, 2025
Hi @A13501350,
This is AWESOME!
Many thanks for this, I try to add it to our CI soon!
Thanks again!
A13501350 commentedon Sep 21, 2025
Glad you found it useful. This implementation is more of a proof-of-concept, especially the CMake scripts. There are a few additional elements needed for full functionality, such as a proper vcpkg.json manifest file and some modifications to the installer.wxs WiX configuration.
airween commentedon Sep 24, 2025
Thanks. I reviewed that branch and I think that would be very useful. As I see this file does the tasks, right? And you add not just the IIS module build and test but Apache module too, right?
Please send that as a PR (after you remove the commented (unnecessary) lines). Thanks!
A13501350 commentedon Sep 24, 2025
I'm not sure what you mean by the Apache module. I only added the build and test for the IIS module, along with some related modifications, of course.
airween commentedon Sep 25, 2025
Sorry, may be this line confused me, because here you (probably) install Apache2. But may be it needs only because it's necessary to build IIS module?
perlsol commentedon Oct 11, 2025
I am not following the above with reagrds to a fix, but I am getting "Incorrect function" all the time in events for modsecurity.
how can I fix this please
A13501350 commentedon Oct 19, 2025
Yes. The IIS module for ModSecurity v2 essentially wraps the core ModSecurity components, which requires the Apache libraries.
fzipi commentedon Oct 12, 2026
Revisiting this one. "Incorrect function" is
ERROR_INVALID_FUNCTIONformatted through the event-log message path, which means the IIS module is logging a Win32 error code where it meant to log text (or no event at all). @A13501350's IIS series (#3613 through #3631, all open) is where the IIS module is getting attention; this one still needs the exact log call identified. Keeping it open as a 2.x IIS bug.A13501350 commentedon Oct 13, 2026
I believe this issue was caused only by the missing message file, and it has already been fixed in #3438. This issue should be closed.