|
| 1 | +[[prebuilt-rule-8-16-13-aws-s3-static-site-javascript-file-uploaded]] |
| 2 | +=== AWS S3 Static Site JavaScript File Uploaded |
| 3 | + |
| 4 | +This rule detects when a JavaScript file is uploaded or accessed in an S3 static site directory (`static/js/`) by an IAM user or assumed role. This can indicate suspicious modification of web content hosted on S3, such as injecting malicious scripts into a static website frontend. |
| 5 | + |
| 6 | +*Rule type*: esql |
| 7 | + |
| 8 | +*Rule indices*: None |
| 9 | + |
| 10 | +*Severity*: medium |
| 11 | + |
| 12 | +*Risk score*: 47 |
| 13 | + |
| 14 | +*Runs every*: 5m |
| 15 | + |
| 16 | +*Searches indices from*: now-9m ({ref}/common-options.html#date-math[Date Math format], see also <<rule-schedule, `Additional look-back time`>>) |
| 17 | + |
| 18 | +*Maximum alerts per execution*: 100 |
| 19 | + |
| 20 | +*References*: |
| 21 | + |
| 22 | +* https://www.sygnia.co/blog/sygnia-investigation-bybit-hack/ |
| 23 | +* https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html |
| 24 | +* https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html |
| 25 | + |
| 26 | +*Tags*: |
| 27 | + |
| 28 | +* Domain: Cloud |
| 29 | +* Data Source: AWS |
| 30 | +* Data Source: Amazon Web Services |
| 31 | +* Data Source: AWS S3 |
| 32 | +* Tactic: Impact |
| 33 | +* Use Case: Web Application Compromise |
| 34 | +* Use Case: Cloud Threat Detection |
| 35 | +* Resources: Investigation Guide |
| 36 | + |
| 37 | +*Version*: 1 |
| 38 | + |
| 39 | +*Rule authors*: |
| 40 | + |
| 41 | +* Elastic |
| 42 | + |
| 43 | +*Rule license*: Elastic License v2 |
| 44 | + |
| 45 | + |
| 46 | +==== Investigation guide |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +*Triage and Analysis* |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +*Investigating AWS S3 Static Site JavaScript File Uploaded* |
| 55 | + |
| 56 | + |
| 57 | +An S3 `PutObject` action that targets a path like `static/js/` and uploads a `.js` file is a potential signal for web content modification. If done by an unexpected IAM user or outside of CI/CD workflows, it may indicate a compromise. |
| 58 | + |
| 59 | + |
| 60 | +*Possible Investigation Steps* |
| 61 | + |
| 62 | + |
| 63 | +- **Identify the Source User**: Check `aws.cloudtrail.user_identity.arn`, access key ID, and session type (`IAMUser`, `AssumedRole`, etc). |
| 64 | +- **Review File Content**: Use the S3 `GetObject` or CloudTrail `requestParameters` to inspect the uploaded file for signs of obfuscation or injection. |
| 65 | +- **Correlate to Other Events**: Review events from the same IAM user before and after the upload (e.g., `ListBuckets`, `GetCallerIdentity`, IAM activity). |
| 66 | +- **Look for Multiple Uploads**: Attackers may attempt to upload several files or modify multiple directories. |
| 67 | + |
| 68 | + |
| 69 | +*False Positive Analysis* |
| 70 | + |
| 71 | + |
| 72 | +- This behavior may be expected during app deployments. Look at: |
| 73 | + - The `user_agent.original` to detect legitimate CI tools (like Terraform or GitHub Actions). |
| 74 | + - Timing patterns—does this match a regular release window? |
| 75 | + - The origin IP and device identity. |
| 76 | + |
| 77 | + |
| 78 | +*Response and Remediation* |
| 79 | + |
| 80 | + |
| 81 | +- **Revert Malicious Code**: Replace the uploaded JS file with a clean version and invalidate CloudFront cache if applicable. |
| 82 | +- **Revoke Access**: If compromise is confirmed, revoke the IAM credentials and disable the user. |
| 83 | +- **Audit IAM Policies**: Ensure that only deployment users can modify static site buckets. |
| 84 | +- **Enable Bucket Versioning**: This can allow for quick rollback and historical review. |
| 85 | + |
| 86 | + |
| 87 | +==== Rule query |
| 88 | + |
| 89 | + |
| 90 | +[source, js] |
| 91 | +---------------------------------- |
| 92 | +from logs-aws.cloudtrail* metadata _id, _version, _index |
| 93 | +| where |
| 94 | +
|
| 95 | + // filter on CloudTrail logs for S3 PutObject actions |
| 96 | + event.dataset == "aws.cloudtrail" |
| 97 | + and event.provider == "s3.amazonaws.com" |
| 98 | + and event.action in ("GetObject","PutObject") |
| 99 | +
|
| 100 | + // filter for IAM users, not federated identities |
| 101 | + and aws.cloudtrail.user_identity.type in ("IAMUser", "AssumedRole") |
| 102 | +
|
| 103 | + // filter for S3 static site bucket paths from webpack or similar |
| 104 | + and aws.cloudtrail.request_parameters LIKE "*static/js/*.js*" |
| 105 | +
|
| 106 | + // exclude common IaC tools and automation scripts |
| 107 | + and not ( |
| 108 | + user_agent.original LIKE "*Terraform*" |
| 109 | + or user_agent.original LIKE "*Ansible*" |
| 110 | + or user_agent.original LIKE "*Pulumni*" |
| 111 | + ) |
| 112 | +
|
| 113 | +// extract bucket and object details from request parameters |
| 114 | +| dissect aws.cloudtrail.request_parameters "%{{?bucket.name.key}=%{bucket.name}, %{?host.key}=%{bucket.host}, %{?bucket.object.location.key}=%{bucket.object.location}}" |
| 115 | +
|
| 116 | +// filter for specific bucket and object structure |
| 117 | +| dissect bucket.object.location "%{}static/js/%{bucket.object}" |
| 118 | +
|
| 119 | +// filter for JavaScript files |
| 120 | +| where ENDS_WITH(bucket.object, ".js") |
| 121 | +| keep |
| 122 | + aws.cloudtrail.user_identity.arn, |
| 123 | + aws.cloudtrail.user_identity.access_key_id, |
| 124 | + aws.cloudtrail.user_identity.type, |
| 125 | + aws.cloudtrail.request_parameters, |
| 126 | + bucket.name, |
| 127 | + bucket.object, |
| 128 | + user_agent.original, |
| 129 | + source.ip, |
| 130 | + event.action, |
| 131 | + @timestamp |
| 132 | +
|
| 133 | +---------------------------------- |
| 134 | + |
| 135 | +*Framework*: MITRE ATT&CK^TM^ |
| 136 | + |
| 137 | +* Tactic: |
| 138 | +** Name: Impact |
| 139 | +** ID: TA0040 |
| 140 | +** Reference URL: https://attack.mitre.org/tactics/TA0040/ |
| 141 | +* Technique: |
| 142 | +** Name: Data Manipulation |
| 143 | +** ID: T1565 |
| 144 | +** Reference URL: https://attack.mitre.org/techniques/T1565/ |
| 145 | +* Sub-technique: |
| 146 | +** Name: Stored Data Manipulation |
| 147 | +** ID: T1565.001 |
| 148 | +** Reference URL: https://attack.mitre.org/techniques/T1565/001/ |
0 commit comments