CVE-2018-20139 - Daikin Emura Series - Arbitrary Remote Control via DNS Rebinding
The Daikin Emura air conditioner's REST API did not check the origin of HTTP requests, allowing a malicious website to control the device via DNS rebinding. An attacker could send commands to the device from the victim's browser after the victim stayed on the attacker's page for about 60 seconds.
There is a lot of hype around DNS rebinding vulnerability and vulnerable IoT devices, including home cameras, air conditioners or climate control devices; this flaw will cover the lack of origin checking on HTTP requests.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Daikin Emura is a range of air conditioners and climate control devices that expose an HTTP REST API on the local network. That API is reachable from any browser on the same network, and it does not check the origin of the requests it receives. The result is a DNS rebinding flaw: an attacker who controls a DNS server can make a victim's browser communicate with the device on the internal network.
The issue was assigned CVE-2018-20139 and fixed in firmware 3.3.6.
Setup
The attack needs three things:
- A DNS server under the attacker's control, configured with a rebinding entry. The author uses FakeDns.
- A web page hosted on the attacker's infrastructure that keeps the victim's browser on the page long enough for the rebinding to take effect.
- A victim who visits that page from a network where the Daikin device is reachable.
The proof of concept used NAT addresses for the fake DNS server; the author notes that an internet address can be used instead.
Finding it
The starting point is the general class of DNS rebinding bugs against IoT devices: home cameras, air conditioners, climate control devices. The flaw in this case is the lack of origin checking on HTTP requests. Browsers enforce the Same-Origin policy, which blocks attempts to load external content that does not belong to the original domain, but that protection only works if the server on the other side validates where a request comes from. A device that answers any request regardless of origin can be reached by a page from any domain, once DNS resolution for that domain points at the device.
Exploitation
Step 1: understand the rebinding primitive
A DNS rebinding attack lets an attacker who controls a DNS server communicate with a device on the victim's internal network. The evil DNS server answers a specific A query with two different IPs on two consecutive requests: the first answer returns the attacker's IP with a short TTL of 1 second, the second answer returns the original IP of the device.
Because browsers use different caching systems with different expiration times, the attack needs a minimum number of seconds to work. For a reliable exploitation the victim has to stay on the attacker's website for at least 60 seconds; on Firefox this may differ from other browsers.
The diagram shows the cache poisoning request flow: the first resolution returns the attacker's server, the second returns the device.
Step 2: configure the evil DNS server
The DNS server is configured with FakeDns and needs a single entry for this scenario:
The entry makes the server answer A queries for rebind-example.voidzone.it. The first parameter before the % is the TTL.
Step 3: host the waiting page
The next step is an HTML page that entertains the user with a YouTube video while the timeout runs. When the timeout expires, an XMLHttpRequest is sent to the device.
The hosted page as it appears to the victim.
The wait page during the 60 second window.
Step 4: read the device response
After 60 seconds the XMLHttpRequest is sent and reaches the Daikin REST API. The response comes back to the attacker's JavaScript:
The response from the Daikin Emura REST API, captured in the browser.
Step 5: the full attack on video
Video of the attack.
Root cause
The device's HTTP API does not validate the origin of incoming requests. Browsers will happily send a cross-origin XMLHttpRequest to a hostname that resolves to the local device, and the Same-Origin policy only prevents the attacker's page from reading responses from a different origin. Once DNS rebinding makes the attacker's hostname and the device the same origin from the browser's point of view, that protection no longer applies. The missing origin check on the server side is what turns the rebinding primitive into full read and control access.
Impact
An attacker who can get a victim to stay on a malicious page for the required time can communicate with the Daikin device on the victim's internal network and read its REST API responses. In the demonstrated scenario the attacker's page can read the device's REST API response. The attack requires the victim to visit the attacker's site and remain there for at least 60 seconds, and it requires the device to be reachable from the victim's browser, which is the normal case for a device on the same local network.
Fix
The vulnerability was fixed in firmware version 3.3.6; the official update was released on 31 October 2018.
Variants to test
The same primitive applies to any local HTTP service that does not check the origin of requests. Concrete things to try:
- Point a rebinding hostname at other IoT REST APIs on the local network and send an XMLHttpRequest from a page the victim keeps open past the TTL. A positive result is a readable JSON or XML response from the device in the attacker's JavaScript.
- Try state-changing requests, not just reads, against the same endpoints. A positive result is the device acting on the request, for example a changed setting confirmed by a follow-up read.
- Test different browsers and caching behaviours to find the minimum dwell time needed. A positive result is a successful response after a shorter wait than 60 seconds.
- Check whether the device validates the
OriginorHostheader at all. A positive result is a response to a request carrying an unrelated origin.
Timeline
- 25/07/2018: first contact with Daikin Europe
- 26/07/2018: response received, report requested
- 07/08/2018: report and PoC sent
- 08/08/2018: vulnerability confirmed
- 14/09/2018: fix promised by the end of October
- 31/10/2018: official update released (firmware 3.3.6)
- 19/11/2018: paper draft sent to the Daikin Europe team
- 13/12/2018: CVE-2018-20139 assigned
Credits
The author thanks Mr. Pieter-Jan Decherf and the Daikin Europe team for the quick responses and updates on the remediation measures.
What happened, in plain words
Daikin Emura is a range of air conditioners and climate control units. These devices can be controlled over the local network: they run a small web service, called a REST API, that other programs on the same network can talk to. An API is simply a set of addresses a program can call to ask for information or to give an instruction, much like a restaurant menu lists the dishes you are allowed to order. A REST API is one common style of such a menu, where each address (a URL) stands for one thing you can read or change.
The problem is that this API answers requests from anyone, without checking where the request came from. A browser has a built-in protection called the Same-Origin policy, which stops a page on one website from reading answers that belong to a different website. But that protection only helps if the server on the other side also checks who is asking. The Daikin device did not check, so a page from any domain could reach it once the domain's name pointed at the device.
The trick that makes the name point at the device is called DNS rebinding. DNS is the phone book of the internet: it turns a name like example.com into a numeric address (an IP address) so your browser knows where to connect. An attacker who runs their own DNS server can give two different answers for the same name: first the address of the attacker's own server, then, a moment later, the address of the device inside the victim's home network. The victim's browser then talks to the device while believing it is still talking to the attacker's website.
The result: an attacker can make a victim's browser communicate with the device on the internal network. The issue was given the identifier CVE-2018-20139. A CVE is a public catalogue number for a known security flaw, so people can refer to the same bug unambiguously. It was fixed in firmware version 3.3.6. Firmware is the software built into a device, and updating it is like installing a new version of an app on your phone.
Setup
The attack needs three things:
- A DNS server under the attacker's control, configured with a rebinding entry. The author uses FakeDns, a small tool that lets you decide, by hand, which address a name resolves to.
- A web page hosted on the attacker's infrastructure that keeps the victim's browser on the page long enough for the rebinding to take effect. Think of it as a shop window with something entertaining inside, so the visitor stays put while something else happens in the back room.
- A victim who visits that page from a network where the Daikin device is reachable, which is the normal situation when the device sits on the same home or office network as the victim's computer.
The proof of concept used NAT addresses for the fake DNS server. NAT (Network Address Translation) is what a home router does when it lets several devices share one internet connection: inside the home the devices have private addresses, and the router translates them when they talk to the internet. The author notes that an internet address can be used instead.
Finding it
The starting point is the general class of DNS rebinding bugs against IoT devices. IoT stands for Internet of Things: everyday objects such as home cameras, air conditioners or climate control devices that are connected to a network. The flaw in this case is the lack of origin checking on HTTP requests. HTTP is the language browsers and web servers use to exchange pages and data, and every HTTP request carries information about where it came from. Origin checking means the server looks at that information and refuses requests that come from somewhere it does not trust.
Browsers enforce the Same-Origin policy, which blocks attempts to load external content that does not belong to the original domain. An origin, in browser terms, is the combination of protocol, host name and port, so http://a.example and http://b.example are two different origins even though they look similar. That protection only works if the server on the other side validates where a request comes from. A device that answers any request regardless of origin can be reached by a page from any domain, once DNS resolution for that domain points at the device.
Exploitation
Step 1: understand the rebinding primitive
A DNS rebinding attack lets an attacker who controls a DNS server communicate with a device on the victim's internal network. The evil DNS server answers a specific A query with two different IPs on two consecutive requests. An A query is simply a DNS question of the type "what is the numeric address for this name?". The first answer returns the attacker's IP with a short TTL of 1 second, the second answer returns the original IP of the device. TTL stands for time to live: it tells the browser how many seconds it may keep the answer before asking again. A TTL of one second means the browser will very soon ask the same question again, which is exactly what the attacker wants.
Because browsers use different caching systems with different expiration times, the attack needs a minimum number of seconds to work. Caching means keeping an answer around so you do not have to ask again; each browser decides for itself how long it keeps things. For a reliable exploitation the victim has to stay on the attacker's website for at least 60 seconds; on Firefox this may differ from other browsers.
The diagram shows the cache poisoning request flow: the first resolution returns the attacker's server, the second returns the device. The diagram shows the request flow: the first resolution returns the attacker's server, the second returns the device.
Step 2: configure the evil DNS server
The DNS server is configured with FakeDns and needs a single entry for this scenario:
The entry makes the server answer A queries for rebind-example.voidzone.it. The first parameter before the % is the TTL. In plain words: the line tells FakeDns "when someone asks for this name, answer with these addresses, and let the browser keep each answer for this many seconds". The name is the one the victim's browser will be pointed at; the addresses are the two stops on the journey, first the attacker's server, then the device.
Step 3: host the waiting page
The next step is an HTML page that entertains the user with a YouTube video while the timeout runs. HTML is the language web pages are written in, and a timeout is simply a programmed pause: the page waits a set number of seconds before doing the next thing. When the timeout expires, an XMLHttpRequest is sent to the device. XMLHttpRequest is the browser feature that lets a page fetch data from a server in the background, without reloading the page; it is the same mechanism that lets a shopping site update a basket without a full page refresh.
The hosted page as it appears to the victim: something ordinary to look at, so the visitor does not close the tab.
The wait page during the 60 second window. The visitor sees a video; behind the scenes the page is counting down until it can ask the device for data.
Step 4: read the device response
After 60 seconds the XMLHttpRequest is sent and reaches the Daikin REST API. The response comes back to the attacker's JavaScript. JavaScript is the programming language that runs inside web pages and makes them interactive; it is what sends the request and reads the answer. Because the browser now believes the name belongs to the same origin as the page, the Same-Origin policy no longer blocks the page from reading the answer.
The response from the Daikin Emura REST API, captured in the browser. This is the proof: data that should only be visible inside the home network has arrived in a page controlled by the attacker.
Step 5: the full attack on video
Video of the attack.
Root cause
The device's HTTP API does not validate the origin of incoming requests. Browsers will happily send a cross-origin XMLHttpRequest to a hostname that resolves to the local device, and the Same-Origin policy only prevents the attacker's page from reading responses from a different origin. Once DNS rebinding makes the attacker's hostname and the device the same origin from the browser's point of view, that protection no longer applies. The missing origin check on the server side is what turns the rebinding primitive into full read and control access. A useful comparison: the browser is a bouncer who checks the guest list, but the device is a venue with no door at all, so anyone who walks in is served.
Impact
An attacker who can get a victim to stay on a malicious page for the required time can communicate with the Daikin device on the victim's internal network and read its REST API responses. In the demonstrated scenario the attacker's page can read the device's REST API response. The attack requires the victim to visit the attacker's site and remain there for at least 60 seconds, and it requires the device to be reachable from the victim's browser, which is the normal case for a device on the same local network.
Fix
The vulnerability was fixed in firmware version 3.3.6; the official update was released on 31 October 2018.
Variants to test
The same primitive applies to any local HTTP service that does not check the origin of requests. Concrete things to try:
- Point a rebinding hostname at other IoT REST APIs on the local network and send an XMLHttpRequest from a page the victim keeps open past the TTL. A positive result is a readable JSON or XML response from the device in the attacker's JavaScript. JSON and XML are two common formats for structured data, roughly like a filled-in form versus a labelled list; both are easy for a program to read.
- Try state-changing requests, not just reads, against the same endpoints. An endpoint is one specific address in the API, and a state-changing request is one that alters something rather than only looking at it. A positive result is the device acting on the request, for example a changed setting confirmed by a follow-up read.
- Test different browsers and caching behaviours to find the minimum dwell time needed. Dwell time is how long the victim has to stay on the page. A positive result is a successful response after a shorter wait than 60 seconds.
- Check whether the device validates the
OriginorHostheader at all. A header is a small labelled field attached to every HTTP request, like the return address on an envelope;Originsays which site the request came from andHostsays which name the browser was trying to reach. A positive result is a response to a request carrying an unrelated origin.
Timeline
- 25/07/2018: first contact with Daikin Europe
- 26/07/2018: response received, report requested
- 07/08/2018: report and PoC sent. A PoC, or proof of concept, is a small demonstration that the flaw is real, not just theoretical.
- 08/08/2018: vulnerability confirmed
- 14/09/2018: fix promised by the end of October
- 31/10/2018: official update released (firmware 3.3.6)
- 19/11/2018: paper draft sent to the Daikin Europe team
- 13/12/2018: CVE-2018-20139 assigned
Credits
The author thanks Mr. Pieter-Jan Decherf and the Daikin Europe team for the quick responses and updates on the remediation measures. Remediation means the work of actually removing the flaw, not just acknowledging it.
Glossary
- API: a set of addresses a program can call to read information or give instructions, like a menu of allowed requests.
- A query: a DNS question asking for the numeric address that belongs to a name.
- Cache poisoning: filling a browser's stored DNS answer with an attacker's address so a later request goes where the attacker wants.
- Caching: keeping an answer around so it does not have to be looked up again immediately.
- CVE: a public catalogue number for a known security flaw.
- DNS: the system that turns names into numeric addresses, like a phone book for the internet.
- DNS rebinding: an attack where a name resolves first to the attacker's server and then to a device on the victim's network, so the browser ends up talking to the device.
- Dwell time: how long a victim has to stay on a page for an attack to work.
- Endpoint: one specific address in an API.
- Firmware: the software built into a device, updated by installing a new version.
- Header: a small labelled field attached to an HTTP request or response, such as
OriginorHost. - HTML: the language web pages are written in.
- HTTP: the language browsers and servers use to exchange pages and data.
- IoT: Internet of Things, everyday objects connected to a network.
- IP address: the numeric address of a device on a network.
- JavaScript: the programming language that runs inside web pages and makes them interactive.
- JSON: a common text format for structured data.
- NAT: Network Address Translation, the way a home router lets several devices share one internet connection using private addresses.
- Origin: in browser terms, the combination of protocol, host name and port that identifies where content comes from.
- Origin checking: a server looking at where a request came from and refusing untrusted sources.
- PoC: proof of concept, a small demonstration that a flaw is real.
- Remediation: the work of removing a flaw.
- REST API: a common style of API where each URL stands for one thing you can read or change.
- Same-Origin policy: the browser rule that stops a page on one site from reading answers that belong to another site.
- State-changing request: a request that alters something rather than only reading it.
- Timeout: a programmed pause before a page does the next thing.
- TTL: time to live, how many seconds a browser may keep a DNS answer before asking again.
- XML: a common text format for structured data.
- XMLHttpRequest: the browser feature that lets a page fetch data from a server in the background.