Introduction

Nhiều thiết bị IoT không có các cơ chế bảo vệ mạnh mẽ.

Thiết bị IoT trong lab này là một máy điều chỉnh nhiệt độ được điều khiển thông qua một giao diện web với hai API là passwordtemperature.

  • Để thay đổi nhiệt độ, ta cần gửi HTTP request đến API temparature kèm theo nhiệt độ và mật khẩu.
  • Giá trị của mật khẩu được gán cứng (trong thực tế thì sẽ thay đổi thường xuyên) và được truy xuất thông qua API password. Password không dùng để xác thực mà được dùng để chống CSRF attack. Nếu không có password, chúng ta chỉ cần dùng CSRF attack là đủ chứ không cần dùng đến DNS rebinding.

Do thiết bị nằm phía sau tường lửa, các máy bên ngoài không thể tương tác với nó. Để vượt qua tường lửa, đoạn code tấn công cần thâm nhập vào mạng nội bộ. Việc này không khó để thực hiện do bất cứ khi nào người dùng trong mạng nội bộ truy cập vào trang web của attacker thì đoạn code JavaScript sẽ được chạy ở trong trình duyệt cũng như là trong mạng nội bộ. Tuy nhiên, do các trình duyệt sử dụng cơ chế bảo vệ sandbox nên đoạn code tấn công vẫn không thể tương tác với các thiết bị IoT.

Mục tiêu của lab này là sử dụng DNS rebinding để né tránh cơ chế bảo vệ sandbox và thu thập các thông tin cần thiết về máy điều chỉnh nhiệt độ. Bằng cách sử dụng các thông tin này, chúng ta có thể tăng nhiệt độ lên mức nguy hiểm.

Environment Setup

The required screenshot of task 3.3 indicates that we have configured the user VM successfully:

Launch the Attack on the IoT Device

Task 0. CRSF Protection

To change temperature, we have to fetch the password from server via endpoint /password. This is used for CSRF protection instead of authentication as the password works as a CSRF token. If we don’t require password, the attacker can just send a cross-site request to change the temperature via endpoint /temperature.

Task 1. Understanding the Same-Origin Policy Protection

There are 3 URLs:

  • URL 1: http://www.seedIoT32.com. This is used for monitoring.
  • URL 2: http://www.seedIoT32.com/change. This is used for changing the temperature.
  • URL 3: http://www.attacker32.com/change. Change temperature arbitrarily by the attacker.

JavaScript code of URL 2 and URL 3 page:

let url_prefix = 'http://www.seediot32.com'
 
function updateTemperature() {
  $.get(url_prefix + '/password', function(data) {
	$.post(url_prefix + '/temperature?value=99'  
               + '&password='+ data.password, 
               function(data) {
                  console.debug('Got a response from the server!');
               });
  });
}
 
button = document.getElementById("change");
button.addEventListener("click", updateTemperature);

The consoles of the URL 2 and the URL 3 display like this:

http://www.seedIoT32.com/change

Got a response from the server!

http://www.attacker32.com/change

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.seediot32.com/password. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

As we can see, due to Same-Origin Policy of the browser, we can not use the URL 3 to send request to the URL 1 to get the password. Normally, if the www.seedIoT32.com domain allows URL 3, it will need to use CORS by adding the Access-Control-Allow-Origin into the response that specifies URL 3.

This is what we need to bypass.

Task 2. Defeat the Same-Origin Policy Protection

We can point the target URL (the variable url_prefix) of the URL 3 to http://www.attacker32.com (attacker server). The /password response can be received because the sending URL (www.attacker32.com/change) has the same origin with the receiving URL (www.attacker32.com/password).

When IP resolution of www.attacker32.com is not known by the user’s browser, it will send a DNS query to local DNS server. And if local DNS server does not have it, it will send a DNS query to www.attacker32.com, which is controlled by the attacker. Therefore, the attacker can decide which IP that will be resolved for www.attacker32.com domain.

Step 1: Modify the JavaScript code

After modifying the JS code of www.attacker32.com/change page and click the button. We can receive the response of the GET /password request:

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 7
Server: Werkzeug/1.0.1 Python/3.8.5
Date: Sun, 25 Aug 2024 08:12:47 GMT
 
StillMe

But, the POST request is denied due to attacker server can not handle this request:

Failure

405 Method Not Allowed

Method Not Allowed

The method is not allowed for the requested URL.

Obviously, we don’t want to send request to www.attacker32.com/temperature but www.seedIoT32.com/temperature instead. To do this and bypass browser’s protection, we need to remap the DNS record of www.attacker32.com to the IP of www.seedIoT32.com.

Step 2: Conduct the DNS rebinding.

After the user browser have the attacker’s /change page, we conduct the DNS rebinding.

First, we modify the DNS record in the name server of the attacker. Then, we flush the DNS cache of the local DNS server (this is for making the attack process faster instead of waiting for 1000 seconds).

Finally, we click the button on attacker /change page to change temperature to 99. Result shows that we have successfully conducted the DNS rebinding attack:

Task 3. Launch the Attack

Moreover, we also make the attack become automatic by using www.attacker32.com URL to send request after the timer is timed out.

But, we first need to flush DNS cache of local DNS server and restore zone file of attacker’s name server. If not, the UI of www.attacker32.com will be the same with www.seedIoT32.com.

After that, we access www.attacker32.com to load the time-out page. To conduct DNS rebinding, we modify DNS record in attacker name server and flush the local DNS server.

Then, we can wait the time-out page to send out the request, which make local DNS server updates its cache. Or, we can access www.attacker32.com/change to update the DNS cache proactively.

This is the before and after states of DNS cache of local DNS server:

root@519fa898f1bd:/# cat /var/cache/bind/dump.db  | grep attacker -B 2
; attacker32.com. SOA ns.attacker32.com. admin.attacker32.com. 2008111001 28800 7200 2419200 86400
; authanswer
			605608	A	10.9.0.180
root@519fa898f1bd:/# rndc flush
root@519fa898f1bd:/# rndc dumpdb -cache
 
root@519fa898f1bd:/# cat /var/cache/bind/dump.db  | grep attacker -B 2
; attacker32.com. SOA ns.attacker32.com. admin.attacker32.com. 2008111001 28800 7200 2419200 86400
; authanswer
			605790	A	192.168.60.80

After 10 second, the temperature will be changed to 88.

Result:

list
from outgoing([[SEED Lab - DNS Rebinding]])
sort file.ctime asc

Resources