Certainly! Below is a basic example of ModSecurity rules that can help you inspect SOAP requests. These examples illustrate how to:
- Check that the
Content-Type header corresponds to SOAP/XML
- Parse and inspect the request body for some common SOAP attack patterns (e.g., suspicious tags or overly large payloads)
- Detect and block XML External Entity (XXE) attempts and XML bombs with generic patterns
Example ModSecurity Rules for SOAP Inspection
# Enable request body access (needed to inspect XML payload)
SecRequestBodyAccess On
# Force ModSecurity to process XML bodies
SecRequestBodyLimit 13107200
SecRequestBodyNoFilesLimit 13107200
# Rule 1: Only inspect SOAP requests based on Content-Type
SecRule REQUEST_HEADERS:Content-Type "application/soap+xml|text/xml" \
"id:9000001,phase:1,pass,nolog,ctl:requestBodyProcessor=XML"
# Rule 2: Block requests with suspicious external entity declarations (XXE attempts)
SecRule REQUEST_BODY "@rx <!ENTITY" \
"id:9000002,phase:2,deny,msg:'Possible XXE Attack Detected - ENTITY found'"
# Rule 3: Block requests containing DoS attack patterns - XML bombs (billion laughs)
SecRule REQUEST_BODY "@rx (&\w+;){10,}" \
"id:9000003,phase:2,deny,msg:'Possible XML Bomb Detected - Repetitive Entity Expansion'"
# Rule 4: Block SOAP actions that may indicate probing or attacks (example: overly long Action headers)
SecRule REQUEST_HEADERS:SOAPAction "@length > 200" \
"id:9000004,phase:1,deny,msg:'SOAPAction header too long'"
# Rule 5: Example inspecting for suspicious tags (e.g., <script>)
SecRule REQUEST_BODY "@rx <script.*?>" \
"id:9000005,phase:2,deny,msg:'XSS attempt inside SOAP body'"
# Rule 6: Limit maximum size of the SOAP payload (e.g., 1MB) to avoid large DoS
SecRule REQUEST_HEADERS:Content-Length "@gt 1048576" \
"id:9000006,phase:1,deny,msg:'Payload too large'"
# Log some details for SOAP request diagnostics (optional)
SecRule REQUEST_HEADERS:Content-Type "application/soap+xml|text/xml" \
"id:9000007,phase:1,pass,log,msg:'SOAP request detected'"
Explanation:
- Rule 1 enables XML request body processing (important to parse XML).
- Rule 2 tries to catch XML External Entity (XXE) payloads by looking for
<!ENTITY.
- Rule 3 attempts to identify XML bomb attacks by matching repetitive entity references.
- Rule 4 protects against suspiciously large
SOAPAction headers.
- Rule 5 is an example looking for embedded
<script> tags that might indicate cross-site scripting delivered inside SOAP (adjust as needed).
- Rule 6 denies requests with payloads larger than 1MB.
- Rule 7 is just logging SOAP requests for monitoring.
Notes:
- This is a simple example and NOT a complete protective set.
- Real SOAP security might require schema validation, XPath checks, or specialized XML parsing.
- Consider testing thoroughly and tuning the rules for your environment.
- The
ctl:requestBodyProcessor=XML directive tells ModSecurity to treat the request body as XML for parsing purposes.
If you'd like, I can help you expand this with more precise patterns or integrate it into your existing ModSecurity configuration.