# Lethal Injection: How We Hacked Microsoft's Healthcare Chat Bot

Azure Health Bot leaked cross-tenant data via URL traversal in Azure Table rowKey, then three vm2 sandbox escapes yielded root RCE and memory disclosure of secrets.

- Payout: unconfirmed
- Severity: critical
- Program: Microsoft
- Found by: Yanir Tsarimi
- Disclosed: 2024-05-07
- Write-up quality: 9/10
- Original: https://www.breachproof.net/blog/lethal-injection-how-we-hacked-microsoft-ai-chat-bot
- Library page: https://bugbountylibrary.com/r/blog%3Abreachproof-net-blog-lethal-injection-how-we-hacked-microsoft-ai-chat-bot
- Tags: area:critical domain:cloud domain:critical-infra impact:data-leak impact:internal-access impact:rce kind:bounty platform:blog sev:critical tech:azure tech:nodejs technique:chained technique:source-review vuln:info-disclosure vuln:path-traversal vuln:rce vuln:sandbox-escape

**Target:** Azure Health Bot portal data-connections API and Node.js vm2 sandbox
**Root cause:** Backend concatenated user-controlled connection ID into an Azure Table API URL without encoding, and whitelisted modules (underscore, buffer) were passed from the unsandboxed root context into vm2.
**Steps:**
1. Request `GET /v4/<botid>/integration/data-connections/<id>/` and note Azure Table response disclosing account, partitionKey, rowKey.
2. Inject encoded traversal in the ID: `%2F..%2F` to cancel prepended path and append own `(PartitionKey='DataConnection',RowKey='<other>')` query, returning other tenants' connection data.
3. In bot JS sandbox, call `require.toString()` to read custom require source; observe `_.indexOf()` used for whitelist check.
4. Override global `_.indexOf = () => 0` then `require('child_process').execSync('id')` for root RCE.
5. After patch, use whitelisted underscore `_.template('...')` to compile code in host context for RCE.
6. After patch, use `Buffer.SlowBuffer(n)` (unrestricted allocUnsafe equivalent) to read uninitialized memory containing JWT secrets, k8s API calls, cross-tenant data.
**How found:** Noticed Azure Table API response format in data-connections endpoint, hypothesized all tenants share one table, and tested URL traversal on the rowKey. For sandbox, read `require.toString()` source, spotted `_.indexOf` instead of native indexOf, then audited each whitelisted module for dangerous host-context functionality (template compilation, SlowBuffer).
**Exploitation:** Attacker with a Health Bot instance queried the data-connections endpoint with a crafted rowKey to read other tenants' auth secrets, then used the bot's JS sandbox to escape vm2 via whitelisted module tampering, achieving root code execution on a shared backend with access to multiple tenants' databases.
**Escalation:** Chained cross-tenant secret disclosure with three independent sandbox escapes to reach shared backend root and read process memory for internal Azure JWT secrets and Kubernetes API traffic.
**Insight:** When a custom require whitelist uses library functions (e.g. underscore's indexOf) instead of native ones, the check itself is overridable from inside the sandbox; also audit whitelisted modules for host-context code compilation (_.template) and uninitialized-memory allocators (Buffer.SlowBuffer) that bypass vm2's allocUnsafe restriction.

## Proof of concept (copied exactly from the original report)

**URL traversal to read another tenant's data connection**

```
https://portal-eastus.healthbot.microsoft.com/v4/test-301x6x6/integration/data-connections/1679070537717/


In this URL, “test-301x6x6” is our unique health bot instance ID, and “1679070537717” is the ID of the unique data connection we created. 
The response to this request was the following JSON:


{
 "odata.metadata": "https://hbstenant2steausprod.table.core.windows.net/$metadata#test301x6x6/@Element",
 "etag": "W/\"datetime'2023-03-17T17%3A08%3A44.7784337Z'\"",
 "partitionKey": "DataConnection",
 "rowKey": "1679070537717",
 "timestamp": "2023-03-17T17:08:44.7784337Z",
 "type": "custom",
 "name": "test data connection",
 "description": "desc",
 "base_url": "https://website.com/a",
 "auth_provider": "",
 "static_parameters": "[{\"type\":\"header\",\"key\":\"Test\",\"value\":\"true\"}]"
}


People familiar with Azure will recognize this as an Azure Table API response. And it makes sense, the service stores our connection data in the Azure Table service, and it pulls that data directly from there.
Our intuition was to start toying with the ID number of our data connection. We believe that the data connections of all customers are in the same table, and if we can query whatever ID we want from the table, we can view the data connections of other customers.
Per the Azure Table API documentation, here’s how a request to retrieve data from a table looks like:
 
So here we have 3 variables we must fill: 

- table name
- partition key
- row keyWe have all the required variables since the previous Table API response discloses all that information. Our guess was, that was the URL the backend server uses to get the information behind the scenes:
 
Here you can see:

- hbstenant2steausprod - the account name Microsoft used for storing the data.
- test301x6x6 - our Azure health bot instance ID. This is not a secret.
- (PartitionKey=’DataConnection’,RowKey=’1679070537717’): Pulling DataConnection with the ID from the request.

The input in our control is the ID. The idea was to send an ID that would allow us to “break out” of our tenant and read other tenants' data. How do we do that?
Since it’s all appended to a URL, the idea was to leverage URL traversal to cancel out the prepended information added by the server, and then add our own:
 
As you can see, we encoded the slashes (%2F) which were injected into the URL, effectively turning the request into:
 
And voila! This request successfully returned the connection data of the other tenant.
```

**Overriding underscore indexOf to bypass require whitelist**

```
Looks pretty harmless at first glance. It’s a simple check if the required module is in the whitelisted array, and if it is, the original Node.js require function will be called.
Well, if you look closer, they called _.indexOf() instead of the native array indexOf function for some reason. And _.indexOf() is a function from the underscore module. Which is whitelisted. Can you see where we’re going with this?
Bypassing the whitelist and achieving remote code execution is no problem when you can just override the indexOf function, which is conveniently already present as a global, you don’t even need to import it.
```

**Buffer.SlowBuffer uninitialized memory read**

```
Since the entire buffer module was whitelisted, we had access to SlowBuffer, which is the same as allocUnsafe. This one was not restricted by the sandbox, since it’s not supposed to be there by default: 
 
Running this code a few times yielded interesting data from the application
```

