# Elastic: hunt requests in Nginx access logs

Choose one ES|QL query in Kibana Discover:

| Query | Required version | Path handling |
| --- | --- | --- |
| [ai_file_requests_decoded.esql](ai_file_requests_decoded.esql) | Elasticsearch/Kibana 9.2+ | Retains ECS `url.original`, removes a literal query string, and decodes once |
| [ai_file_requests_literal.esql](ai_file_requests_literal.esql) | Elasticsearch/Kibana 8.14+ | Matches ECS `url.path` as ingested; no extra decoding |

## Required data and setup

Install the [Elastic Nginx integration](https://www.elastic.co/docs/reference/integrations/nginx/) and collect access logs with Elastic Agent into the normal `logs-nginx.access-*` data streams. The integration is listed at Basic subscription level. You need permission to read those streams and use ES|QL. Choose a time range in Discover. If your deployment renames data streams, replace only the `FROM` selector after confirming the access-log dataset and ECS fields.

The [documented ingest pipeline](https://github.com/elastic/integrations/blob/main/packages/nginx/data_stream/access/elasticsearch/ingest_pipeline/default.yml) captures the request target and uses `uri_parts`; [ECS](https://www.elastic.co/docs/reference/ecs/ecs-url) defines `url.original` as the original observed target and `url.path` as the path component. Confirm these fields on one actual event before running the hunt. This query is scoped to `event.dataset == "nginx.access"`; a field with the same name in endpoint telemetry is insufficient. No custom index, runtime field, or Deception Check event producer is required.

The decoded query requires a single-valued original target. If it is absent or malformed upstream parsing leaves it unavailable, that event cannot be covered by this variant. `URL_DECODE` returns null with a warning when decoding fails; review warnings and original events separately. The literal variant uses `url.path` as supplied by ingestion and therefore does not promise encoded-path coverage. Neither variant filters on HTTP status. The query retains the source columns and adds original target, matched path, and branch; inspect source identity, server, status, and response context when present. Results are capped at 10,000 rows; use narrower windows for larger sets.

References: [ES|QL syntax](https://www.elastic.co/docs/reference/query-languages/esql/esql-syntax), [8.14 function reference](https://www.elastic.co/guide/en/elasticsearch/reference/8.14/esql-functions-operators.html), [SPLIT](https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/string-functions/split), [MV_FIRST](https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/mv-functions/mv_first), [ENDS_WITH](https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/string-functions/ends_with), [URL_DECODE](https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/string-functions/url_decode), and [9.2 function additions](https://www.elastic.co/search-labs/blog/esql-elasticsearch-9-2-multi-field-joins-ts-command).

## Read the result

`hunt_group` separates the Claude credential filename from the nine configuration filenames. These are case-insensitive hunts for the same ten slash-prefixed path endings as the Sigma rules. Nested deployments match; backup suffixes, trailing slashes, directory-only requests, and filenames appearing only in a query do not. Configuration files may be intentionally public. A request, including a failed request, does not establish file existence, retrieval, secret content, or compromise. Use the investigation steps in the [pack README](../README.md).

## Validation and limits

Experimental, manually authored hunt starters. The exact shipped suffix predicates and request-parser expressions were checked with local positive, negative, and missing-data fixtures. Native query compilation and execution in vendor or customer tenants were not performed. Local Python fixtures are a reference check of selected logic; they do not validate a vendor parser, ingestion pipeline, URL decoder, query engine, performance, or alert configuration.

The decoded variants split at the first literal `?` before one URL-decode pass, retaining the original target. No repeated decoding is performed. Double encoding, escaped access-log representations, semicolon parameters, server rewrites, and prior ingestion decoding can change coverage. Malformed percent encodings and `+` handling require a native test; cross-platform decoder parity is not asserted. Start with a small time range, verify a known safe request in your own access logs, and inspect the original event before promoting the hunt to an alert. Respect platform result limits and narrow the time window when results reach them.

Decoded variants accept origin-form request targets beginning with `/`. Absolute-form proxy targets, authority-only CONNECT targets, and `*` targets require separate handling. This avoids treating a host name as a file path. The Elastic literal variant instead uses the integration's parsed path.

Before the full hunt, run only the source selector and inspect roughly 20 events for the required raw request or ECS fields. In an authorized test location with no such files, verify a request for `/.claude/.credentials.json`, an ordinary page, and `/?name=/.claude/.credentials.json`; only the first should match. Test a failed status as well. Request targets can contain sensitive query values: retain originals in the SIEM, and redact them before sharing a result.
