Gentlemen have come all the way from China to talk to you guys about breaking Google Home and exploiting it with SQLite. Let's give them a gigantic round of applause. Have a great time. Smile. I'm going to take pictures. Have fun. Thank you. Hello everyone. Thank you for coming. We are very excited to share our search at DevCon 27. The title of our talk today is Breaking Google Home, Exploiting it with SQLite, Measuring Vulnerability. First, let me introduce my teammates and myself. We are senior security research at Tencent Blade Team and this is my teammate Chen Yuxiang. Now he's focusing on browser security and IoT security and this is Lin Yuxiang. He is focusing on mobile security and IoT security and my name is Wu Huiyi. I'm a bug hunter and a key partner. I'm also speaker, I'm also speaker for DevCon, Hacking Boards and POC. Next, I will introduce the Tencent Blade Team. Our team was funded by Tencent Security Platform Department at 2017. And now we are focusing on the security research in areas such as AI, IoT devices, mobile devices, cloud and browser security. We are focusing on the blockchain. In the past years, we have reported more than 200 security vulnerabilities to many companies such as Google, Apple, Amazon, Microsoft and so on. Last year, we shared how to break Amazon Echo at the DevCon 26, so we can again this year. And you can connect us at blade.tencent.com. So, we are very happy to be here today. We are very happy to be here. Next, let's take a brief look at the alternate. First, we will introduce the attack surface of Google Home smart speaker. Then, we will share the details on how to find and explore the light and the curve. Finally, we will summarize our research. Okay, let's start with the first part. . Smart speakers are the most popular smart home devices of the past three years. Amazon, Google and some Chinese companies are the main players in this field. In the fourth quarter of 2018, Amazon and Google's market share has been very similar. After we shared the, uh, after we shared how to break Amazon Echo and Xiaomi AI speakers, in DevCon 26 we began to start is the security of Google Home smart speaker. The Google Home family include four devices, all of which have similar hardware. We choose the best selling Google Home Mini as the main tester devices. The first part is about hardware analysis. We find that the Google Home Mini used the OneWare CPU and the Toshiba's flash chip, but we didn't, did not find any debugging and flashing interface. So, we can only choose to extract firmware directly from the flash chip. Similar to the Amazon Echo, we first use a heat gun to solder the chip from the board. By analyzing the data sheet of the chip, we find a test circuit. The test circuit is a test circuit of BGA67 chip. And the difference is that the pins of BGA67 chip are very thin. So, we have not found an adapter that can connect the test circuit to the programmer. So, we designed a new adapter. It's main function is to explore the pins of the test circuit to a large pitch. The pins show that we can connect the test circuit to a large pitch. So, we can easily connect the chip to the programmer. And this is the finished product that we finally produce it. We connect it to the RT9088 programmer, which is a universal programmer that supports reading and writing most of flash chips. Finally, we gathered the RAM and just data in Google Homes flash chip and мож石了这 pack轣去试试用HM O cloud. So, about We also need to pass the OOB data and ECC trigger piece according to the specification in the datasheet and extract the company system firmware. By analyzing the system first you can know that Google Home is using a NAT Chromium OS. The map- the main function are implemented by the Chromium OS- by the Chromium browser. And the update speed will be a- a little slower than the Chromium browser. Okay. My part ends here. And- and my teammate Ni Yuxiang will continue to share the next part. Uh thanks for your introduction. Next uh let's introduce the security overviews of Google Home. Uh firstly let's look at the security overviews of Google Home. On the OTA mechanisms the firmware related results of Google Home is open to public. These results uh include bootloader kernels and related bu- bun- uh binaries programs and some even has symbols. Google Home used the HTTP request to download the firmware. We can also simulate the request for the- for the security overviews of device update. The latest OTA package can be obtained by the curse command in the pictures uh below. So we can easily to get the firmware and then try to analyze the firmware. Uh through the analyze of firmware and related resource we believe that the security mechanism adopted by Google Home is worth learning. About lens. Enabling security boot on IOT devices in- is a good example. The bootloader boot image system images is protected by the security mechanism throughout uh boot process. The details as follows. The boot loader and boot images use the same sensors, methods and- uh in-play with shs and ices sensors. The bootloader seen that there is no logic to provide unlocking. Uh in addition Google Home also pro- uh uh performer integrities uh veri- verifications on system image. Uh let's look at the uh main programs in the fanvirus. The fanvirus has uh memory directories as shown in these pictures. That contains a main program called Cardshell. The program just like Chrome so it's program is protect by sandbox. On Chrome OS the sandbox mechanisms mainly includes the UID, UANAN space and sitcom BFF. In addictions the system also enable ASLRs and uh Cardshells also add annex and uh stack gannery. Next we will introduce the attack surface on Google Homes. Combined with existing security research and our tech things Google Homes attack surface include the following uh four aspects. G- Google Home has multi- multiple parts uh port opens once of the port is the 80808 is the un-FTP servers uh we can control some basic operations of Google Homes through this port in the LAN. There is also a port of 8009 the port is the target of our attacks using the card protocol. We will describe in the following sections. And the wireless interface is also a attack surface. Google Homes use the mobile chip. Some idea about mobile wifi and BLE fanvirus attack can be tried. It is also possible to try to uh find uh vulnerabilities of the bootloaders and let it load malicious fanvirus. Finally we can try to find another uh other uh hardware interface. In this section we will show you how to extend the attack surface of Google Homes. First let's introduce the basic knowledge about a protocol. Uh Google allow developer to develop cask apps and power it to every store. In general the cask app include senders and receivers. Sender devices maybe mobile devices or PC running on chrome. Uh receiver is uh Google's IoT devices such as Google Home. The entire architecture is as follows. You will assess the sender application rail and the sender application and the application is used as a use the CAST protocol to find the receivers in the LAN. When the receiver uh is discarded the sender application will communicate directly with the URLs uh with the reader applications on the receivers with the CAST protocol. Uh in detail the Google Homes will pull the URLs of each receiver application according to the CAST app ID and accept the receiver application through the Chrome Renders. After our attempt we found that uh CAST protocol will have the following uh security uh security risk including the CAST IP can be any web page. The CAST IP is the IP store may be malicious. Uh and uh senders can directly trigger uh CAST protocol which may even require no user interaction. Based on this uh this security risk we can govern an attack. Uh a Google Home into uh attack on our browser. Let's take a look at uh some special states. The attacker is registered as the CAST developers. CAST application can be developed and distributed. When you publish an applications you need to specific uh CAST receiver URLs. However, Google does not all your lines are CAST IPs. Lans can can specific it as a web page in any context. Remote trigger the Google Home to access any code and then want to make web page. If, if the attackers and Google Homes are in the, in the land, the attackers can also send a CART protocol such as the launch request. This request view directly triggers Google Home or step to the CART receiver URL. To make matters worse, if the routers in the victim's home, homes, uh, turn on the UPNP port forwarding, the attacker can also complete a remote sign attacks on the internet. The attackers modify the CART, uh, receiver URL web page to, uh, malicious, uh, page. Lens Google Homes may assist in vendors after visiting the page. So, now we only need to, uh, Chrome assist vulnerability to exploit Google Homes. Now, Wenchang Chen will introduce, uh, microlens and other vulnerabilities. Um, okay. So, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, okay. Thank you for, uh, the introduction. Now, I will continue with, uh, part three. Um, fuzzing and, uh, manual auditing, SQLite and LabCurl. Uh, first, why do I audit these two libraries? Um, because third-party libraries are always sweet, they have less code and, uh, focused functions. And almost every device has them installed. And the most important thing is Google Home or Google Chrome are using them too. Uh, before introducing the code audit part, I would like to mention some previous researches. Uh, first, Michael Zawiski's fuzzing has significantly improved the, uh, SQLite's quality. And then there's a talk on Black Hat in 2017, which also explains the idea of exploiting SQLite. Uh, after that, there doesn't seem to be a lot of news about the vulnerabilities of SQLite, but we have found some. So, uh, let's talk about SQLite. Uh, in the next part, we will introduce the code auditing and the exploiting of Magellan, which is a set of vulnerabilities in SQLite, and Dias, which is a set of vulnerabilities in LabCurl. The Chromium project comes with a father for SQLite. Uh, we have made some simple changes to it, uh, such as adding some syntax-based files. When we looked back, we found that there were, uh, was a lot of crash files generated. However, these test cases can only trigger empty pointer dereferencing. One of these test crashes is caused by down-plicated primary keys, and when I was bugging, I typed the first three create-a-table statements to see what was going on in memory. However, I was surprised to find that the dot tables command shows six tables. The question is, uh, what those content DL segments stand for? Uh, like, uh, uh, this is the, uh, running, uh, The SQLite manual shows that the tables are called shadow tables. The five types of shadow tables, content, secdl, segments are for FTS3 or 4 and state and doc size are FTS4 only. However, because of those tables are treated like standard tables, you can create corresponding state and doc size table even you are operating on an FTS3 table. Uh, you can create state and doc size by simple, uh, by simple create a table statement. Because the SQLite itself is doing this too. And FTS3 and 4 is sharing some code, which means state and uh, doc size might change the code flow in some conditions. For example, one of our exploits are simulating an FTS4 table on FTS3 environment. Uh, this is useful because some software like Chromium use only FTS3 and FTS4. Uh, you can create state and doc size by simple entertainment. So, we create a model using this model in order to use this model, uh, in specifically disabled FTS4. This will extend the attack surface by entering some code branch that should never be entered. The shadow table is used as a container to store the content of the full-text search metadata. What is shown on this slide is the definition and meaning of each shadow table. We can see that almost every shadow table has a field of type blob. That's because, to support full-text queries, FTS maintains a direct and directują of all the inverted index that maps from each unique term or word that appears in the dataset to the local locations in which it appears within the table contents. It is complicated but all we know is that compared to the other fields those blobs may have some important influence on FTS queries. In SQLite the raw binary data is typically represented in the form of X, single quotation mark and hexadecimal numbers. However the blobs here are binary data to represent the entire B-tree. Since it represents such a complex structure is it possible to create a memory corruption vulnerability by destroying the data of the structure? Let's read about the document of the serialized data structure first. You can check the SQLite menu to easily get the definition. I will show you a simplified version so you can understand what I'm modifying when I'm trying to exploit them. Basically I'm modifying the bytes with the different functional sections to mislead the code flow. The first segment B-tree leaf nodes. The first term stored on each node which is term one in the figure above is the stored verbatim. Each subsequent term is prefixed compressed with respect to its uh to its predecessor. Interior nodes, non-leaf nodes have different structure. And then the document has a different structure. The block list format. A dock list consists of an array of 16 four bit signed integers. Serialized using the FTS var int format. Each dock list entry is made up of a series of two or more integers as follows. One the dock ID value and two the zero or more term offset list. In general those blobs are just serialized B-tree data. When the SQLite wants to perform operations on those tables it will simply deserialize or pass those to the serialized block. This is the kernel of the FTS3. The number of the executors. The number of the executors is 10 to 12. you will have a lot of time to do all the work being done to get a complete B-tree. Then I have found some problems. The problems are mainly treated to merge and match. Because they are deeply related to the B-tree. Two of them merge the node of the tree and other is to traverse the nodes of the tree to try to find a match to the content. Also the last one is a crash I have mentioned before. It was that brought this series of problems into my attention. Software must enable FTS3 to use the inputs and controls in the root of an object. This support and support external SQL query to trigger these problems. Okay the first one and 20346 which is also the main vulnerability we use later to exploit Google Home. It requires a lot of complex preconditions that is we have to carefully construct a lot of tables and content but once the preconditions are met vulnerability explosion will be very simple and stable. The vulnerability is located in the function FTS3 append to node. It can be triggered with a special semantic the merge equals one two which means the level to be merged. As you can see this function will try to append a node to another. The node is stored in the blob so this function and other function will first pass in the B-tree and then get the start position and the length of binary data of the node that will be processed. And last perform the memory copy operation to copy. Okay let's go to its caller function turnkey node. It will get the binary offset and length from the blob data that will describe the node being processed. Then the node information is returned in a reader object passed to the vulnerable FTS3 append to node. To control the memory copy in append to node we need to control a doc list and a end doc list which is returned from node reader next. The end doc list is the source of the char pointer to the blob data and end doc list is the node size. Which are second and third parameter of memory copy respectively. To control them is not a difficult thing. Let's read the code then you will know why I'm saying that is easy. To save the space of storing an integer CircleLite uses a variant integer algorithm. You can just consider Fs get variant 13.2. So we can just save the space of storing an integer. So we can just consider Fs get variant 13.2 as a function to convert a bunch of bytes into an integer. It will store the result in n suffix. Then it will move the current cursor by adding the content of bytes and it will read to i off. The data for a node is stored as a length following by corresponding data with exactly size of a length. Normally they should appear in pairs but we can modify the blob to make the end of the blob boundary has only the length field but no data field. Ok let's go to the append to node. Since uh in the last step a doc list and end doc list is controlled we can now offload the buffer of p node a in line 3 1 0. Or we can copy some raw memory data to it. As long as it does not exceed the aligned value. Then we can query the new table to get the leaked raw memory. By setting up adjacent tables we can offload the function pointers of the table very uh accurately to exploit a code execution. And here's another 1506 in functions to get into real note. And a protecting prediction of this one is rather simpler. All you need to do is to modify the shadow table sit-sit a node in 副ilsir to non root node. You can change the blob data to change the code flow. Query the modified table by keyword match. Then the code will scan every node inside the Ptree. Then the code will trigger memory correction because it has many constrained conditions it was to be very hard to exploit. Um, but this one is, is, uh, exploitable anyway. Uh, you can check the wonderful write up by a Korean researcher named Anki Chen. And last, uh, 20505. This one is very like to a combination of the previous two. The vulnerable function is, uh, seg reader next. You can modify the shadow table and mislead the code flow. All these three vulnerabilities can be modified to leak raw memories. So, we can also use this to leak address of, uh, for example, functions, structures, global variables, constant variables to bypass the ASLR. And here's another one, LabCore. Um, our tag, our target is, uh, remote code execution, but LabCore has already been used by a lot of users and their code, it reads very quickly too. To find a vulnerable function, here are some guidelines for finding vulnerable functions. Uh, the first, find the big functions. Most functions with a lot of lines is not recommended in software engineering and functions that are too long should be refactored into shorter function fragments. Usually, such a large function is difficult to test and there will be a lot of attack surface. And most of the functions enabled in LabCore is related to remote interactions and communicates with the remote server more than once. After a carefully sifting through the protocols, we confirmed that NTLM over HTTP was what we wanted to test. And here are those problems we have found in LabCore. We named them as DS, uh, name of another famous navigator. The first one, um, 890 is a vulnerability in NTLM type 2 message. It can leak at most, uh, 64 kilobytes client memory per request to attacker. The result is very like to the hard play but is client version. And the second one, 3822, is a vulnerability in type 3 message. It will result in, uh, a stack buffer overflow. LabCores also wrote this in his blog and saw this very bad security issue. Okay, let me show you how this happened. The first one. The vulnerable function is in decoder type two target. it reads a 32 bit integer from the type two message header. Then we know we can set, um, a target info offset with a larger value. And target info length to a crafted value which if you add them together an integer overflow will happen. The overflow result is very small and will pass the check in line 185. And next memory copy will copy data out of bounds. For example if we use the value above it will actually copy data from the front of variable buffer in 32 bit environment. And then the data will be sent to the attacker in type 3 message leaking maximum 64 kilobytes data per request to the attacker. And let's go to 382. This vulnerability is located in a big function named curl auscrate NTLM type 3 message. In the beginning this function declares a lot of variable on stack memory. The NTLM buffer is a big buffer which has around uh uh for uh for a uh for a uh for a uh for a uh for a uh for a uh for a uh for a kilobyte memory. Then the function tries to read the NT response length from the type 2 response which is sent from the server. Attack could return a value bigger than the buffer size to client. And that's in line 779. This check should check if the size of the data is bigger than NTLM buff's remaining size. But the in explicit sign unsigned cast prevents the check from operating correctly. This check compares two unsigned tests. This check is a signed variable and a Markov NTLM buff size which simply defines the number a thousand and the 24. But this value is a signed integer in the view of compiler. When unsigned and and signed are compared in the same place some of them must be casted in order to compare correctly. And this is a problem. The compiler prefers to convert signed to unsigned numbers. So if we have NT response length greater than the NTLM buff size the result will be the same. The result will be a large unsigned number and it is of course bigger than the remaining size will pass the check. In line 7 h 1, because NT response length is bigger than the remaining size of NTLM buff hence here will be a stack buffer overflow. When the code triggers a mesh bytes. But instead override the stack variants and control the flow of the code. I marked the position where the, where it triggers the buffer flow. You can see in this big function there are, there are almost 18 lines after it. And many of them are operating heap or stack memory and operating is based on the value of those stack variables. That's the reason why I say big function is never a good coding practice. Okay, my part is done. And, uh, Lee Chang will go ahead to introduce how to exploit. Uh, thank you for my partner's introductions. Now, uh, let's review the following, uh, vulnerabilities. The keys to the vulnerability trigger is how to use the insert state to control the variables used by our memory, memory copy function. Include, uh, the memory copy function and the memory copy function. So, let's go to PN, uh, PNodeA, PNodeN, and ADocLeaks and DocLeaks. The insert data is as follow. First, the entire data is stored in the buffer of PNodeA. Uh, we can control the size of the PNodeA buffers by modifying the length of the insert state. Uh, in heap functions we are able to allow PNodeA to the appreciate areas to cover the, uh, target mem- memory. Uh, in this state, uh, the orange callers in that, indicate that the size of PNodeN and P- uh, N-DocLeaks, which is. We are in type. N-DocLeaks is used to control that length to be overflowed. Uh, PNodeN which is the obsessed of the right our turn memory areas. The green part is the ADocLeaks data which can be used for our B read or O read data. And, uh, write. The next session uh we will we will introduce the ideas of using these vulnerabilities. We expect expect to find a uh function pointer that can be used on the heap. When creating our FTS tree tables the tokenizer is created by default. And the tokenizer default is a simple tokenizer. Uh as shows in uh following pictures. Simple tokenizer is a structures on the heap where it is uh members base points to the SQL trees tokenizer structures. The members pin models or the SQL trees tokenizer structure points to the tokenizer models. The tokenizer models contain some interesting function uh callback functions. Uh the tokenizer function such as the X create X opens. On our lens when inserting the FTS tree tables the X open callback functions will be triggers. Uh if a function address of X opens can be modified to the uh attributes uh expertise address the PCs can be hijacked. Uh how to use the uh variables functions pointers for PC hijacking? Uh here's two conditions. Uh the two conditions need to be met. The first after his overflows is necessary to be able to operate the FTS tree table. In addictions when hijacking needs to be complete before the memory is released otherwise the crash will be interrupt. By analyzing the logical uh memory copy to freeze we found an interesting function. Uh which performed a SQL SQL update operation before releasing the memory as shown in the, the blue tag code. Finally, we use the SQL triggers to perform the FTA tree table insert operation before the SQL update operations and free memories. Since uh triggering the X open callback functions so that the PCs can be hijacked. The next step is to make a memory uh layout. The SQL logical of the card shell is T-MALOCKS. A feasible memory layout idea is as follows. The first by creating a multiple first uh FTA tree tables we will create a multi multiple simple tokenizer structures. Drop the previous uh created FTA tree tables. And then we will create a multiple tokenizer structures. Drop the image on the table to make it add the explained by our own working at the� appreciating the uh simple tokenizer structures, we will be free. The uh uh resizing payloads of the same side as simple tokenizers, it it has the high uh prob probabilities that payloads will be allows to photograph these symbol token structures. So our payloads have a greater joining a simple tokenizer structures of existing FTA tree tables. With the uh secure SQL triggers that perform operations of FTA tree tables before the free. Last are changed as the tokenism model callback functions uh will be triggers to hijack the PC. Uh when we have the ability to hijack the PCs and control the R0 registers we only need to be able to list information and bypass ASLRs. The previous sections uh uh also introduced uh we can try to uh adjust the the underlist PNode A and list memory after heap. We need to describe the following two types of dress. Licking the dress of cut shells based on uh based on this dress and obsessed calculate the required RP gags. Uh licking the dress of the last heap according to this address and obsessed the probabilities of calculating the address of the heaps spray. The latest heaps sprays and ROPs after these three steps we can ask this in Google Home's renders. Uh cut shell is uh like binary program that contain many of the available ROP gags. So the ROP gags that are used in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the uh in the pictures on the right the realize uh marks the red lines mark the heaps sprays units which face tokenism models and ROP gags. The x create x open address in the face tokenism model structures will be aside the state address. The blue lines marks our face simple structure uh tokenized structures. When the FTA tree tables operate can be triggered. SQLite will be get a malicious X open through the structures of simple tokenizers and then RC. Above uh above is the screen source of our RC in cut-to-shelves. The read box on the left show that the register we can control. That that they are R0, R11. The function of jet is read from the R11s and finally is go to BLX. Then as a result we have been able to hijack the PC. The image on the right uh show show the result of our shell codes. We execute uh Javascript codes for fetch URLs and uh navigators, AVP networks, and uh uh the app name in uh exp dot html codes. Normally uh negotiate uh navigators app name is read only and uh and is next give. But our shell codes change the app name to AIA. Uh let's look at some actual attack signs. There are three types of attack vectors that attack Google homes remotely. First, let's look at some actual attack signs. There are three types of attack vectors, we, the attacker is located in uh LAN. The attacker said uh launch ABPID one. Command through uh a cut protocol. And Google home will put a leak doc at TML on the application application stop AB stops according to the ABID and know it. At this time the leak this can be obtain by the attention by the attackers. The second, the attacker send uh launch ABPID two command 938 in. Then the attacker declared that the attacker has been unlocked. The attacker has uh, Google Homes load 8xp.html. So that's the RC happen. The entire process does not require user interaction. In the other two sense, you don't need to be on the same, uh, on the same lens to start the attacks. The attacker inducts the victims to assess the URLs of the sender application and we can scan the networks on the routers that, uh, if the router have the UMP forwardings, try, uh, we can try to launch remote, remote attacks on the Internet. Conclusion. Here the, uh, here is the timelines of the microlens. We have report lens in, uh, November's and is quickly fixed by SQLite and, uh, Chromios. In the design of the microlens, in December's, Google's decide to give us a total 10,000 rewards for the batch of vulnerabilities. And they have, uh, uh, and, and then have, uh, in, enhancements. There is the defense in diff flag. This allowing modifying shadow tables from untrusted source. For backwards compatibility is default off in SQLite. So if you are using SQLite with FTS, you may want to enable this one uh, to prevent the attacker from the modifying your shadow table. But, uh, the good news is is default on in Chrome from commit in the last November. Here is the, uh, timelines of Dias. These quickly fixed and released by in two week. Also, uh, uh, also have uh notif- the sensor to urge vendors dis- disable the one of the vulnerable FTA trees of web SQL before the patch come out. If they don't use these features. And uh we have not notified the security teams of Apple's Interest, Facebook's and Microsoft about how to fix the program and how to mitigate the phrase in the center of their products. So uh we have uh uh to analyze the securities otherwise. The ones enhance your systems with the newest available defense in different mechanism in a time. The two keep your uh the the third pass libraries up to date. Threes improve the quality of security auditing uh auditing and testing of the third pass libraries. For fourth introduce security specifications into the developments and testings. Thank you.