Hello, DEF CON. Thank you for coming to our presentation. We are excited to share our talk titled, Watchers Being Watched Exploiting the Surveillance System and Its Supply Chain. We'll talk about our vulnerability research on surveillance system devices. Please enjoy. First, let us introduce our research group. I'm Chanhee Kim, and I'm currently working as an offensive researcher at S2W. And he's Myungwoo Park, and he's a student attending a university in Korea enjoying offensive research. And this is what we'll show you in this talk. We'll be talking about a $30,000 bounty and a four-month journey to become a DEF CON speaker. In our talk, we'll cover how we extract the firmware, then the steps we took to analyze the vulnerabilities, and after that, the various vulnerabilities that could be exploited in the world and their scenarios. In the last, the impact of our research on the supply chain. That's it. Please look forward to it. This video will be the final goal, which happened in the real world. We wanted to see why we're doing this research. This was posted by an Iranian hacker, and we would like to show that we have successfully demonstrated what the video is showing. Let's watch the video. That's like a hacker from a movie, isn't it? Next, why is making our surveillance device more securely important? We can see surveillance devices everywhere in our lives. Because of the COVID-19 pandemic outbreak, the demand of the surveillance devices has been surging for various purposes, such as a men's store, smart cities, and for those access control. Thus, the global surveillance device market is currently worth $4.1 billion. So, in these circumstances, surrounding by such devices, MVRs are taking on a more essential role in our lives and those users. Next is our target. Many people don't know much about MVR, but as we just highlighted, MVR is more than just important since it plays a brand-like role in all the surveillance systems. Therefore, we selected MVR as our target. So, what is an MVR? A network video recorder called MVR stores recorded video from CCTVs and eye cameras and monitors or manages real-time video. Due to the nature of managing these videos, many devices can access them over the Internet. And the screen you see below is the MVR screen. This is our detailed research motivation. First, as we investigated enough online, there was not as much as studies on it compared to CCTV or IP camera system. And as a result of showdown search, we found that more than 30,000 devices are exposed to the Internet. However, there are cases where critical vulnerability have been discovered previously. There was a case when the Mirai Bonnet became popular in 2021. Hikvision's pre-auth RCE vulnerability was maliciously used for a DDoS attack. So, we are motivated by such examples which are serious vulnerabilities. Next is vendor choice. We chose four vendors, Hikvision and Tawa, because they have the highest market share in the virtual surveillance system. And we chose vendor A, which has the highest market share in Korea. Lastly, regardless of market share, we also selected Shinology's surveillance station package as a target vendor. This is because Shinology is famous for security and has an image of being safe, so we wanted to check whether surveillance-related packages were also the same. Next, let us tell you about our firmware extraction methodology. We tried a variety of methods to extract the firmware, and this picture is a list of what we tried. Since three of these products had UART ports available, we tried to extract the firmware through UART. And Shinology allows the root shell access via SSH, so no other method was needed. Before that, let us tell you why we didn't perform the extraction via remote access. Hikvision and Tawa supported remote access, but only limited shell access was possible. We tried many ways to bypass it, but they failed, so we had no choice but to use UART. We identified the UART port on the PC board and connected a cable to make it interactable with the UART shell. However, all three devices were not regular UART, but modified UART. So we couldn't use the UART shell, as shown in the picture on the right. We started looking for a way to bypass it. First, in the case of Hikvision, we couldn't bypass UART mitigation on the first NVR we purchased. So we used the downgrade method of repurchasing an older version of the Hikvision device. An older version device had lower UART versions, and there were differences from mitigation applied to the latest UART. We were able to access the UART shell using Hikvision's UART mitigation bypass technique we could find on the Internet. And last, we updated the older version of the product to the latest firmware. The bypass technique already known in the older version... On the latest version, there was no reaction even though we tried our best on giving command input. But as shown in the picture on the right, which is the older version, using setenv and semicolons caused the command injection. So we were able to insert the UART command. Since we could use the UART command disk, we were able to obtain a kernel shell for the device by adding the shell to the RDNID argument in bootargs. Next, the case of Dahua. In Dahua, several UART command disks were available, but the most important command disk, such as printenv, did not exist. So we used setenv to print the changed argument once again to check the value of the environment variable with the keys we know. However, bigger problem awaited us. We modified bootargs and booted the device, but we couldn't see the kernel output. In order to use the kernel shell, of course, there must be kernel output. So we looked for a way to check the kernel output. First, we knew that the environment section exists using the mtdpart command. And to print the contents of this environment section, we used the ntdump command to print the contents of the environment variable. Now that we were able to check the key values of the environment variable, we changed the value of each environment variable one by one to see if we could grab the kernel output. We found out that there was an environment variable called dhkeyboard that specifies the kernel output mode, so we could change it to 0 to get kernel output. Next is vendor A. In the case of vendor A, unlike the previous two cases, it was not possible to even use the u-boot shell. As you can see, as soon as we booted the device, type password has appeared and we couldn't use any u-boot commands. Vendor A was calling the secure UART and we started doing a lot of research to bypass this. We learned about the glitching attack through a lot of research and led the u-boot code to perform this attack. By reading the code, the booting algorithm in the u-boot system says that if the initialization process was successful, all those launched the kernel, and if it fails, it restarts the bootloader shell. We assumed that vendor A wouldn't have exception handling for this method, and we found a way to make the initialization process fail. Let us tell you how to perform this attack. First, we will explain the process of loading kernel during the normal boot sequence. First, load the kernel into RAM from flash memory. Second, the CPU rests the kernel loaded into RAM and decompresses it. If the decompression is successful, the CPU starts the kernel and terminates the execution of u-boot. Now, let us tell you the boot sequence's difference between performing the attack and vice versa. As with the normal process, load the kernel into RAM from flash memory. At this time, we gave it an electric shock, which caused the kernel to be broken and to be loaded into RAM. As the CPU tries to decompress the broken kernel in RAM, it naturally fails. When this happens, the CPU restarts the bootloader shell as I mentioned earlier. Through previous research, we learned that the attack is carried out by connecting the chip select and data out on the pad of flash memory. Therefore, we checked the datasheet of the flash memory available at vendor A and found out which chip should be connected. We are now all set, but how do we connect these two pads? We created a specialized tool for performing this particular attack by attaching the heads of jumper cables together. Looks very easy, right? Here is a demo of this attack. If we give it an electric shock, and boom, we can use the bootloader shell. Once we had the kernel shells for all devices, we needed to extract the file system. We ejected out the file system to our NAS using NFS and USB. One thing we didn't know was that the USB had to be formatted as XFS for the device to recognize it. As you can see, we were able to successfully transfer all devices' file systems to our NAS. However, we encountered a big variable while configuring the AWS analysis environment, because most file systems were read-only, so no files could be modified or written. Now, even though we had a root shell, the shell becomes unusable once the device boots up, so we had to bypass it. We found out that only the root file and device directory were modifiable, so we decided to use bind-mount. We discovered that when we bind-mount an arbitrary file in a writeable directory, the file becomes editable. We immediately bind-mounted ETC password to a writeable location. Now, we can modify ETC password. However, the main binary ran an integrity check and rebooted the device when changes to file contents were detected. So we found a way to get around this. First, we cloned ETC password to a writeable directory. If you look at the picture on the right, you can see that the root shell is set to DSH, a restricted shell. Second, bind-mount is performed in the RCS script after the initialization process is completed and immediately before starting the main binary. Next, we ran the main binary, and when the web service becomes available, we changed the contents of the bind-mounted file. Finally, we have a restricted root shell accessed via SSH. Now, we can replicate the file system using NFS. Additionally, this bind-mounting replaces the original file contents when the device is rebooted, so we created the previous process as a shell script and used it. Next, we will discuss the vulnerabilities we discovered and the MBR hacking scenarios we created by linking these vulnerabilities. Here, we will explain one scenario for each vendor we targeted. First, let's look at the scenario for vendor A. The code on the left is the query string parsing logic used in the web page. It calculates the start and end of the parameters based on the equal and ampersand characters. This parameter named length is used as the parameter for SDRN copy. Therefore, since the length is a controllable parameter by the attacker, it can cause a buffer overflow. So, let's insert a large number of characters into the query string parameter. As you can see, the return address is overwritten because there is no canary successfully manipulating the PC register. However, we encountered a few problems. First, Annex was enabled, so we needed to perform the ROP. Next, since the payload must be successfully delivered to the server, we could only insert printable characters. All gadgets in the binary start with 1, so we could not use gadgets within binary. For this reason, we also couldn't leak the libc address. So, how do we write the exploit code? We found several solutions. First, we discovered that the R0 register holds a stack address at a certain size. We confirmed that this stack address contains the string we inserted into the query string. Next, since the main binary has a 32-bit address space, it has low entropy. Lastly, the Lydie binary spawns a new child process whenever the child process dies. What do you think? Doesn't it seem like everything is set for fault-proof? Look here. As I mentioned, the R0 register holds a stack address containing the string we can manipulate. At that time, we can control the PC register. Now, we needed to reboot the binary until the PC register holds the libc system address. Here is the method. We send a request that makes the R0 register hold the libc command payload. Then, we send an arbitrary libc system address in the PC register. Now, let's start the boot machine. Before long, we obtained a share. Fortunately, we got the share within 600 tries, not the expected 2 to the power of 16 tries. Great, we got a root share. But what can we do with it? All critical files like video, account, user password were encrypted, so we found additional vulnerabilities in the device so we can take over the admin web page. Unfortunately, since this vulnerability has not been patched yet, we cannot disclose it in here. All right, we can now access the device management page with admin privileges. Now, we can do anything. This is the real-time video manipulating scenario made by chaining the explained vulnerabilities. The attacker infiltrates the MVR through RCE. Then, using a vulnerability we cannot disclose here, the attacker gains access to the admin web page. Finally, the attacker manipulates the real-time video. Here is the demo video of this scenario. When we send a payload, the MVR screen is tampered. Next, let's discuss the machine authorization scenario for Synology. Synology performs a load of MVR through the surveillance station package. Let's look at the authorization code of this package's API handler. First, it verifies if the user sending the request is logged in through the isAuthorized function. Then, it checks if the user has permission to use the surveillance station package. Doesn't it seem like something is missing? It doesn't check if the user has necessary permissions to use specific features, whether the user is an admin or a guest. So, we found that even with guest permissions, one could abuse all features of the Synology surveillance station. We discovered that surveillance station features include reboot, shutdown, and package installation. Additionally, we found something unusual. Some requests usable in surveillance station are forwarded to the NAS's core package. Regardless of how the requesters identify, these requests are forwarded to the core package as admin, allowing a guest using surveillance station to request to the Synology NAS with admin privileges. We received CVE with CVESS score 9.9 from Synology. Next, let's look at the scenario of hijacking real-time video. In a normal flow, guests do not have access to the camera, so they cannot view video on the front end. However, due to the vulnerability, even guests can obtain video information. Synology returns the RTSP server address and access credentials in the response, granting attackers unlimited access to the videos. Let's look at the scenario. Here, we included a request to terminate the layout. The attacker sends a request to terminate the layout, disconnecting all live video layouts connected to Synology on all computers. Then, the attacker sends GetLiveViewPass request to steal the video information. And requests the video from the RTSP server using the stolen information. Now, the attacker has hijacked the real-time video. Here is the demo. When we send the payload, the layout is terminated and we can watch the live video. Thank you. Next, we will introduce the vulnerabilities and scenarios of DAWA. The first vulnerability is called reachable assertion, and we will explain how we found it. While analyzing the login function, we discovered that there are many login options. As shown in the table below, there are six types of assert time and password type pairs. By default, the assert type and password type are set to default. The data sent in the request includes the username, hashed password, session, assert type, and password type. If the request is successful, a response containing true is received. We are curious about what will happen when an attempt to log in with different authentication types will lead us to unable to analyze the login options. During the analysis, we found a developer's mistake in the processing of the login request data, and were able to shut down the device with a reachable assertion as a result. Now, let me explain the vulnerability. First, before processing the login logic, the function's getPasswordType and its password value are called. The getPasswordType function extracts assert type and password type by parsing, and compares specific strings such as default and default, respectively. If the strings match, the function returns a type for their own. If the type is both default, it returns 4, and if it is OTP and SSC, it returns 7. Next function is called, isPasswordValid, and parses the login parameters based on the type value returned by the previous function, getPasswordType, and creates a string object. The series of process enters when assert type and password type are set to default. You can see that there is an exception handling logic that checks to see if those parameters are null before generating a string object for both parameters. Most of the branches have this null exception handling logic, but not all of them. The following code handles the case when the authentication type is OTP and WSSC. As seen in the code below, string objects for authority input and password type variables are created, but there is no exception handling logic for these objects. So, we remove the authority input parameter, set the authentication type to OTPWSSC, and send a request. As a result, the authority input is set to null, which causes a retrieval assertion to be drawn when creating a string object for that parameter, causing the main binary to exit. When the main binary terminates, the watchdog causes the device to reboot. This is a pretty simple vulnerability. The following vulnerabilities are very important because they require the device to reboot. The second vulnerability is Elf Injection. First, that will set permissions by group, and once creating an account, it can only perform tasks included in the permissions of the assigned group. This group information is stored in a file named groupsec and is encrypted using ASCBC. We tried analyzing the source code to find the key in Ivy, but it was quite complicated and eventually failed to find it. However, since the configuration information must be decrypted and loaded into memory during the main binary boot process, so we performed a dynamic analysis of the boot process, and unfortunately we were able to find the decrypted data. The structure of the decrypted groupsec file is as follows. The columns are ID, name, authority, and memo. Each column is separated by a column, and each line is separated by a line feed. When adding or modifying group information, the getline function is called as part of the process of saving the changed data. This function generates a line with the ID, name, authority, and memo, extracted from the login request separated by columns. We found out that there was no validation checking procedure of the input value until generating a line with the getline function. So, we added a line feed to the memo to tamper the structure and restarted the device to see what would happen during the parsing process of the groupsec file. As a result, the device entered the initialization routine and recreated the groupsec file. When entering the initialization routine, the user can change the add-in password on the web and perform any actions. We are curious if the initialization routine would still be entered if the file was deleted. After deleting the file and rebooting the device, we found that it still enters the initialization routine. Let me introduce the first scenario of DAWA using two vulnerabilities mentioned above. By using retrieval assertion and alpha injection, an attacker can take over the device and obtain add-in privileges. First, the attacker obtains an account with a user-managed privileges through credential stuffing. Next, the structure of the groupsec file is tampered through alpha injection. Then, the attacker reboots the device using retrieval assertion. When rebooted, the device enters the initialization routine, allowing the attacker to change the add-in password and perform malicious activities. Next is Stack Overflow. First, this vulnerability occurs not in the main binary but in a background service called AOL. This service is used to attempt online recovery when the device is abnormal, and it's open on port 8088. Since this port is not forwarded, it can only be accessed from the same network. It consists of 16 bytes of fixed size of headers and data. And for header, the constitutional data byte index 0 indicates the function index, and the byte chat indexes 4 to 7 indicate the data size. The data is then used as an argument for the input handler remitted by the data size defined in the header. However, the pinpoint is that the data size can be publicated. Now, let me explain the request processing procedure. The following function is called per-message. First, this function uses the structure with the VFT array, which consists of functions and variables related to each feature. As shown in the table on the left, each structure includes the permission level, index verification function, parameter parsing function, handler function, parameter allocation free function, and next table pointer. There are about 20 such tables. Here is how it works internally. The function iterates through a loop, calling the index verification function of each structure with the first byte of the header as an argument. The index verification function, as seen in the code on the bottom right, checks if the value obtained by subtracting a specific constant number from the argument is not zero. If the result is zero, it returns zero, or otherwise, it returns minus one. Referring back to the code on the left, if the return value is greater than zero, or meaning a matching index is found, the count table pointer is told in the eight variable, and zero is returned. If the matching index is found, minus one is returned, and the request is not processed. Next, the dpStackParse function is called. This function retrieves the table corresponding to the index and calls the parseFarm function. As shown in the parseFarm function on the right, it appropriately processes the data according to the requested function, and then returns the result. Finally, once all preprocessing steps are complete, the dpHandleQuery function is called to register the input handler and then execute it. There are many different functions that could be called, including logWin, query, and update, but they all require the logWin. So, we started analyzing the logWin function first. The function is executed if the first byte is A0. The data consists of username, password, and a random value with a double ampersand used as a delimiter. The vulnerability occurs when parsing this data, which we'll explain in a moment. As you can see in the code on the right, the strings for the username and password are set to 128 and 160 bytes respectively, and the memory is initialized with a memset. Next, a stringString function is called to find the positions of the double ampersands and null. The data before the first double ampersand is copied to username, and the data before the next double ampersand is copied to password. The problem is that there is no length validation checking during the copying process, allowing us to input data of any size. As a result, a buffer overflow occurs. You can cover the return address by putting 156 bytes of random data, the desired value, and the password location, as shown below. Since there was no stack canary, we couldn't manipulate the PC register. However, we encountered an issue where we couldn't include a null in the payload, making our pain possible. We didn't want to conclude with just a simple buffer overflow. So, we began analyzing the source code. Fortunately, we found some useful functions. There were functions for rebooting, starting SSH, removing inter-settings, performing a soft recovery, and killing all MBR-related binaries. Among these, the most interesting function was the soft recovery. This function deletes the config directory, resetting all configuration information. As seen in the previous vulnerability, if the groupsec file is deleted or tampered, the initialization routine is entered upon reboot, allowing the admin password to be changed. Therefore, we manipulated the PC register to call the soft recovery function. However, soft recovery deleted even the network files, making external access impossible. Unfortunately, we faced another challenge. After several days of analysis and contemplation, it soon came to my head that during the boot, there is a process where configuration files in the config directory are decrypted and loaded into memory. So, we began analyzing the boot loads. As a result, we found that the network configuration file is loaded first, and then the account file is loaded around 5 seconds later. I was curious to see what would happen if the main binary center soft recovery failed within 5 seconds of loading the network configuration file. The most fortunate point is that AOR is loaded before the main binary boots. First, we kill the main binary using the recover assertion, causing the device to reboot. Then, we wait until the network configuration file is loaded. In our case, it took approximately 20 seconds for the device. Next, we send the soft recovery failure to AOR, which deletes all configuration files. Then, the main binary can't access the account configuration file and enters the initialization routine. As a result, we are able to change admin account. Let me explain the admin takeover vulnerability using recover assertion and stack buffer overflow. First, we will reboot the device via recover assertion. After rebooting, we wait for the network configuration file to be loaded. And then, send the soft recovery failure to AOR to remove all configuration files. In the process of loading account setting files such as groupsec, it enters an initialization routine because the files do not exist. The attacker changes the admin password and gains access to the admin page. This is a demo. The last vulnerability is from Hikvision. Hikvision was much more solid compared to other devices, making it more challenging. However, we found an interesting vector, a local subs component. That is a plugin that must be installed for users to view video from the web. This plugin runs with admin privileges on Windows and is accessible on port 33686, meaning anyone on the same network can access it. It was a very interesting plugin, so we started analyzing it and found the vulnerability. Due to an entity associated with a bounty for this vendor, we can't disclose detailed root codes. In short, it is a vulnerability that allows RCE by sending a crafted message. Instead, we will show you a demo. Through RCE, we can completely take control of Windows. With admin privileges, we can perform any actions. The next vulnerability is OS command injection, which allows a user with admin privileges to execute arbitrary commands. We create a scenario to take control of the internal network using these two vulnerabilities. First, we obtain admin privileges through credential stuffing. Next, we open a reversal through command injection to enter the MVR. Then we perform network scanning to find Windows computers using the application named local subs component. Finally, by exploiting the plugin RCE, we could take control of Windows and perform malicious activities. Here is the demo. By just pressing the button, we can automatically take control of Windows computer in the... One of the things we learned during the project is the Hikvision and our Huzy OEM supplier. Both companies also sell under their own brands, but they are relabeled and sell to various retailers in the U.S., such as Lorex and Luma. This means that devices are being used all around us without realizing that they are made in China. First, OEM stands for Original Equipment Manufacturer. It refers to the manufacturing method in which a company outsources the production of its products to another company and then sells them under its own brand. If a product is made by Company A and is sold under the brand name of Company B, Company A becomes the OEM supplier and Company B becomes the OEM vendor. The images below show DAWA's MBR and OEM's MBR. They look very similar, don't they? This picture illustrates the OEM sales process. Products manufactured by OEM suppliers like Hikvision and DAWA are relabeled by OEM vendors and sold to users. If a vulnerability occurs in a product produced by an OEM supplier, it can affect the products sold by the OEM vendor as well. This means that many devices can be impacted by the same vulnerability. So, we decided to check if the vulnerabilities were valid for OEMs using the same firmware. First, we ran bin-deep on the main binaries of DAWA and OEM vendor Bush and found that the logic was similar. Hikvision also confirmed similar through deeping. After confirming that OEM vendors use similar firmware, we decided to fault-trace devices and test them. For Hikvision, we fault-traced Anki and Ampibis. Four out of six vulnerabilities each were valid. For DAWA, we fault-traced Zhiyuan and EGPS. Four and six of the seven vulnerabilities were valid, respectively. We confirmed that the vulnerabilities were validly exploited and reported them to Mitre, KISA, which is the Korean CNA, to get CBIS and KBIS, which increased the number of recognized vulnerabilities by 61%. Finally, we will show you a video of vulnerability testing on OEM vendors. The first video is the OEM vendor testing for DAWA. By sending DAWA's recover assertion payload, we could shut down all devices. The second video is OEM vendor testing for Hikvision. After sending the voice command injection payload, we could connect a reverse shell and input the shutdown command to turn off all devices. Also, we are curious about how many devices were affected by the vulnerabilities we found. So, we searched using Shoda. In the case of Hikvision, most model devices' name or firmware versions were not present in the banner data. So, we needed a different approach to identify as many as possible. We found that for MBR devices, when accessing the login page, a config.json file is requested. This file contains the configuration information related to MBR. For version information, we used the web version and plug-in version coded in the C.js to search for devices with versions equal to or lower than the one we did our study. As a result, we found that approximately 130,000 devices were vulnerable. For Delwa, since the device name was present in the banner, we simply searched for it. As a result, we found approximately 100,000 devices. Finally, we came to the conclusion part. First of all, this is what we would like to comment to offensive researchers in MBR field like us. The vulnerabilities were discovered during our research period include. Even when analyzing one-day cases, we found that these vulnerabilities were statically numerous. So, when you want to analyze your MBR, we recommend that you focus on these vulnerabilities. We conducted an analysis focusing on HTTP communication process of domain binary in order to achieve good results as much as possible over the project of four months. However, MBRs have numerous attack surfaces, including private protocols with their cloud service, SDK communication with VMS, private protocols used to communicate with MBRs or IP cameras, and communication with other sensors. Therefore, we recommend that you do not focus solely on analyzing the HTTP process, but analyze various attack surfaces. The following is what we would like to recommend to users. What we felt while conducting a one-day case study is that as long as MBR is not exposed to the external network, it is safe from these attacks. Major MBR vendors provide solutions that allow external access using things like DDNS without exposing the device to an external network. You can take advantage of these solutions to keep your devices safe from these attacks. Thank you to people who helped us with the research. Especially, thank you to Dr. Junsang Yoo. Thank you for listening to our presentation. And if you have any questions, please contact us on Twitter below. More details of our research can be found via the QR code on the right. Thank you.