
I tried the AWS WAF rules to mitigate PHP2Shell introduced in the AWS Security Bulletin (2026-143-AWS) and the AWS Security Blog
This page has been translated by machine translation. View original
Introduction
For two PHP vulnerabilities (commonly known as PHP2Shell: CVE-2026-109618 and CVE-2026-109619), AWS Security Bulletin 2026-143-AWS provides information on affected PHP versions and fixed versions, as well as AWS WAF rules as an interim measure for cases where immediate updates are not possible.
Additionally, the AWS Security Blog introduces mitigation measures using AWS WAF.
This time, we applied the two rules introduced as PHP2Shell mitigations (PHP2Shell and Block-Oversize-Body) to a test ALB and used curl to verify the following three points, and we present the results.
- The difference between requests that are blocked and requests that pass through
- Results when PHP_SESSION_UPLOAD_PROGRESS is located after the first 8 KB of the body
- Conditions under which non-attack requests are blocked
The Two Rules Provided by AWS
The AWS Security Bulletin lists one rule per CVE as interim measures when using AWS WAF. The custom rule PHP2Shell is for CVE-2026-109619, and SizeRestrictions_BODY, included in the AWS Managed Rules Core Rule Set (CRS), is for CVE-2026-109618.
PHP2Shell
The following is the rule definition published in the bulletin.
{
"Name": "PHP2Shell",
"Priority": 0,
"Statement": {
"AndStatement": {
"Statements": [
{
"ByteMatchStatement": {
"SearchString": "POST",
"FieldToMatch": { "Method": {} },
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }],
"PositionalConstraint": "EXACTLY"
}
},
{
"OrStatement": {
"Statements": [
{
"ByteMatchStatement": {
"SearchString": "PHPSESSID",
"FieldToMatch": {
"Cookies": {
"MatchPattern": { "All": {} },
"MatchScope": "KEY",
"OversizeHandling": "CONTINUE"
}
},
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }],
"PositionalConstraint": "EXACTLY"
}
},
{
"ByteMatchStatement": {
"SearchString": "PHPSESSID",
"FieldToMatch": { "Body": { "OversizeHandling": "CONTINUE" } },
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }],
"PositionalConstraint": "CONTAINS"
}
}
]
}
},
{
"ByteMatchStatement": {
"SearchString": "PHP_SESSION_UPLOAD_PROGRESS",
"FieldToMatch": { "Body": { "OversizeHandling": "CONTINUE" } },
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }],
"PositionalConstraint": "CONTAINS"
}
}
]
}
},
"Action": { "Block": {} },
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "PHP2Shell"
}
}
This blocks requests that satisfy all three of the following conditions.
- Method is POST
- Cookie key exactly matches PHPSESSID, or body contains PHPSESSID
- Body contains PHP_SESSION_UPLOAD_PROGRESS
From the definition, the following can be read.
- String comparison is case-sensitive (TextTransformations is NONE)
- There is no condition on Content-Type
- Body OversizeHandling is CONTINUE. Judgment is made by looking only at the range that WAF can inspect (first 8 KB for ALB)
Block-Oversize-Body
Block-Oversize-Body is a rule that blocks requests where the body exceeds 8,192 bytes (8 KB), and it only looks at the body size. It is published as a custom rule on the AWS Security Blog.
The AWS Security Bulletin introduces SizeRestrictions_BODY from CRS, which performs the same function.
The custom rule (Block-Oversize-Body) is superior in terms of WCU savings (700 for CRS), customizability, and log traceability.
For those already using CRS (AWSManagedRulesCommonRuleSet), the AWS Security Blog also states that SizeRestrictions_BODY performs the same function.
The verification template includes this custom rule. The name on the Blog is Block-Oversize-Body, and the name in the template is block-oversize-body. The following JSON is the template rule with the custom 403 response (the setting that returns the rule name) removed. The name and priority are the same values as in the template. For the metric name, the template prepends the WebACL name.
{
"Name": "block-oversize-body",
"Priority": 5,
"Statement": {
"SizeConstraintStatement": {
"FieldToMatch": { "Body": { "OversizeHandling": "MATCH" } },
"ComparisonOperator": "GT",
"Size": 8192,
"TextTransformations": [{ "Priority": 0, "Type": "NONE" }]
}
},
"Action": { "Block": {} },
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "block-oversize-body"
}
}
Unlike PHP2Shell, the body OversizeHandling is MATCH. The AWS Security Blog explains that this is specified to also target bodies that exceed the inspection limit.
The previous version of the template (commit cd6bafd) had CRS SizeRestrictions_BODY at priority 5. Even in the current version replaced with block-oversize-body, the matches for the same shaped requests and the position where the rule blocking at the 8 KB boundary switches were the same as the previous version.
WAF log recording was split into two places in the previous version.
- Previous version (CRS SizeRestrictions_BODY)
- The rule name aws-crs-size-restrictions-body attached to the WebACL appeared in nonTerminatingMatchingRules (Count configuration) or terminatingRuleId (Block configuration)
- The rule ID SizeRestrictions_BODY within the managed rule group appeared in ruleGroupList. In Count configuration, even though requests passed with a 200 response, the terminatingRule action in ruleGroupList was recorded as BLOCK
- block-oversize-body
- The rule name appears in one place: nonTerminatingMatchingRules (Count configuration) or terminatingRuleId (Block configuration). The action matches the request result: COUNT for Count configuration, BLOCK for Block configuration. When blocked, 403 is also recorded in responseCodeSent
Verification Environment
This verification environment is available as a CloudFormation template and can be reproduced from the GitHub repository (commit febe2c7).
The template creates a new WebACL containing the above two rules and associates it with the ALB specified by LoadBalancerArn. The main parameters mentioned in the body are as follows.
- BlockPhpUploadProgress=true (default value) adds PHP2Shell. The name is block-php-upload-progress, priority is 4. The action follows RuleAction, and when blocking, it returns the rule name with a 403. Everything else is the same as the definition in the AWS Security Bulletin
- BlockLargeBody=true (default is false) adds block-oversize-body
- RuleAction=Count sets all rules in the WebACL to Count. Count records matches in WAF logs and metrics while allowing the request through. Use this to check the impact before switching to Block
Deployment command (example of deploying with RuleAction=Count)
This is the deployment example from the README with one line added for BlockLargeBody=true. This assumes a test ALB. If another WebACL is attached to the ALB, the association will be replaced by this WebACL. AllowedCountries=JP is the setting for the country-based rule that blocks POST requests from outside Japan. The template also includes a rate limiting rule. Before switching RuleAction to Block, please also verify the impact of these rules.
aws cloudformation deploy \
--stack-name waf-post-guard \
--template-file template.yaml \
--region ap-northeast-1 \
--parameter-overrides \
AllowedCountries=JP \
RuleAction=Count \
BlockLargeBody=true \
LoadBalancerArn=arn:aws:elasticloadbalancing:REGION:ACCOUNT_ID:loadbalancer/app/NAME/ID
The ALB is located in the Tokyo region. Since the HTTPS listener uses a self-signed certificate, -k is appended to curl. Unless otherwise noted, the following results are from a configuration with RuleAction=Block, BlockPhpUploadProgress=true, and BlockLargeBody=true (the deployment example uses RuleAction=Count). Which rule blocked each request was confirmed via the x-waf-blocked-by header in the 403 response (which contains the rule name) and WAF logs. Each request was sent once.
Verifying PHP2Shell Conditions with curl
We sent a POST satisfying all three PHP2Shell conditions and POSTs with one condition removed via curl, and checked the response codes.
# Cookie PHPSESSID + PHP_SESSION_UPLOAD_PROGRESS in body
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "https://<ALB DNS name>/" \
-b "PHPSESSID=dummy" \
-F "PHP_SESSION_UPLOAD_PROGRESS=dummy" \
-F "a=b"
# Both as body fields
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "https://<ALB DNS name>/" \
-F "PHPSESSID=dummy" \
-F "PHP_SESSION_UPLOAD_PROGRESS=dummy" \
-F "a=b"
| Request | Result |
|---|---|
| POST, Cookie PHPSESSID, PHP_SESSION_UPLOAD_PROGRESS in body | 403 |
| POST, PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS in body | 403 |
| POST, multiple cookies (a=1; PHPSESSID=x), PHP_SESSION_UPLOAD_PROGRESS in body | 403 |
| POST, PHP_SESSION_UPLOAD_PROGRESS in body only | 200 |
| POST, Cookie PHPSESSID only | 200 |
| PUT, PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS in body | 200 |
A POST with a multipart body manually assembled using --data-binary instead of -F also returned 403, same as the first command.
PHP2Shell Only Inspects the First 8 KB of the Body
Allowed requests, including parts that were not inspected, are forwarded as-is in their entirety to the backend behind the ALB.
With block-oversize-body removed (BlockLargeBody=false, RuleAction=Block), we sent multipart POSTs. The body placed PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS (both with value dummy) after a large pad field, varying only the position of PHP_SESSION_UPLOAD_PROGRESS. The values in the table represent the end position of PHP_SESSION_UPLOAD_PROGRESS, with 0 at the start of the body.
| End position of PHP_SESSION_UPLOAD_PROGRESS (bytes) | Result with PHP2Shell only |
|---|---|
| 8,183 | 403 |
| 8,191 | 403 |
| 8,193 | 200 |
| 8,237 | 200 |
POSTs where PHP_SESSION_UPLOAD_PROGRESS fit within the first 8,192 bytes returned 403, and those that did not returned 200.
With block-oversize-body also set to Block (BlockLargeBody=true), we sent the same shaped POSTs with varying total body sizes, and the blocking rule was split based on the position of the two strings.
| Total body size (bytes) | Position of the two strings | Blocking rule |
|---|---|---|
| 8,106, 8,196, 8,206 | Within first 8,192 bytes | block-php-upload-progress (PHP2Shell) |
| 8,256–9,206 | End of PHP_SESSION_UPLOAD_PROGRESS is past 8,192 bytes | block-oversize-body |
The 8,196-byte and 8,206-byte POSTs also satisfy the block-oversize-body condition (over 8,192 bytes). However, block-php-upload-progress at priority 4 is evaluated before block-oversize-body at priority 5 and blocks them first.
The publicly available PoC takes the latter form. From reading the source (without executing it), the multipart body places PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS after more than 1,000 dummy fields, followed by a file and a large field. When we sent a 1,056,388-byte POST reproducing this order with harmless dummy values (the two strings located approximately 56 KB from the start of the body), it was blocked with 403 by block-oversize-body.
Conditions Under Which Non-Attack Requests Are Blocked
Legitimate requests exceeding 8 KB are also blocked by block-oversize-body
When the following 5 types were sent in Count configuration (RuleAction=Count), all responses were 200. The WAF log recorded all 5 as matching block-oversize-body (nonTerminatingMatchingRules).
| Request | Body size |
|---|---|
| JSON POST | 20,013 bytes |
| Image upload (multipart POST) | 102,710 bytes |
| PUT | 15,000 bytes |
| PATCH | 15,000 bytes |
| GET with JSON body | 20,013 bytes |
With RuleAction=Block, these were all blocked with 403.
We also verified with RuleAction=Block for sizes around the threshold (8,192 bytes) and body sizes significantly exceeding the WAF inspection range (first 8,192 bytes). These are the results of sending harmless urlencoded POSTs with only the body size varied.
| Body size (bytes) | Result |
|---|---|
| 8,191 | 200 |
| 8,192 | 200 |
| 8,193 | 403 |
| 1,048,576 | 403 |
| 5,242,880 | 403 |
For POSTs of 8,193 bytes or more, REQUEST_BODY was recorded in oversizeFields in the WAF log. The inspected range (requestBodySizeInspectedByWAF) was 8,192 bytes.
JSON and text/plain bodies are also blocked by PHP2Shell
The following two POSTs both returned 403.
- Content-Type of application/json, body of
{"PHPSESSID":"dummy","PHP_SESSION_UPLOAD_PROGRESS":"dummy"} - Content-Type of text/plain, body of
PHPSESSID=dummy PHP_SESSION_UPLOAD_PROGRESS=dummy
For example, if a form for posting PHP tutorial articles contains both of these strings in the body text, that POST would also be blocked.
We also tested a rule that adds a condition "Content-Type header contains multipart/form-data" as an AND to the AWS Security Bulletin rule. This rule compares Content-Type in lowercase. Adding it to the WebACL in Count mode and sending a multipart POST and the above two POSTs, this rule matched the multipart POST but did not match the JSON or text/plain POSTs. It also did not match a POST sent with --data-binary without specifying Content-Type (curl adds application/x-www-form-urlencoded). This rule has a narrower blocking range than the bulletin's definition. A rule that does not convert to lowercase (case-sensitive) did not match a POST with Content-Type of Multipart/Form-Data.
When block-multipart-post in the Template Is Enabled
The template also includes a rule called block-multipart-post (enabled with BlockMultipartPost=true; disabled by default). This is a rule that blocks any POST containing multipart/form-data in Content-Type, regardless of size or content. It is based on the Block-Multipart-FormData from the AWS Security Blog with a POST condition added. It will also block legitimate file uploads and multipart form submissions.
We examined how block-php-upload-progress (PHP2Shell) and block-oversize-body overlap when this rule is enabled. With BlockMultipartPost=true and RuleAction=Count, we sent 3 types of multipart POSTs and tabulated the matches recorded in the WAF log (— indicates no match).
| Request | block-multipart-post | block-php-upload-progress (PHP2Shell) | block-oversize-body |
|---|---|---|---|
| multipart POST, Cookie PHPSESSID, PHP_SESSION_UPLOAD_PROGRESS in body | Match | Match | — |
| Normal multipart POST | Match | — | — |
| multipart POST reproducing PoC order (1,056,388 bytes) | Match | — | Match |
block-multipart-post is evaluated before block-php-upload-progress and block-oversize-body. When enabled with RuleAction=Block, multipart POSTs are stopped here and evaluation does not proceed to subsequent rules. The reason multiple matches appear in the table is that evaluation continued in Count mode. When disabled, normal multipart POSTs that do not contain the two strings pass through if the body is 8,192 bytes or less. Those exceeding 8 KB (such as 102,710-byte image uploads) are blocked by block-oversize-body.
Summary
AWS Security Bulletin 2026-143-AWS and the AWS Security Blog introduce AWS WAF rules as interim measures for two PHP vulnerabilities. We verified PHP2Shell and Block-Oversize-Body of those rules on an ALB.
If you are considering adopting these two rules as AWS WAF mitigations, we hope the evaluation results presented here will serve as a reference.
However, please note that WAF rules are interim measures, and the fundamental solution is to update PHP to the fixed versions (8.5.12, 8.4.27, 8.3.36, 8.2.35).
The following AWS Security Blog article summarizes countermeasures using AWS WAF rules and PHP-side configurations. We recommend referring to it as well.
The background on how Amazon Threat Intelligence confirmed exploitation before the vulnerability was disclosed, along with recommended responses, can be found in the following article.
