Skip to content

Commit daf90f2

Browse files
chemamartinezagithomas
authored andcommitted
microsoft_defender_endpoint: add support for oauth endpoint params (elastic#15667)
Add support for the oauth_endpoint_params configuration parameter for all available data streams. Log data stream still works under httpjson so the option has been added under data stream level along with all the OAuth2 options for this data stream. For the another data streams, as they work under the CEL input, it has been added at input level so adding any value to this option will affect all data streams that rely on CEL (machine, machine_action, and vulnerability). Finally, the auth logic for the vulnerability data stream is implemented in the CEL program instead of delegate in the CEL auth options for the input. Therefore, the oauth endpoint params in this case are added manually in the program as well.
1 parent 0c704c3 commit daf90f2

File tree

19 files changed

+364
-151
lines changed

19 files changed

+364
-151
lines changed

packages/microsoft_defender_endpoint/_dev/deploy/docker/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
- ${SERVICE_LOGS_DIR}:/var/log
88
command: /bin/sh -c "cp /sample_logs/* /var/log/"
99
microsoft-defender-mock:
10-
image: docker.elastic.co/observability/stream:v0.18.0
10+
image: docker.elastic.co/observability/stream:v0.20.0
1111
ports:
1212
- 8080
1313
volumes:
@@ -19,7 +19,7 @@ services:
1919
- --addr=:8080
2020
- --config=/config.yml
2121
microsoft-defender-endpoint-vulnerability-cel:
22-
image: docker.elastic.co/observability/stream:v0.18.0
22+
image: docker.elastic.co/observability/stream:v0.20.0
2323
ports:
2424
- 8080
2525
volumes:

packages/microsoft_defender_endpoint/_dev/deploy/docker/http-mock-config.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ rules:
1616
- "application/json"
1717
body: |-
1818
{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrN","token_type": "Bearer","not_before": 1549647431,"expires_in": 3600,"resource": "f2a76e08-93f2-4350-833c-965c02483b11"}
19+
# Refresh token to get access token: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#refresh-the-access-token
20+
- path: /tenant_id/oauth2/token
21+
methods: [ POST ]
22+
query_params:
23+
refresh_token: refresh_token_123
24+
grant_type: refresh_token
25+
request_headers:
26+
Authorization:
27+
- "Basic dGVzdC1hcHAtaWQ6dGVzdC1zZWNyZXQ="
28+
Content-Type:
29+
- "application/x-www-form-urlencoded"
30+
responses:
31+
- status_code: 200
32+
headers:
33+
Content-Type:
34+
- "application/json"
35+
body: |-
36+
{{ minify_json `
37+
{
38+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrN",
39+
"token_type": "Bearer",
40+
"expires_in": 2,
41+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
42+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
43+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD..."
44+
}
45+
`}}
1946
- path: /api/alerts
2047
methods: [GET]
2148
query_params:
@@ -152,6 +179,34 @@ rules:
152179
- "application/json"
153180
body: |-
154181
{"token_type":"Bearer","expires_in":"3599","ext_expires_in":"3599","expires_on":"1924905600","not_before":"1730182638","resource":"https://management.azure.com/","access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrN"}
182+
# Refresh token to get access token: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#refresh-the-access-token
183+
- path: /tenant-id/oauth2/v2.0/token
184+
methods: [ POST ]
185+
query_params:
186+
scope: 'https://securitycenter.onmicrosoft.com/windowsatpservice/.default'
187+
refresh_token: refresh_token_123
188+
grant_type: refresh_token
189+
request_headers:
190+
Authorization:
191+
- "Basic dGVzdC1jZWwtY2xpZW50LWlkOnRlc3QtY2VsLWNsaWVudC1zZWNyZXQ="
192+
Content-Type:
193+
- "application/x-www-form-urlencoded"
194+
responses:
195+
- status_code: 200
196+
headers:
197+
Content-Type:
198+
- "application/json"
199+
body: |-
200+
{{ minify_json `
201+
{
202+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrN",
203+
"token_type": "Bearer",
204+
"expires_in": 2,
205+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
206+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
207+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD..."
208+
}
209+
`}}
155210
- path: /api/machineactions
156211
methods: ["GET"]
157212
request_headers:

packages/microsoft_defender_endpoint/_dev/deploy/docker/vulnerability-http-mock-config.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ rules:
88
- "application/json"
99
body: |-
1010
{"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"topsecretaccesstokenthatshouldnotbeleakedforabit"}
11+
# Refresh token to get access token: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#refresh-the-access-token
12+
- path: /tenant_id/oauth2/token
13+
methods: [ POST ]
14+
query_params:
15+
refresh_token:
16+
- refresh_token_1
17+
- refresh_token_2
18+
grant_type: refresh_token
19+
request_headers:
20+
Authorization:
21+
- "Basic dGVzdC1hcHAtaWQ6dGVzdC1zZWNyZXQ="
22+
Content-Type:
23+
- "application/x-www-form-urlencoded"
24+
responses:
25+
- status_code: 200
26+
headers:
27+
Content-Type:
28+
- "application/json"
29+
body: |-
30+
{{ minify_json `
31+
{
32+
"access_token": "topsecretaccesstokenthatshouldnotbeleakedforabit",
33+
"token_type": "Bearer",
34+
"expires_in": 2,
35+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
36+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
37+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD..."
38+
}
39+
`}}
1140
- path: /api/machines/SoftwareVulnerabilitiesExport
1241
methods: ["GET"]
1342
query_params:

packages/microsoft_defender_endpoint/changelog.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# newer versions go on top
2+
- version: "4.1.0"
3+
changes:
4+
- description: Add support for OAuth2 Endpoint Params option.
5+
type: enhancement
6+
link: https://github.com/elastic/integrations/pull/15667
27
- version: "4.0.0"
38
changes:
49
- description: |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
service: microsoft-defender-mock
2+
input: httpjson
3+
data_stream:
4+
vars:
5+
client_id: test-app-id
6+
client_secret: test-secret
7+
tenant_id: tenant_id
8+
login_url: http://{{Hostname}}:{{Port}}
9+
request_url: http://{{Hostname}}:{{Port}}/api/alerts
10+
enable_request_tracer: true
11+
oauth_endpoint_params: |
12+
grant_type: refresh_token
13+
refresh_token: 'refresh_token_123'
14+
assert:
15+
hit_count: 3

packages/microsoft_defender_endpoint/data_stream/log/agent/stream/httpjson.yml.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ auth.oauth2.scopes:
1616
auth.oauth2.provider: azure
1717
auth.oauth2.azure.resource: {{azure_resource}}
1818
{{/if}}
19+
{{#if oauth_endpoint_params}}
20+
auth.oauth2.endpoint_params: {{oauth_endpoint_params}}
21+
{{/if}}
1922
request.url: {{request_url}}
2023
request.method: GET
2124
{{#if proxy_url }}

packages/microsoft_defender_endpoint/data_stream/log/manifest.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ streams:
9494
default: oauth2/token
9595
description: "Microsoft supports multiple Oauth2 URL endpoints, the default is oauth2/token, but can also be oauth2/v2.0/token"
9696
secret: false
97+
- name: oauth_endpoint_params
98+
type: yaml
99+
title: OAuth2 Endpoint Params
100+
description: Endpoint Params used for OAuth2 authentication as YAML. See [documentation](https://www.elastic.co/docs/reference/beats/filebeat/filebeat-input-httpjson#_auth_oauth2_endpoint_params_2) for details.
101+
show_user: false
102+
multi: false
103+
required: false
97104
- name: request_url
98105
type: text
99106
title: Security Center URL
Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,97 @@
11
{
2-
"@timestamp": "2025-09-08T14:14:17.520Z",
2+
"@timestamp": "2025-10-16T10:42:06.592Z",
33
"agent": {
4-
"ephemeral_id": "3f082892-0f6c-45a1-aa4d-4887bd3462c8",
5-
"id": "36f3bbaf-2d4f-4f3c-af1f-4c13524514f5",
6-
"name": "elastic-agent-19107",
4+
"ephemeral_id": "b43b835d-ba25-4ad7-aa9f-200c15733e48",
5+
"id": "353e6432-27a9-40a4-98a2-557dbb69496b",
6+
"name": "elastic-agent-48674",
77
"type": "filebeat",
8-
"version": "8.19.0"
8+
"version": "8.19.3"
99
},
1010
"cloud": {
1111
"account": {
12-
"id": "123543-d66c-4c7e-9e30-40034eb7c6f3"
12+
"id": "a839b112-1253-6432-9bf6-94542403f21c"
1313
},
1414
"instance": {
15-
"id": "c5a964f417c11f6277d5bf9489f0d"
15+
"id": "111e6dd8c833c8a052ea231ec1b19adaf497b625"
1616
},
1717
"provider": "azure"
1818
},
1919
"data_stream": {
2020
"dataset": "microsoft_defender_endpoint.log",
21-
"namespace": "61125",
21+
"namespace": "90146",
2222
"type": "logs"
2323
},
2424
"ecs": {
2525
"version": "8.11.0"
2626
},
2727
"elastic_agent": {
28-
"id": "36f3bbaf-2d4f-4f3c-af1f-4c13524514f5",
28+
"id": "353e6432-27a9-40a4-98a2-557dbb69496b",
2929
"snapshot": false,
30-
"version": "8.19.0"
30+
"version": "8.19.3"
3131
},
3232
"event": {
33-
"action": "Malware",
33+
"action": "Execution",
3434
"agent_id_status": "verified",
3535
"category": [
36-
"host",
37-
"malware"
36+
"host"
3837
],
39-
"created": "2020-06-30T10:09:01.1569718Z",
38+
"created": "2021-01-26T20:33:57.7220239Z",
4039
"dataset": "microsoft_defender_endpoint.log",
41-
"duration": 0,
42-
"end": "2020-06-30T10:07:44.333733Z",
43-
"id": "da637291085411733957_-1043898914",
44-
"ingested": "2025-09-08T14:14:20Z",
40+
"duration": 101466100,
41+
"end": "2021-01-26T20:31:33.0577322Z",
42+
"id": "da637472900382838869_1364969609",
43+
"ingested": "2025-10-16T10:42:09Z",
4544
"kind": "alert",
4645
"provider": "defender_endpoint",
4746
"severity": 21,
48-
"start": "2020-06-30T10:07:44.333733Z",
47+
"start": "2021-01-26T20:31:32.9562661Z",
4948
"timezone": "UTC",
5049
"type": [
51-
"end"
50+
"access",
51+
"start"
5252
]
5353
},
54-
"file": {
55-
"name": "SB.xsl",
56-
"path": "C:\\Windows\\Temp\\sb-sim-temp-ikyxqi\\sb_10554_bs_h4qpk5"
57-
},
5854
"host": {
59-
"hostname": "testserver4",
60-
"id": "c5a964f417c11f6277d5bf9489f0d",
61-
"name": "testserver4"
55+
"hostname": "temp123.middleeast.corp.microsoft.com",
56+
"id": "111e6dd8c833c8a052ea231ec1b19adaf497b625",
57+
"name": "temp123.middleeast.corp.microsoft.com"
6258
},
6359
"input": {
64-
"type": "log"
65-
},
66-
"log": {
67-
"file": {
68-
"path": "/tmp/service_logs/defender_atp-test.json.log"
69-
},
70-
"offset": 0
60+
"type": "httpjson"
7161
},
72-
"message": "An active 'Exeselrun' malware was detected",
62+
"message": "Low-reputation arbitrary code executed by signed executable",
7363
"microsoft": {
7464
"defender_endpoint": {
7565
"assignedTo": "[email protected]",
7666
"evidence": {
77-
"entityType": "File"
67+
"aadUserId": "11118379-2a59-1111-ac3c-a51eb4a3c627",
68+
"accountName": "name",
69+
"domainName": "DOMAIN",
70+
"entityType": "User",
71+
"userPrincipalName": "[email protected]"
7872
},
79-
"incidentId": "12",
80-
"investigationId": "9",
81-
"investigationState": "Benign",
82-
"lastUpdateTime": "2020-07-03T15:15:39.13Z",
83-
"resolvedTime": "2020-06-30T11:13:12.2680434Z",
84-
"status": "Resolved"
73+
"incidentId": "1126093",
74+
"investigationState": "Queued",
75+
"lastUpdateTime": "2021-01-26T20:33:59.2Z",
76+
"rbacGroupName": "A",
77+
"status": "New"
8578
}
8679
},
8780
"observer": {
88-
"name": "WindowsDefenderAv",
81+
"name": "WindowsDefenderAtp",
8982
"product": "Defender for Endpoint",
9083
"vendor": "Microsoft"
9184
},
9285
"related": {
9386
"hosts": [
94-
"testserver4"
87+
"temp123.middleeast.corp.microsoft.com"
88+
],
89+
"user": [
90+
"temp123"
9591
]
9692
},
9793
"rule": {
98-
"description": "Malware and unwanted software are undesirable applications that perform annoying, disruptive, or harmful actions on affected machines. Some of these undesirable applications can replicate and spread from one machine to another. Others are able to receive commands from remote attackers and perform activities associated with cyber attacks.\n\nA malware is considered active if it is found running on the machine or it already has persistence mechanisms in place. Active malware detections are assigned higher severity ratings.\n\nBecause this malware was active, take precautionary measures and check for residual signs of infection."
94+
"description": "Binaries signed by Microsoft can be used to run low-reputation arbitrary code. This technique hides the execution of malicious code within a trusted process. As a result, the trusted process might exhibit suspicious behaviors, such as opening a listening port or connecting to a command-and-control (C&C) server."
9995
},
10096
"tags": [
10197
"microsoft-defender-endpoint",
@@ -105,8 +101,13 @@
105101
"framework": "MITRE ATT&CK",
106102
"technique": {
107103
"name": [
108-
"Malware"
104+
"Execution"
109105
]
110106
}
107+
},
108+
"user": {
109+
"domain": "DOMAIN",
110+
"id": "S-1-5-21-11111607-1111760036-109187956-75141",
111+
"name": "temp123"
111112
}
112113
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
input: cel
2+
service: microsoft-defender-mock
3+
vars:
4+
url: http://{{Hostname}}:{{Port}}
5+
login_url: http://{{Hostname}}:{{Port}}
6+
client_id: test-cel-client-id
7+
client_secret: test-cel-client-secret
8+
tenant_id: tenant-id
9+
oauth_endpoint_params: |
10+
grant_type: refresh_token
11+
refresh_token: 'refresh_token_123'
12+
data_stream:
13+
vars:
14+
preserve_original_event: true
15+
enable_request_tracer: true
16+
batch_size: 2
17+
assert:
18+
hit_count: 5

packages/microsoft_defender_endpoint/data_stream/machine/agent/stream/cel.yml.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ auth.oauth2:
1616
client.secret: {{client_secret}}
1717
token_url: {{login_url}}/{{tenant_id}}/oauth2/v2.0/token
1818
scopes: {{token_scopes}}
19+
{{#if oauth_endpoint_params}}
20+
endpoint_params: {{oauth_endpoint_params}}
21+
{{/if}}
1922
state:
2023
page_size: {{batch_size}}
2124
redact:

0 commit comments

Comments
 (0)