1 00:00:00,640 --> 00:00:05,660 Hello everyone, welcome to VMware Device Visualization Backhunting. 2 00:00:06,020 --> 00:00:13,880 We are excited to share our talk with you and also feel a little disappointed for we cannot arrive DEF CON in person. 3 00:00:14,560 --> 00:00:21,200 And we do hope our talk will serve as a guide for anyone who's looking to start VMware security research. 4 00:00:24,800 --> 00:00:28,020 Firstly, allow me to introduce us to you. 5 00:00:28,020 --> 00:00:35,880 My name is Jiaxin Huang and Hao Zheng and me are both security researchers of Tenggong team at Xianxin Group. 6 00:00:35,880 --> 00:00:41,260 And we are both interested in reverse engineering and visualization security. 7 00:00:41,720 --> 00:00:43,640 Yueliu is our team leader. 8 00:00:44,020 --> 00:00:49,980 And our team consists of lots of people interested in viral security domain. 9 00:00:49,980 --> 00:00:53,360 And we have a website to post our blog on it. 10 00:00:53,420 --> 00:00:57,560 So if you are interested in it, make sure to follow us. 11 00:00:57,740 --> 00:01:02,900 And if you have any questions, feel free to DM or email us. 12 00:01:04,580 --> 00:01:06,360 Here is the short story. 13 00:01:06,360 --> 00:01:09,420 Let's describe our visualization backhunting journey. 14 00:01:09,420 --> 00:01:15,060 We actually started to research visualization security from the end of 2022. 15 00:01:15,800 --> 00:01:20,640 And in that time, we basically know nothing about visualization. 16 00:01:21,200 --> 00:01:24,180 So why are we interested in it? 17 00:01:24,900 --> 00:01:28,980 Because visualization is involved in lots of hacking contests. 18 00:01:29,260 --> 00:01:32,720 And it's a very hard, very challenging target. 19 00:01:33,020 --> 00:01:38,320 And for myself, I want to reverse engineer it and learn how it works. 20 00:01:38,520 --> 00:01:41,780 So what have we achieved in last year? 21 00:01:41,780 --> 00:01:48,100 We successfully escaped from the paralyzed desktop on GeekCon 2023. 22 00:01:48,520 --> 00:01:53,600 And we reported lots of workstation EXXI bugs to VMware. 23 00:01:55,180 --> 00:02:03,290 And we learned a lot, not just about visualization, but about the whole architecture of the entire computer. 24 00:02:05,380 --> 00:02:08,700 So what can we bring to you today? 25 00:02:09,120 --> 00:02:14,400 Firstly, we will introduce the VMware visualization architecture to you. 26 00:02:14,440 --> 00:02:20,580 Most people hunting bugs directly from debugging the visual device is code. 27 00:02:20,840 --> 00:02:23,680 But we choose to take a bigger view. 28 00:02:23,880 --> 00:02:28,800 We studied it from reverse engineering the whole VMware visualization architecture. 29 00:02:29,140 --> 00:02:35,200 And this helped us to figure out which code and how they can be influenced by the guest OS. 30 00:02:35,460 --> 00:02:40,040 And hopefully, it will bring some new idea to you. 31 00:02:40,600 --> 00:02:51,760 And later, we will use the bugs that we found in USB visualization and SCSI visualization to explain the possible source of 3D in visual device. 32 00:02:52,140 --> 00:02:59,900 And anyway, a visual device is still the most cost-effective choice in visualization bug hunting. 33 00:03:01,700 --> 00:03:04,960 Okay, let's start the first part. 34 00:03:04,960 --> 00:03:07,280 VMware Hypervisor Reverse Engineering. 35 00:03:09,400 --> 00:03:14,960 If you are new to VMware visualization, I do have some tips for you. 36 00:03:15,160 --> 00:03:21,460 The most important binary on VMware Workstation or EXXI is VMX. 37 00:03:21,840 --> 00:03:29,160 It is responsible for starting the visual machine and contains most of visual device code. 38 00:03:29,480 --> 00:03:38,840 And no matter it is EXXI or Workstation, VMX is identical and basically just use different system API. 39 00:03:39,340 --> 00:03:43,740 And in this part, we will use Workstation for example. 40 00:03:44,280 --> 00:03:49,580 And also debugging VMware Workstation on the Windows can be much easier. 41 00:03:51,020 --> 00:04:03,360 OpenVM tools shares a lot of code with VMX, like IO function, event loop, and this can really speed up your reverse engineering procedure. 42 00:04:03,620 --> 00:04:14,240 And also, as a beginner, you may need to collect CVs, papers, device documents, and even check the QEMU code. 43 00:04:14,240 --> 00:04:18,680 Just utilize every information you can find to reverse engineering. 44 00:04:20,340 --> 00:04:25,180 So, first question, where should we start? 45 00:04:25,300 --> 00:04:33,190 If you already learned something about Hypervisor, there's always a loop that handles switching in or switching out of the visual machine. 46 00:04:33,680 --> 00:04:41,660 So we will locate the loop code and start reverse engineering the Hypervisor from there. 47 00:04:42,100 --> 00:04:50,890 Also, we know that VMX is a user-mode process, so it should access the kernel for switching. 48 00:04:50,890 --> 00:04:53,850 So they should have a kernel module. 49 00:04:54,250 --> 00:04:58,130 And on Windows, it's VMX86. 50 00:04:58,290 --> 00:05:06,490 And if we are talking about the EXXI, it just directly communicates with the VM kernel. 51 00:05:07,210 --> 00:05:17,510 And tools such as API Monitor can help us analyze the communication process between the VMX and the host OS kernel. 52 00:05:19,710 --> 00:05:29,310 And so, of course, the OS lock screen can help us to figure out the meaning of the device IO control. 53 00:05:31,330 --> 00:05:36,330 So it won't be hard to locate the main loop code. 54 00:05:36,330 --> 00:05:48,190 You can see that VMX uses the IO control ROM VM switch into the visual machine and blocks it until the visual machine needs to force you to help. 55 00:05:48,550 --> 00:05:58,710 VMX will get the return code of the IO control ROM VM and call the corresponding user RPC handler to handle the visual machine request. 56 00:06:00,230 --> 00:06:03,590 So what is the user RPC? 57 00:06:03,790 --> 00:06:11,650 And it's a mechanism that VMware designed for VMM to interact with VMX on host. 58 00:06:11,850 --> 00:06:18,430 And very similar to hypercode, but on user space process VMX. 59 00:06:18,950 --> 00:06:23,510 And user RPC contains lots of code related to device emulation. 60 00:06:23,570 --> 00:06:27,210 And basically, it is the start of device emulation. 61 00:06:28,710 --> 00:06:35,230 And it will only take one argument, which is user RPC block pointer. 62 00:06:35,490 --> 00:06:38,590 And it's a shared area memory region. 63 00:06:38,950 --> 00:06:44,490 Shared area is another mechanism for shared data with VMX and VMM. 64 00:06:44,790 --> 00:06:52,050 You may not be able to see some data be changed in VMX because they may be modified in VMM. 65 00:06:52,050 --> 00:06:59,950 So if we want to know what is passed in user RPC block, we should figure out how the shared area works. 66 00:07:01,570 --> 00:07:08,330 The implementation of shared area is related to creation and loading of VMM. 67 00:07:08,830 --> 00:07:18,330 So we need to study it from the initialization process and pay attention to every memory location cost. 68 00:07:18,450 --> 00:07:24,710 And also remember to check the interaction between VMware VMX and VMX86. 69 00:07:26,570 --> 00:07:34,430 We will notice that there is a EOF object called a VMM block embedded into VMX binary. 70 00:07:34,850 --> 00:07:40,570 Also, there are lots of VMM extensions stored in VMM block section. 71 00:07:40,570 --> 00:07:43,670 And these are also EOF objects. 72 00:07:43,910 --> 00:07:54,270 VMX will link them with VMM block in memory to construct the actual VMM binary according to the user's configuration. 73 00:07:56,910 --> 00:08:01,310 Okay, let's take a look at the VMM block. 74 00:08:01,310 --> 00:08:14,450 We can see there are predefined export symbols such as user RPC block and their corresponding mapping address in the shared private CPU VMX section. 75 00:08:14,750 --> 00:08:18,770 And some virtual devices require the shared memory too. 76 00:08:18,910 --> 00:08:23,630 So VMX will define this export or symbol in it too. 77 00:08:23,930 --> 00:08:34,490 And after these symbols have been defined, VMX will calculate the total size of shared area memories and allocate the corresponding memory space. 78 00:08:34,690 --> 00:08:41,170 Now we have seen how shared memory were allocated, but how do VMM access them? 79 00:08:42,790 --> 00:08:47,130 You will notice that VMM block has two sections. 80 00:08:47,130 --> 00:08:55,790 One of them contains VMM's GDT information and the other contains the VMM's virtual address mapping information. 81 00:08:58,050 --> 00:09:05,950 And combining this information, we will see VMX is responsible for allocating memory. 82 00:09:06,090 --> 00:09:11,210 And building the page table structures based on VMM block's information. 83 00:09:11,270 --> 00:09:22,130 And the VMX86 will further populate the page table information and allow the VMM EO file, which is constructed by VMX. 84 00:09:22,430 --> 00:09:29,830 And VMX, VMM block, VMX86 work together to build the VMM's environment. 85 00:09:30,330 --> 00:09:34,030 And mapping the host allocated address to VMM's virtual address. 86 00:09:34,030 --> 00:09:42,310 So if you need to know how to manipulate data in shared area region, you will need to check the VMM's code. 87 00:09:44,110 --> 00:09:52,750 And VMX choose to run which user RPC code handler is depending on the return code of the IO control VM run. 88 00:09:52,810 --> 00:09:58,330 So it's time for us to check how VMware's switch works. 89 00:09:58,790 --> 00:10:03,510 And the most important structure is cross page. 90 00:10:03,510 --> 00:10:11,790 It's a one page size memory region allocated for each vCPU by VMX86. 91 00:10:12,030 --> 00:10:18,430 And it's responsible for storing the context between VMM and the host. 92 00:10:18,450 --> 00:10:23,270 Just like the VM says, VMCS in Intel VT. 93 00:10:24,410 --> 00:10:32,050 We can check the monitor loader section to see its virtual address on the VMM's environment. 94 00:10:33,430 --> 00:10:43,770 When VMX call the IO control run VM, it will cause the VMX86 cause the host to switch to VMM code. 95 00:10:44,030 --> 00:10:51,690 And saving the CPU state to cross page and restore the VMM's CPU state. 96 00:10:51,850 --> 00:10:57,330 And the operation to switch out is the opposite of this process. 97 00:10:58,830 --> 00:11:07,150 Now we can check the VMM's code to see user RPC is implemented through the platform user code. 98 00:11:07,210 --> 00:11:13,190 And save the user RPC opcode and the platform code invocation number 100 to the cross page. 99 00:11:15,130 --> 00:11:25,350 And the platform code 100 will cause the VMX86 to return the user RPC code to VMX. 100 00:11:25,350 --> 00:11:32,430 So when IO control run VM returns, VMX can call the corresponding user RPC code handler. 101 00:11:33,010 --> 00:11:44,630 Also, whenever VMM prepares to call user RPC, you will see VMM modify the user RPC block to transfer data to VMX process. 102 00:11:47,230 --> 00:11:53,170 So now we finally understand the whole user RPC implementation. 103 00:11:53,430 --> 00:12:01,030 And based on this knowledge, we are able to further reverse the engineering the device visualization. 104 00:12:01,730 --> 00:12:14,430 For port IO emulation, VMM will reserve the x86 IO instructions and may attempt to use the user RPC to call VMX to process. 105 00:12:16,450 --> 00:12:23,290 And not all of the port IO callback will be registered in VMX process. 106 00:12:23,330 --> 00:12:27,910 There are some devices implement their IO callback in VMM. 107 00:12:29,230 --> 00:12:41,170 For MAMIO, in most cases, VMX associates the memory region with an ID and implement the callback in VMM. 108 00:12:43,550 --> 00:12:52,650 And most MAMIO functions in VMM automatically will call user RPC to handle the device emulation. 109 00:12:52,810 --> 00:12:57,350 But they may access the shared area to transfer data to VMX. 110 00:12:57,350 --> 00:13:05,750 So you need to check the code in VMM to understand what happened when you access the MAMIO region in guest machine. 111 00:13:08,130 --> 00:13:13,580 Also, physical memory access is another important part we need to analyze. 112 00:13:14,310 --> 00:13:18,700 We will not discuss too much about the memory mapping structure. 113 00:13:19,270 --> 00:13:24,560 But you should know that on Windows, the main guest memory is mapped as a file. 114 00:13:25,130 --> 00:13:30,230 And on EXXI, it is mapped by VMKernel. 115 00:13:30,890 --> 00:13:37,610 When VMX gets the physical memory region object, it will first check the object's type. 116 00:13:37,610 --> 00:13:42,530 And in most cases, it will directly access the point field. 117 00:13:44,410 --> 00:13:56,970 And the last interesting thing is we also found that on EXXI's VMM, some visual devices MAMIO will not always call user RPC. 118 00:13:57,430 --> 00:14:02,610 They will call user RPC only when hosted emulation is enabled. 119 00:14:02,950 --> 00:14:14,670 Instead of using user RPC to interact with VMX, they use VMK code directly called VMKernel to handle device emulation. 120 00:14:15,410 --> 00:14:25,550 So although VMX are identical on EXXI and Workstation, visual device emulation code won't always be the same by default. 121 00:14:29,530 --> 00:14:36,350 And basically, this graph describes the result of our VMware hypervisor analysis. 122 00:14:41,700 --> 00:14:49,400 Anyway, it is important for you to check the VMM code when you reverse engineering the device visualization. 123 00:14:49,660 --> 00:14:56,980 If you are not sure where device's data comes from, you can go check the VMM's code. 124 00:14:57,120 --> 00:15:04,140 If you are not sure how to trigger the device's code, you can go check the VMM's code. 125 00:15:04,740 --> 00:15:12,260 And if you want to find some new device's code, go check the VMM's code. 126 00:15:15,590 --> 00:15:23,360 Okay, let's enter in the second part, VMware device visualization bug hunting. 127 00:15:23,360 --> 00:15:29,320 Okay , let's start from the USB part. 128 00:15:29,320 --> 00:15:34,260 Basically, we can divide the USB emulation into three parts. 129 00:15:34,260 --> 00:15:43,420 USB host controller emulation, like EHCI, EHCI, XHCI. 130 00:15:44,360 --> 00:15:48,260 The second part, VUSB emulation. 131 00:15:48,520 --> 00:15:52,360 These are objects described in the USB specification. 132 00:15:52,360 --> 00:15:59,880 For example, URB object, USB pipe object, and USB port object. 133 00:16:00,640 --> 00:16:05,600 And the third part, VUSB backend device emulation. 134 00:16:05,600 --> 00:16:16,040 And these are actual USB devices, such as Bluetooth, HID, and RNG, and so on. 135 00:16:16,900 --> 00:16:39,920 So, as you can see, when guests want to access the USB device, it will need to put data in memory and access the host controller MMIO space, which will trigger the VMM handler's MMIO access, causing the corresponding user RPC co-handler in VMX. 136 00:16:39,920 --> 00:16:49,040 Then it will convert the data into URB object, and eventually processed by the backend USB device. 137 00:16:49,280 --> 00:16:57,160 If it tries to access a USB device plugged in the host machine, it will also need another service to help. 138 00:16:57,600 --> 00:17:02,620 And we actually find bugs in all these three parts. 139 00:17:04,400 --> 00:17:12,560 The fourth bug is in the host controller part, and it's an uninitialized memory. 140 00:17:13,520 --> 00:17:18,280 Before we start it, let me just explain some concepts. 141 00:17:18,440 --> 00:17:31,120 In control transfer, a USB device accepts a type of request called a standard device request, which begins in the format of setup packet. 142 00:17:31,140 --> 00:17:40,220 So it will be 8 bytes at least, and it has a w-length field, the length of subsequent data. 143 00:17:41,840 --> 00:17:49,740 The USB device may use this type of data, but the host controller does not transfer data based on this unit. 144 00:17:49,740 --> 00:17:57,740 For example, in UHCI, data is transferred in units of transfer descriptors. 145 00:17:58,540 --> 00:18:16,400 So when VMX handles the UHCI emulation, it retrieves the first TD on QuickHead and extracts the w-length field from the setup packet, and uses this size to determine the size of data buffer for URBObject. 146 00:18:17,140 --> 00:18:27,720 After allocation is finished, it will copy the data into URBObject, and they do lots of checks to prevent buffer overflow. 147 00:18:28,760 --> 00:18:31,980 Let's go back to the allocation process. 148 00:18:32,060 --> 00:18:39,660 It's actually when we're depending on the target USB device you are transferring to. 149 00:18:39,820 --> 00:18:46,560 A different type of backend USB device will result in URBObject with different fields. 150 00:18:46,940 --> 00:18:56,400 For example, HID device will allocate URBObject with all the additional fields besides the data buffer of the URBObject. 151 00:18:56,500 --> 00:19:01,360 Also, HID device will use malloc for data location. 152 00:19:05,020 --> 00:19:08,060 So there are some problems here. 153 00:19:08,120 --> 00:19:14,700 Allocating w-length size URBObject doesn't mean you will get the w-length size data from guest-supplied TDs. 154 00:19:14,920 --> 00:19:18,780 And malloc allocation lets the memory un-initialized. 155 00:19:19,040 --> 00:19:23,720 Also, backend USB device will return data through the same URBObject buffer. 156 00:19:23,740 --> 00:19:28,280 So it will eventually let the HIP data leak to the guest OS. 157 00:19:30,720 --> 00:19:37,220 And the second bug is user-after-free appeared in the USB emulation code. 158 00:19:37,760 --> 00:19:42,020 Again, let's first explain some concepts. 159 00:19:42,500 --> 00:19:51,460 In XHCI, there is a structure called device context which stores the USB device status. 160 00:19:51,460 --> 00:19:56,520 It is constructed by device-slot-context and endpoint-context. 161 00:19:56,720 --> 00:20:01,740 Device-slot-context holds the USB device information. 162 00:20:01,780 --> 00:20:05,620 Endpoint-context holds the information for a single endpoint. 163 00:20:05,940 --> 00:20:09,800 Also, each endpoint has one or more transfer rings. 164 00:20:09,800 --> 00:20:15,140 The data transfer requires blocks on the transfer rings. 165 00:20:15,200 --> 00:20:18,560 And XHCI transfer data is based on these units. 166 00:20:20,000 --> 00:20:24,560 In order to explain this bug, we need to look back at an older bug. 167 00:20:24,780 --> 00:20:28,300 And the old bug's patch is very interesting. 168 00:20:28,300 --> 00:20:36,660 It only alters the sequence between the calls to release transfer ring and the code that assigns values to endpoint-context. 169 00:20:37,540 --> 00:20:42,360 Let's first figure out how transfer ring release works. 170 00:20:44,660 --> 00:20:51,060 Firstly, it will get the transfer ring object from the endpoint-context. 171 00:20:51,160 --> 00:21:00,780 Then, it will retrieve the USB device object based on the USB port number saved in the device-slot-context. 172 00:21:01,470 --> 00:21:10,030 Then, it will obtain the USB pipe object from the USB device object based on the endpoint ID. 173 00:21:10,680 --> 00:21:17,340 And after that, it will release all the URB objects on that USB pipe object. 174 00:21:17,500 --> 00:21:21,460 And finally, it will release the transfer ring object. 175 00:21:23,420 --> 00:21:34,920 Also, it will release the possible URB object on the back-end USB device in case there may be a dangling pointer on the back-end USB device. 176 00:21:36,140 --> 00:21:39,720 So, it seems no problems here. 177 00:21:39,820 --> 00:21:47,200 However, it's actually not the URB object that could become the dangling pointer. 178 00:21:47,200 --> 00:21:54,320 It is because the transfer object pointer is not only held by the endpoint-context. 179 00:21:54,700 --> 00:22:00,420 A URB object also holds a point that points to a field of transfer ring object. 180 00:22:00,620 --> 00:22:10,240 And this field is responsible for tracking the corresponding TRP when XHCI returns the USB device response to the guest. 181 00:22:11,940 --> 00:22:24,000 And before the patch, XHCI command-like config endpoint could modify the endpoint-context contents before releasing the transfer ring. 182 00:22:24,000 --> 00:22:32,060 So, it may lead the type stored in endpoint-context mismatch with the USB pipe object type. 183 00:22:33,640 --> 00:22:44,900 And this will cause the function written without a USB pipe object and left the URB object on that USB pipe object not be freed. 184 00:22:45,600 --> 00:22:52,920 And the previous pointer now becomes a dangling pointer and causing user after-free. 185 00:22:53,300 --> 00:23:03,900 So, now our question is, after this patch, is it possible to make the USB pipe object mismatch again? 186 00:23:05,140 --> 00:23:13,220 We know vmx will need to check the port number stored in slot-connect to find the USB device object. 187 00:23:13,620 --> 00:23:20,560 So, if we can modify the port number, it may lead vmx find a wrong USB device object. 188 00:23:20,820 --> 00:23:25,540 So, in that case, it will also find a wrong USB pipe object. 189 00:23:27,300 --> 00:23:31,720 So, we do have address-device command can make this possible. 190 00:23:31,840 --> 00:23:39,060 You can see the address-device command only modifies the slot-context and the control-endpoint-context. 191 00:23:40,000 --> 00:23:49,400 So, firstly, we finish the device configuration process and we create the transfer ring on non-control-endpoint. 192 00:23:49,700 --> 00:23:54,360 And then we transfer URB data on these transfer rings. 193 00:23:54,460 --> 00:24:00,560 In the end, we use the address-device command on that device to modify the device port number. 194 00:24:01,040 --> 00:24:10,440 Now, if we try to release the transfer ring on that endpoint, it will fail to find the right USB pipe object and causing UEF again. 195 00:24:11,040 --> 00:24:16,320 So, this is a bug that happens between host controller and the USB emulation. 196 00:24:16,800 --> 00:24:22,500 And the cause is it fails to manage the object lifetime in USB emulation. 197 00:24:24,660 --> 00:24:29,570 And the third bug is in the USB backend device emulation. 198 00:24:30,280 --> 00:24:35,610 And it is out-of-boundary will be triggered within the system API. 199 00:24:38,740 --> 00:24:41,600 Let's start with some concepts. 200 00:24:41,960 --> 00:24:47,820 The guest OS communicates with the smart card through the virtual smart card reader. 201 00:24:48,920 --> 00:24:54,980 And the guest OS uses CCID protocol to interact with the virtual smart card reader. 202 00:24:56,600 --> 00:25:05,840 The application data units, APD, serve as the payload for interaction between the smart card reader and the smart card. 203 00:25:06,440 --> 00:25:13,080 And you can see their relationship are very like the host controller and the USB device. 204 00:25:13,340 --> 00:25:20,440 And you may already seen that both of these data structure has the length field. 205 00:25:21,720 --> 00:25:27,440 And it is always need to be careful handling this length field. 206 00:25:28,280 --> 00:25:36,600 VMware do checks whether the message length field of CCID protocol matches the length field of command APD. 207 00:25:36,940 --> 00:25:41,920 But it fails to verify whether these two fields conform to the size of URP buffer. 208 00:25:43,520 --> 00:25:50,420 It directly uses this field as arguments to call the Windows sCAD transmits API. 209 00:25:50,820 --> 00:25:55,740 Clearly, sCAD transmits cannot check whether the length matches the data buffer. 210 00:25:56,540 --> 00:26:03,280 So it will out-of-bound access to the heap data and write it to the smart card on your host. 211 00:26:03,280 --> 00:26:06,920 Also, you may be able to read it back. 212 00:26:06,920 --> 00:26:09,500 So it's kind of interesting. 213 00:26:12,200 --> 00:26:19,320 Okay, in conclusion, it's very challenging to defend such complex system. 214 00:26:19,380 --> 00:26:22,160 VUSB emulation can be attacked. 215 00:26:22,200 --> 00:26:25,260 USB device emulation can be attacked. 216 00:26:25,480 --> 00:26:29,800 And host consoler emulation can be attacked too. 217 00:26:30,740 --> 00:26:34,700 Also, we still have cases cannot present. 218 00:26:34,700 --> 00:26:38,200 But you can defer the binary to found. 219 00:26:40,260 --> 00:26:44,640 And maybe more attack scenarios in the future. 220 00:26:44,760 --> 00:26:53,320 Maybe plugging evil USB device and leverage the VMX to execute the code. 221 00:26:53,320 --> 00:26:58,680 Or leverage local USB service to privilege escalation. 222 00:27:00,700 --> 00:27:04,780 And anyway, that's the USB part. 223 00:27:04,860 --> 00:27:11,120 And next part will be presented by my colleague. 224 00:27:11,220 --> 00:27:18,440 And we will show you that how SCSI works different on ESXi and the workstation by default. 225 00:27:24,870 --> 00:27:25,870 Hello, everyone. 226 00:27:25,870 --> 00:27:26,790 I'm Zhenghao. 227 00:27:26,790 --> 00:27:29,630 I'm the speaker on this topic. 228 00:27:29,630 --> 00:27:35,070 Now it's my turn to expose VMkernel, a whole new attack surface. 229 00:27:35,530 --> 00:27:42,550 But I will first talk about some differences between ESXi and the workstation. 230 00:27:42,550 --> 00:27:48,230 Because our new attack surface is hidden in these small differences. 231 00:27:48,970 --> 00:27:57,410 ESXi is a type 1 hypervisor that runs directly on the host's physical hardware. 232 00:27:57,410 --> 00:28:08,510 Well, workstation is a type 2 hypervisor that is installed on top of an existing host operating system. 233 00:28:08,510 --> 00:28:14,490 Workstation sports more configurations and devices than ESXi. 234 00:28:14,490 --> 00:28:23,550 Which means that in certain situations, workstation can be audited at more points than ESXi. 235 00:28:23,550 --> 00:28:33,490 In some specific device, the data flow direction of ESXi and workstation is different. 236 00:28:33,490 --> 00:28:50,290 Next, I will take SCSI device emulation as an example to demonstrate the vulnerabilities on different attack surface caused by different data flow orientations. 237 00:28:50,870 --> 00:28:56,090 This is an overview of the SCSI data flow. 238 00:28:56,090 --> 00:29:02,170 You can see that there are two paths for writing data to the disk. 239 00:29:02,170 --> 00:29:06,750 One through VMkernel and one through VMX. 240 00:29:06,750 --> 00:29:15,970 These are two completely different code paths, belonging to ESXi and workstation, respectively. 241 00:29:17,390 --> 00:29:25,150 The specific code path of SCSI in workstation is shown in the figure. 242 00:29:25,150 --> 00:29:48,110 If the user calls the MPI function SCSIioRequest command, it will enter the LSI logic MPO process SCSIioMessage function, where it will confirm whether the environment is hosted emulation. 243 00:29:48,110 --> 00:30:02,510 Finally, the LSI logic hosted process SCSIioMessage function calls the relevant handler in VMX through user RPC. 244 00:30:02,530 --> 00:30:11,410 The specific code path of SCSI in ESXi is shown in the figure. 245 00:30:11,410 --> 00:30:21,410 ESXi divides the situation into whether the environment itself is in hosted emulation. 246 00:30:21,490 --> 00:30:28,710 If it's in hosted emulation, it's the same as the workstation path. 247 00:30:28,710 --> 00:30:37,630 Otherwise, it goes to LSI logic VMk process SCSIioMessage. 248 00:30:37,630 --> 00:30:43,510 Go to VMkernel through VMk call arguments. 249 00:30:45,710 --> 00:30:56,250 Because of this small code gap, ESXi has a new attack surface that workstation does not have. 250 00:30:56,250 --> 00:31:04,290 Next, I will introduce the vulnerabilities I found on these two different parts. 251 00:31:04,830 --> 00:31:18,990 The first vulnerability we will talk about is located in VMX, and the official description is out-of-bounds read-write vulnerability. 252 00:31:19,790 --> 00:31:30,270 As a tool for storing data, stability is the most critical and basic requirement for disk. 253 00:31:30,270 --> 00:31:38,540 VMware implements corresponding disk verification capabilities in device emulation. 254 00:31:38,810 --> 00:31:47,310 One of the disk verification capabilities is to detect data corruption through chipset. 255 00:31:47,310 --> 00:31:52,030 This is where the vulnerability occurs. 256 00:31:52,550 --> 00:31:59,010 Before we start, let's first introduce a SCSI command. 257 00:31:59,010 --> 00:32:18,050 In the SCSI command's reference menu, there is a command called write16 that allows the operation of 8-byte logical block address and 4-byte transfer length. 258 00:32:18,050 --> 00:32:33,050 This shows that we can use this command to access any address in the 64-bit space, provided there is no disk capacity limit check. 259 00:32:33,910 --> 00:32:44,130 VMware did not implement the disk capacity limit check in its disk verification program implementation. 260 00:32:44,810 --> 00:33:04,050 As can be seen in the figure, after applying for a heap of corresponding size according to the disk capacity, only the operation is checked to see if it is a read or write operation. 261 00:33:05,010 --> 00:33:09,830 Obviously, this is a heap overflow. 262 00:33:09,830 --> 00:33:23,350 The write16 and other read and write commands in the SCSI command's reference menu allow us to access any 8-byte address. 263 00:33:23,350 --> 00:33:30,610 This allows us to easily perform arbitrary read and write operations. 264 00:33:31,330 --> 00:33:43,530 The vulnerability we will discuss next is located in VMkernel, and the official description is out-of-bounds read. 265 00:33:44,150 --> 00:33:49,310 Still start with the SCSI command's reference menu. 266 00:33:49,310 --> 00:34:03,410 In the SCSI command's reference menu, there is a command called unmap, which can unmap one or more logical basic addresses. 267 00:34:04,430 --> 00:34:14,350 The structure of unmap itself is relatively complex, and is divided into three parts. 268 00:34:14,350 --> 00:34:22,030 unmap command, unmap parameter list, and unmap block descriptor. 269 00:34:22,030 --> 00:34:32,950 Let's first look at the structure definition of unmap command in the SCSI command's reference menu. 270 00:34:32,950 --> 00:34:44,310 The focus of the figure is the parameter length, which indicates the total length of the unmapped parameter data. 271 00:34:44,390 --> 00:34:57,870 The unmapped parameter list is divided into two parts, unmapped parameter list header and unmapped block descriptor data. 272 00:34:57,870 --> 00:35:11,050 The unmapped parameter list header consists of three fields, unmapped data length, unmapped block descriptor data length, and reserved. 273 00:35:11,370 --> 00:35:22,890 The unmapped block descriptor consists of two fields, unmapped logical block address and number of logical blocks. 274 00:35:22,890 --> 00:35:33,070 These two fields indicate the starting address and length of the block that the user wants to unmap. 275 00:35:33,110 --> 00:35:46,330 This is an open view of the three unmapped structures, so that everyone can easily understand the structure of the unmapped command. 276 00:35:47,270 --> 00:36:00,210 The three structures are very closely related, and we will focus on parameter list length and unmapped block descriptor data length. 277 00:36:00,210 --> 00:36:03,670 Both fields indicate the length. 278 00:36:03,670 --> 00:36:14,050 Unmapped block descriptor data length indicates the length of all subsequent unmapped block descriptors. 279 00:36:14,050 --> 00:36:27,790 Parameter list length includes not only the length of all unmapped block descriptors, but also the length of the unmapped parameter list header. 280 00:36:28,130 --> 00:36:38,810 Let's see how VMware implements the unmapped command according to the SCSI command's reference menu. 281 00:36:38,970 --> 00:36:50,450 Before actually running the unmapped command, the vscsi-check-unmapped-cmd function will be entered first. 282 00:36:50,450 --> 00:37:05,850 In this function, a heap of the corresponding size is requested according to the parameter list length, and all the unmapped data is copied to the heap. 283 00:37:05,890 --> 00:37:13,650 After the unmapped data is copied, the content of the data will be checked. 284 00:37:14,030 --> 00:37:24,350 But it forgets to check the relationship between parameter list length and unmapped block descriptor data length. 285 00:37:24,350 --> 00:37:34,770 And the number of unmapped block descriptors is determined based on the unmapped block descriptor data length. 286 00:37:34,770 --> 00:37:49,850 The user can set a special parameter list to carry a large number of unmapped block descriptors, but only check the first unmapped block descriptor. 287 00:37:50,230 --> 00:37:52,510 Check completed. 288 00:37:52,510 --> 00:37:55,650 Enter the actual use stage. 289 00:37:55,650 --> 00:38:13,830 According to the code in the figure, parameter list length is used as the boundary length, which allows the previously unchecked unmapped block descriptor to be put into use. 290 00:38:13,830 --> 00:38:23,710 The unchecked logical block size is used as the size variable in the code shown in the figure. 291 00:38:23,710 --> 00:38:27,030 An obvious out-of-bounds write. 292 00:38:27,030 --> 00:38:38,890 In fact, it's this out-of-bounds write that actually causes the crash, not the so-called out-of-bounds read. 293 00:38:39,350 --> 00:38:48,790 Regarding the new attack surface of VMkernel, I have summarized the following three major points. 294 00:38:48,790 --> 00:38:54,050 Modify the existing sandbox protection mechanism. 295 00:38:54,050 --> 00:38:58,310 Elevate the current process privileges. 296 00:38:58,310 --> 00:39:00,590 Virtual machine escape. 297 00:39:00,650 --> 00:39:03,770 Okay, thank you for your listening. 298 00:39:03,770 --> 00:39:08,910 If you have any problem, you can contact us with Twitter.