[00:00.000 --> 00:06.600] Hello, I'm Hyejin and thank you for coming here. The topic I will talk about today is [00:06.600 --> 00:18.720] HackDMI, Pwning, HDMI for fun and profit. Yes. First of all, my name is Hyejin and I am a [00:18.720 --> 00:24.240] vulnerability assessment training mentee of B.O.B. which is the next generation cyber [00:24.240 --> 00:32.500] security leader training program in Korea. And his name, his name is Jung Eunjin and who is [00:32.500 --> 00:41.660] sitting down there. And he is working as a researcher at a company named Theory and he is [00:41.660 --> 00:51.540] mentor at B.O.B. We are both members of the team Shin Ki-ha-jin and actually I was a mentee [00:51.540 --> 00:58.960] and he was a mentor. We worked on the topic of vulnerability assessment for HDMI based [00:58.960 --> 01:10.700] embedded device at B.O.B. Our team is made up of two mentors, one PL and five mentees. The [01:10.700 --> 01:17.900] table of contents is as follows. First, I'd like to give you a quick introduction about previous [01:17.900 --> 01:26.260] talk and one day vulnerabilities about HDMI. And after that, I'm going to talk about the CEC and [01:26.260 --> 01:33.660] DDC protocols that we regard as attack vectors. Finally, I'd like to introduce you to each [01:33.660 --> 01:43.110] protocol folder that we've made and tell you about the result. This is the previous talk about [01:43.110 --> 01:51.810] HDMI. Hacking display made interesting at Bracket Europe and what the ATC at 44con and high [01:52.010 --> 02:02.430] def fuzzing at Defcon. This is the one day of the HDMI and it was the vulnerabilities of memory [02:02.430 --> 02:13.280] corruption type that occurred at CEC and DDC protocols. Now, let's talk about the HDMI [02:13.280 --> 02:20.940] protocols. Here, I will give you a brief description of the each protocol and the knowledge [02:20.940 --> 02:29.180] required to transmit the message or command that each protocol use. If you listen to this part, [02:29.180 --> 02:40.350] you will probably be able to send the message to your device that support HDMI. HDMI is [02:40.350 --> 02:46.970] provided for transmitting digital television audio-visual signals from DVD players, [02:46.970 --> 02:55.090] set-top box, and other audio-visual source to the television sets and projectors or other [02:55.090 --> 03:04.170] video displays. Maybe even without this explanation, you already used HDMI to connect your [03:04.170 --> 03:15.450] laptop to a TV or a beam projector. And also I connected my laptop with HDMI today. And HDMI [03:15.450 --> 03:28.350] has four separate channels. It is TMDS, DDC, CEC, and HEAC. At first, looking at the TMDS part of [03:28.350 --> 03:37.070] the figure, you can see the video and the audio data on both the input and the output part. TMDS [03:37.070 --> 03:47.230] is used to carry audio and video data. The DDC channel is used by an HDMI source to determine the [03:47.230 --> 03:57.210] capabilities or characteristics of the sink by the- by reading the EEDID data structure. HDMI [03:57.210 --> 04:04.930] source are expected to read the sink EEDID and to deliver the audio and video formats that are [04:04.930 --> 04:13.570] supported by the sink. In addition, HDMI sink are expected to detect info frames and to process [04:13.570 --> 04:23.190] the received audio and video data appropriately. The next one is CEC. CEC channel is [04:23.190 --> 04:30.610] optionally used for a higher level user functions such as automatic setup task or task [04:30.610 --> 04:40.410] associated with the infrared remote control users. The last one is the HEAC, which is the [04:40.410 --> 04:48.190] optionally used as a high-speed bidirectional data channel and stands for HDMI Ethernet and [04:48.190 --> 05:00.440] Audio Return Channel. The four protocols mentioned above are mapped from the actual HDMI pins as [05:00.440 --> 05:12.140] follows. TMDS is from 1 to 12, which is marked yellow. And pin 13 is the CEC and pin 14 is the [05:12.140 --> 05:24.500] utility line used by the HEAC. 15 and 16 are SCL, SDA, and 17, 18, and 19 are internal ground, [05:24.500 --> 05:34.480] VCC, and HPD. Here we were interested in functions such as carry controls, status, and data [05:34.480 --> 05:41.760] information, rather than the video data transmission. In addition, the protocol supports the [05:41.760 --> 05:52.460] both directions. So today we are going to talk about the CEC and DDC protocols. The first one is [05:52.460 --> 06:01.600] CEC. CEC stands for Consumer Electronics Control. You can connect your laptop or smartphone to [06:01.600 --> 06:09.280] your TV using HDMI. Of course it's possible to connect multiple devices as shown in the picture [06:09.680 --> 06:19.640] if you have multiple HDMI cables. And you may want to control each devices. For example, you can [06:19.640 --> 06:28.340] adjust the volume of the home theater or changing the TV channel. The CEC protocol allows you to [06:28.340 --> 06:42.130] control each devices with a single remote control. CEC is a protocol that provides high level [06:42.130 --> 06:49.850] control functions between all of the various audio visual products in a user's environment. It [06:49.850 --> 06:56.590] provides a number of features designed to enhance the functionality of devices within an HDMI [06:56.590 --> 07:05.770] system. Because CEC provides functions in the user's environment, each manufacturer has a [07:05.770 --> 07:13.770] different brand name. So maybe any net plus or easy link, easy sync, rather than the CEC can be [07:13.770 --> 07:23.880] more familiar. And in HDMI, there are two types of the address. Physical address and logical [07:23.880 --> 07:35.060] address. And the address used by the CEC message is the logical address. However, CEC is a [07:35.060 --> 07:42.340] protocol based on a bus system, so therefore it cannot learn a certain physical connectivity of [07:42.340 --> 07:52.620] the network. So it uses the DDC protocol to locate physical addresses to device in the network. [07:53.880 --> 08:01.900] All CEC devices therefore have both physical and logical address, whereas non-CEC devices only [08:01.900 --> 08:11.880] has the physical address. The physical address is four digit long. It seems like the IPv4 [08:11.880 --> 08:21.160] address. And it has a five device deep hierarchy. For example, the root device TB has 0 0 0 0 [08:21.160 --> 08:31.340] and the connected device on TB have 1 0 0 0 and 2 0 0 0. In addition, the DVD and STB connected [08:31.340 --> 08:41.760] to the amplifier become 2 1 0 0 and 2 2 0 0. When a physical address is allocated like this, then [08:41.760 --> 08:53.360] it allocates a logical address. Logical address defines the device type. For example, TB is [08:53.360 --> 09:03.360] 0, a recording device is 1 2 or 9, depending on the device type. Logical address is allocated [09:03.360 --> 09:13.380] through the polling message. First, text the first address and send the polling message. If it is a [09:13.380 --> 09:21.580] recording device, it sends a polling message to the first of 1 2 and 9. Actually, it will be 1. [09:21.580 --> 09:29.880] And if polling is acknowledged, it takes the next address. And if not, it stops the [09:29.880 --> 09:40.860] procedure and retains that address. That is, it's logical address becomes 1. The CEC message [09:40.860 --> 09:48.880] frame has this structure. The first is the start bit, which is followed by the header block and [09:48.880 --> 09:58.120] the data blocks. And it is a special bit indicating the start. The header block and the data [09:58.120 --> 10:06.560] blocks are each composed of 10 bits, which is consists of 8 bits of information bits and 2 bits of [10:06.560 --> 10:15.100] the control bits. And the data block is optional block. Information bits and control bits are [10:15.100 --> 10:26.310] described in detail in the next slide. First is the header block. The information bits in the [10:26.310 --> 10:34.050] header block contain the logical address. The addresses of the initiator and destination are each [10:34.050 --> 10:43.490] 4 bits. And the control bit has the same format for both the header block and the data blocks. The [10:43.490 --> 10:54.050] control bit includes the EOM bit and the ACK bit. The EOM bit stands for end of message. If the [10:54.050 --> 11:01.290] current block is followed by one or more blocks, it becomes 0. And if the current block is the [11:01.290 --> 11:09.470] last one, it becomes 1. The ACK bit stands for acknowledge, which contains the value of the [11:09.470 --> 11:18.350] acknowledge of the data or header blocks. The data block also consists of information bits and [11:18.350 --> 11:26.990] control bits. The header block is essential but the data block is an optional block. The data [11:26.990 --> 11:33.370] block has data block 1 and data block 2, where data block 1 contains the OP code in the [11:33.370 --> 11:42.630] information bits and data block 2 contains the operand. The operand has a dependency on OP [11:42.630 --> 11:52.470] code. If the OP code is 32, which corresponds to the set menu language, the operand will contain [11:52.470 --> 11:59.270] the language what you want to set. Data block 1 is one block and data block 2 can be the [11:59.270 --> 12:08.710] multiple blocks depending on the OP code value. However, the maximum message size is 16 blocks. [12:09.030 --> 12:15.270] That is the message with the maximum length is one block of header and one block of the data [12:15.270 --> 12:27.860] block 1 and 14 blocks of the data block 2. The second protocol is TDC. TDC stands for display [12:27.860 --> 12:36.660] data channel. And it is used by the HDMI source to read the sync EEDID in order to discover the [12:36.660 --> 12:44.760] sync configuration and capabilities. More easily illustrated, when you connect the TV and the [12:44.760 --> 12:56.600] laptop with the HDMI, the sync TV sends the EEDID data to the source laptop. So what data does [12:56.600 --> 13:06.160] TDC send? It's called EEDID, extended display identification data. The EEDID is a metadata [13:06.160 --> 13:12.720] format for display devices to describe their capabilities to a video source such as [13:12.720 --> 13:24.860] graphics card or set up box. This format is defined by a standard published by the VESA. However, [13:24.860 --> 13:34.360] EEDID is for PC monitors. An EEDID is an extension of the EEDID used to illustrate more advanced [13:34.360 --> 13:44.040] features. For example, PC monitors generally does not support audio, so a traditional EEDID [13:44.040 --> 13:53.400] structure would not account for this, whereas an EEDID would. Therefore, it sends the EEDID data. [13:53.580 --> 14:05.140] The EEDID data consists of the EEDID 1.3 and CA extension. And they have the following [14:05.140 --> 14:13.440] structures. Because data sent by the fuzzer is also this EEDID data, so we need to know a little [14:13.440 --> 14:21.720] bit about the data structure. EEDID 1.3 includes information such as horizontal size, vertical [14:21.720 --> 14:28.860] size, and color characteristics. And there is also an extension flag, which means that extension [14:28.860 --> 14:39.960] data follows the EEDID structure. And if you- if you are not sure what the EEDID is yet, turn on [14:39.960 --> 14:48.620] your laptop. If your laptop is now connected to a TV or a monitor with HDMI, you can probably [14:48.620 --> 14:58.160] find EEDID data in your laptop. On Windows, it is stored in the registry, and on Ubuntu, it can [14:58.160 --> 15:10.160] be found in the path sys class DRM, and on Mac OS, you can check it through the IO registry. The [15:10.160 --> 15:21.000] HDMI transmits EEDID data over the I2C bus. As you know, I2C is a serial computer bus. And it is [15:21.000 --> 15:28.080] widely used for attaching lower speed peripheral ICs to processors and microcontrollers in [15:28.080 --> 15:36.120] short distance in troubled communication. I2C uses only two bidirectional open collector lines, [15:36.120 --> 15:46.240] SDA and SDL, put up with registers. Typical voltages used are 5 or 3.3, although systems with [15:46.240 --> 15:57.640] other voltages are permitted. We use Arduino to transmit the EEDID data directly. You can use [15:57.640 --> 16:05.260] other things, but you can easily use I2C slave mode with Arduino compared to the Raspberry Pi. [16:05.960 --> 16:12.080] You can connect the register and the wire to each pin as shown in the picture. The wires [16:12.080 --> 16:22.180] connected to the breadboard is in turn are SDL, SDA, ground, VCC, and HPD. And each line [16:22.180 --> 16:29.600] is connected to the pin that is mapped in the HDMI. With this connection, the hardware [16:29.600 --> 16:40.830] preparation is finished. So far, we have looked at a brief description of the CEC and the DDC [16:40.830 --> 16:53.130] protocols and its message. Now, I will use them to create a further. The first is CEC. Any [16:53.130 --> 17:00.710] device that supports CEC can be the target device. For example, smart TV, beam projector, [17:00.710 --> 17:08.430] set-top box, blu-ray, smart phone, and game controllers, and so on. In the case of a [17:08.430 --> 17:14.710] smart phone, it is highly likely to purchase an additional adapter. Make sure that the adapter [17:14.710 --> 17:23.630] also supports the CEC. And for CEC protocol, whether to support CEC rather than the type of [17:23.630 --> 17:34.980] the device is a more important factor to determining the target. For the CEC further, all you need [17:34.980 --> 17:47.960] is a USB CEC adapter and a HDMI cable. We will use the Pi serial for serial communication. Now, [17:47.960 --> 17:54.640] it's time to send the CEC message directly to the device. There is a USB CEC adapter [17:54.640 --> 18:03.760] communication library which is called LibCEC. It can be found in the GitHub. And if you have a [18:03.760 --> 18:11.260] USB CEC adapter created by Persec, you can send the CEC message. Of course, other adapters [18:11.260 --> 18:17.660] are also supported and if you are having trouble to buy a new adapter, you can use the Raspberry [18:17.660 --> 18:29.710] Pi. With LibCEC, you can send the CEC message as above. But this library is so well made that it [18:29.710 --> 18:37.150] can be drop our faulting data. So, we will not use this library when faulting. Since the [18:37.150 --> 18:43.610] adapter shown above is the USB CEC adapter, data can be transferred via the serial [18:43.610 --> 18:52.990] communication. Of course, you can use Pi serial. You can send a message with just three lines of [18:52.990 --> 19:04.140] the code as above. This is a command to power off the setup box. Let's first look at the code that [19:04.140 --> 19:12.300] sends messages to the CEC adapter without using the LibCEC library. Before that, you've probably [19:12.300 --> 19:21.460] seen this picture. When data is transferred using the adapter, one block is represented by four [19:21.460 --> 19:30.260] bytes. More precisely, the information bits in a block. This works for both the header block and [19:30.260 --> 19:38.980] the data blocks. The four bytes consists of messages typed, message code, message value, and [19:38.980 --> 19:46.880] message end. The actual data value contained in the information bits are stored in message [19:46.880 --> 19:54.580] value. Message start and message end are the bytes representing the beginning and end of a [19:54.580 --> 20:07.930] block. Respectively, FF and FE. Message code can be thought of as a control bit. Here, the [20:07.930 --> 20:14.310] message to be transmitted has a structure of message start, message code, message value, and [20:14.310 --> 20:22.050] message end. At this point, you can see that the message code is different, which can be found in [20:22.050 --> 20:30.090] the LibCEC code in CEC adapter message code. For basic message transmission, you need to [20:30.090 --> 20:38.570] know about four message codes in your code. In particular, OB and OC are message codes related to [20:38.570 --> 20:45.970] message transmit. And I said that the message code is similar to the control bit. For the E1 [20:45.970 --> 20:58.030] bit of the control bit, that is represented by OB and OC. And the AC bit is also similar. We [20:58.030 --> 21:07.550] create a fuzzer for the three parts of the CEC message frame. First is an OP code. 3-6 was [21:07.550 --> 21:16.290] excluded because it is the OP code to power of the device. And the second is the operand. And we [21:16.290 --> 21:24.010] randomly selected a value from zero to FF to transmit the operand of 14 blocks. And the [21:24.010 --> 21:32.330] header block is fixed to the logical address of the target device. In the case of an OP code, to [21:32.330 --> 21:38.170] increase the probability of a crash, we use the list of OP code that are likely to cause [21:38.170 --> 21:46.650] vulnerabilities. And finally, the message length. In the case of the CEC protocol, the maximum [21:46.650 --> 21:57.710] message size is fixed to 16 blocks. That is 160 bits. In addition, each block is recognized as [21:57.710 --> 22:06.330] one block of header block and an OP code and operands in order. Therefore, data of various [22:06.330 --> 22:15.850] message sizes were transmitted including messages that exceeded the maximum size. Now it is [22:15.850 --> 22:24.310] the DDC protocol. The target device is an HDMI source device. Maybe you can probably guess the [22:24.310 --> 22:31.990] reason. Because the DDC protocol allows the sync device to send the EEDID data to the source [22:31.990 --> 22:39.270] device. Therefore, the source device, which is the device that received the data, was targeted. [22:39.990 --> 22:51.010] Source device includes desktops, laptops, set-top box, and smartphones. And we used the Arduino [22:51.010 --> 23:00.370] Mega 2560 and transmitted the data via the wire library provided by Arduino. Also, we cut and [23:00.370 --> 23:10.950] soldered the HDMI cable for more reliable data transmission. If you cut the HDMI cable, you can [23:10.950 --> 23:21.520] get 19 pins and a wire connected to each pin. And we connected the appropriate registers and [23:21.520 --> 23:31.600] wires to the required SCL, SDA, ground, VCC, and HPD locations and soldered them to make the same [23:31.600 --> 23:43.770] cable as the last picture and then connect each of the five jumper wires to the Arduino. Now, we [23:43.770 --> 23:50.450] can transfer the actual data through the wire library supported by Arduino for communication [23:50.450 --> 24:00.650] with I2C devices. The main functions for data transfer are begin on request, on receive, read, [24:00.650 --> 24:11.750] and write. Note that it uses a 32 byte buffer. Therefore, any communication should be within [24:11.750 --> 24:22.810] this limit. Exceeding bytes will be just dropped. But we will send the EDID value of 128 bytes. So, [24:22.810 --> 24:35.270] I modified buffer length in the header file to 128 as follows. As a result, EDID data can be [24:35.270 --> 24:42.090] transmitted as shown in the picture. On the left is a code written using Arduino IDE and on the [24:42.090 --> 24:52.780] right is the result of sending EDID data to the laptop via Arduino. And it will now send the [24:52.780 --> 25:03.120] EEDID data. It consists of EDID 1.3 and CA extension. It's the CA861D. At this time, if the [25:03.120 --> 25:10.100] value of the thread such as header, padding, and checksum, which are marked in red, are [25:10.100 --> 25:20.460] used well, the fuzzing effect can be enhanced. We created the data in the above three ways when [25:20.460 --> 25:27.740] mutating. First, it's a structure of EDID, and second, random among the structure that are [25:27.740 --> 25:39.410] likely to cause vulnerabilities, and finally, a random value for all data. And one more thing to [25:39.410 --> 25:47.070] note here. To fuzz through the HDMI cable, the process of connecting and disconnecting HDMI [25:47.070 --> 25:55.510] should be repeated. However, if you have to plug in and out every time you send data, it's very [25:55.510 --> 26:04.570] inefficient and it will not be called a fuzzer. This is confirmed by the HPD signal. When the [26:04.570 --> 26:12.810] 5 volts is applied to the sync TV, the sync sends the HPD high to the source. And then the [26:12.810 --> 26:21.650] source sends an EDID request to the sync, and as a result, the sync sends the EDID to the source. [26:24.080 --> 26:31.580] So, we repeatedly send low and high to HPD pin, giving the same effect as connecting and [26:31.580 --> 26:42.030] disconnecting HDMI. Now, let me tell you about the result we have obtained through our fuzzer. [26:44.630 --> 26:51.070] First, if you look at the CEC protocol, in the memcpy function, you can see a one byte stack [26:51.070 --> 27:03.990] overflow resulting in a memory leak. In closer look, the top part of the write function is the [27:03.990 --> 27:12.110] onTransact function in libHDMI CEC contains the header and data blocks we sent. And the [27:12.110 --> 27:20.990] read int32 and read C string functions are just that part. If you look at the onEventUpdate [27:20.990 --> 27:30.930] function in libHDMI CEC JNI, copy it to V8 using the way you received above. At this time, a [27:30.930 --> 27:39.710] one byte overflow occurs. And the following is the DDC, and you can see that the kernel panics [27:39.710 --> 27:46.930] and fails to reboot when you send the EDID data. Also, we can see that the value is modified to [27:46.930 --> 27:58.410] 61 that we sent. In fact, we want more influential data- influential results. But fuzzing [27:58.410 --> 28:07.110] with a real HDMI cable creates a problem of stability and speed. At the time, we thought that [28:07.110 --> 28:13.530] the graphics driver vulnerability is highly influential. So, we made a graphics driver [28:13.530 --> 28:26.730] fuzzer of HDMI on Ubuntu. So, I'd like to briefly introduce the Ubuntu DDC fuzzer that we- that [28:26.730 --> 28:33.710] The process of creating this fuzzer can be summarized in four main steps. First, with source code [28:33.710 --> 28:42.730] auditing, I found a part that has HDMI EDID data. We confirmed that the EDID data is stored in [28:42.730 --> 28:50.210] the second parameter of the DRM to prove DDC EDID function, which named buff, after calling [28:50.210 --> 29:00.820] this function. The second is hooking with KProofs. The KProofs is debugging mechanism for the [29:00.820 --> 29:08.400] Linux kernel. It enables you to dynamically hook into the kernel and allows you to do various [29:08.400 --> 29:18.500] actions through the callback function. The following source code is basic example. In ADDR field of [29:18.500 --> 29:25.220] KProof struct, you can set the address of function to break. And you can start with the symbol [29:25.220 --> 29:33.940] using the symbol name and offset field instead of the ADDR field. When the break point, what you [29:33.940 --> 29:40.560] set in the address field is hit, KProof called pre-handler and after that instruction is [29:40.560 --> 29:50.680] executed, it calls the post-handler. And it's handler's second parameter, which names Lex, it's [29:50.680 --> 29:58.860] pointing to the structure containing the registers saved when the break point was hit. So you can [29:58.860 --> 30:09.900] counter the register value with it. Actually, we want break when a function returns, so we use [30:09.900 --> 30:18.920] return proofs. It's the other type of proofs and also called KReproofs. And maybe K or Sims [30:18.920 --> 30:28.740] could be helpful for you to get all kernel symbols. Anyway, the code is similar to the KProofs. In [30:28.740 --> 30:36.580] the entry handler, we have saved the address of the buffer where the EDID data is stored. And [30:36.580 --> 30:43.820] before returning, that is after the EDID data is stored, we modified its value by accessing that [30:43.820 --> 30:52.020] address. In fact, we did not read or write the return value at RET handler, but instead changed [30:52.020 --> 31:02.700] the EDID value at the point of return. Now we can mutate the EDID data. But there is one more [31:02.700 --> 31:10.240] problem to be solved here. That is, calling this function interactively as if we had [31:10.240 --> 31:21.820] repeatedly sent HPD signal at the Arduino fuzzer part. I thought that using XRender would solve [31:21.820 --> 31:29.140] this problem easily. XRender is used to set the size, orientation, and reflection of the [31:29.140 --> 31:37.920] outputs for a screen. So we thought that EDID-related functions would be triggered. However, [31:37.920 --> 31:46.960] when I used XRender to create a fuzzer, I got too much noise. So we did it another way. And we [31:46.960 --> 31:57.760] checked the call stack. There are various tools to trace the call stack, and we used FTrace. FTrace [31:57.760 --> 32:04.860] is an internal tracer designed to help our developers and designers of systems to find what is [32:04.860 --> 32:13.680] going on inside the kernel. The files for using FTrace are in the past, syskernel debug tracing, [32:13.680 --> 32:19.440] and there are several types of the tracers. There are types that are defined in the file [32:19.440 --> 32:26.520] available tracers, and the traceable function list is in the file available filter functions. [32:27.300 --> 32:36.800] Trace results are stored in the file trace. First, we set the options to check the call stack of [32:36.800 --> 32:44.640] DRM do proof DDC EDID as shown in the multiple echo commands. And this will give you the result [32:44.640 --> 32:52.220] shown in the picture. The result shows that this function is called from the IOC tier, and I [32:52.220 --> 32:59.420] checked the source code for DRM IOC tier would get connected. Now, the final step is to call [32:59.420 --> 33:10.830] this one. And this is the lib DRM user space library for accessing the DRM on Linux that [33:10.830 --> 33:18.010] supports the IOC tier interface. And you can see the code for DRM would get connected in this [33:18.010 --> 33:27.350] library. So, we used it to call this function. As a result, we were able to complete the [33:27.350 --> 33:36.900] fuzzle. The presentation so far can be summarized in these pictures of two protocols and the [33:36.900 --> 33:48.280] each protocol fuzzles. And it is our future work. And source and images are as follows. Thank [33:48.280 --> 33:55.460] you for listening so far. And if you have any questions, please send me an email. Thank you so [33:55.460 --> 33:56.240] much.