Talk today from Liu Huimin about bug finding and exploit techniques for file transfer apps on Android phones. So if you have your file transfer apps open at DEF CON, really? But if so, this might be a good time to turn it off. This is Liu's first time speaking at DEF CON, although he has given talks at CanSecWest, Black Hat, basically all over the world he's given this. So give him a welcome and we're going to give him a classic DEF CON welcome with the speaker shots. Cheers. Good morning, everyone. My name is Liu Huimin, and Zhang Xiangqian is my colleague, but he won't come here because of some visa issues, so I will do this talk alone. Yeah. Now I will show you a comprehensive research about exploits of nearby file transfer apps. The title is Your Secret File, Am I? And bug finding and exploit techniques on all transfer apps or all top Android phones. First, let's introduce ourselves briefly. We are from Advanced Technology Research Team of Tencent Secure's Xianwu Lab. Tencent is the largest social media and entertainment company in China. And we focus on mobile security and IOT security, and we found many Android kernel and system security vulnerabilities. And we found many Android kernel and system security vulnerabilities. And we did slightLAB只 двеians , for various meglioations and accomplished many fancy attacks. And we present many slides like this. proofreading This is our presentation. First, we will give an introduction about the nearby sharing technology, and talk about our motivation to do this talk. Secondly, we will present the attack surfaces and some previous work. Next, we will show you a relative map of our real vulnerabilities and the exploit and the demos. Uh next we will show you the real uh then we will talk about the mitigation method. Uh yeah. Finally it's it will be our concluding. Now let's begin our part one. Introduction. There are many nearby transform uh transmission technologies such as Bluetooth, Android Beam, Wi-Fi direct. But we focused our research on nearby sharing apps on Android including uh smartphone window built in apps and third party developers apps. Many users want nearby firing uh file sharing apps. Why? We believe that uh uh Bluetooth and Android Beam based on NFC have two weakness. Uh the first one is the user friendly. First not user friendly enough. And sec secondly not fast enough. When you want to share a picture to your friend it uh usually takes seconds or minutes to transfer a big picture. But uh this technology based on Wi-Fi technology will be transfers uh fastly. When we want to send or receive a Blu-ray movie. It will be not capable at all. So now we will talk about by transfer apps that are based on WiFi related technology are people's new choice. Based on our research we found that nearly all top smart phone vendors have their uh sharing apps. So uh based on the IDC's data we can find that the shipment last year is a nearly a billion phones. A billion within a single year. That's a big number. If they are vulnerable, a huge number of people will be affected. So we began our research. This is what the Android sharing apps look like. It's it is a little like the AirDrop on the uh iOS and iPhone that. There are several ways to connect and send files on Android. In this example, when the both sides are all active status, the sender just select the file and the receiver will be shown on the screen and then the receiver can tap the uh tap the profile picture of the receiver and uh the receiver will click the accept just like the AirDrop. Then the file will be transferred. So this is what the Android sharing apps look like. Some apps use another approach. The receiver clicks the receive button and then the sender can see the receiver and they establish the link and accomplish the file transferring. There are little difference here but there are many difference in the security design. There are some other ways such as scanning the QR code to transfer apps uh to transfer files or uh shake the phones at the same time. On the other hand, many nearby file sharing apps will show the thumbnail. This will introduce a new attack vector. We will detail it later. Yeah. The sharing process or nearby sharing apps are shown here. In general, there are four steps. First, discover by BLU advertising name, ID device uh ID device type and so on. Secondly, we can pair. So most apps pair and exchange keys automatically. Which means that the card has a common key. So it's very convenient. But it is vulnerable. Thirdly, connect via wi-fi or wi-fi P2P. Finally we can transfer files such as pictures, APKs, and so on. Since we know that general sharing process, let's analyze the uh attack surfaces. First at the uh the uh the adversary nearby. The uh the attackers can be sniffed and sender or Bluetooth and wifi packets. Then, what attackers can eventually get when attack succeeded. First, the attacker can get the transfer files and more, such as hijack and the traffic, hijack the traffic, get more information and even remote code execution. Here, the attack surface is as follows. Link is establishing, secure transmission, device and ID spoofing, man-in-the-middle and others. First, when link is establishing automatically, attackers may join to a network without user's permission. On the other hand, attacker may obtain the established network password because of unsecure connection. When files are transferring, there may be no encryption at all, so we can get the file directly. And sometimes, the key exchange are not safe, so attackers can recover all the real file from the encrypted traffic. Next, device and ID spoofing. Many apps fail to authenticate the real device or users. For example, when Alice wants to send a bob a file, then the attacker can collect all the bobs at the, at the advertised information and advertise themselves to create a fake bob. In this case, many apps fail to distinguish between the fake and the real bob. We call it device and ID spoofing. Based on the device spoofing, the attackers may accomplish man-in-the-middle attack, so the normal user will feel nothing. We'll show the demo later, but the technical details will be explained later too. What's more, we've found some other interesting attack surfaces. For example, some sharing apps will start a web server, which will open more doors for attackers. And there are other information decoder we can't even think about it. And Android components release attack surfaces. Uh, we are not the first researchers to, uh, notify, uh, notice the near, nearby communication apps. We're searching about the, uh, zero-conf on OS 10 and iOS. Research by Xiao Long, et cetera, analyzed AirDrop and found some vulnerabilities. And on NDS 19, some, some researchers reversed, analyzed the Google Nearby Connection API. However, there are nothing about file sharing apps on Android. My colleague, we, and I will present this on this talk. To the best of our knowledge, our research is the first comprehensive research about Android Nearby Sharing Apps. We analyzed many related apps, including pre-installed and third-party apps. And we found a lot of vulnerabilities in these apps. And then we arranged them in several common attack methods. Um, here, let's show you some of the real vulnerabilities. Notice that in this talk, we will focus on the specific, uh, we won't focus on specific apps or vendors. Uh, so I will cover all the vendors and, uh, apps name here, uh, for just for, uh, security. Yeah. Besides, there are huge number of users will be affected. Uh, so, uh, I will cover all the, all the critical code too. Yeah. Some of the vulnerabilities are not fixed here, so. We will present four vulnerabilities categories. Sniffer attack related vulnerabilities. Two, the main, the middle attack related vulnerabilities. Then, we will talk about logic vulnerabilities. Finally, we will present all the, uh, other vulnerabilities here. First, let's talk about sniff attack. This is a building app or a smart phone and we will take it as our example. These three pictures show the normal file sharing process. The receiver don't need to input any password. Or something, uh, else. Yeah. The whole process is totally automatic. However, more convenience can often means less security. This app use Bluetooth low energy, uh, and, uh, to advertise and discover other peers and tran- transfer files by WiFi P2P. Can it accomplish a secure key exchange here? To capture Bluetooth data, we can use a Bluetooth sniffer such as Ubertooth, RF, 501, and so on. This is a BLE packet we captured. It is a scan response packet which is send when someone, some other device are scanning. It contains your ID, device name, and some other information, such as some flags and spotted ciphers, spotted cipher values. The packet is, uh, advertising packet which is often easy to understand. And this is a BLE data packet. The BLE sends data in 37, 38, 39 channels but Ubertooth can only sniff one channel at a time. So it can't we need to sniff several times to gather the data packet. The picture shows the encrypted data transfer when establishing connection between different volume of apps. So we extracted the data here and it looks like this. What does it mean? The answer lies in the app itself. So we reverse engineering app. This is a core crypto algorithm. We can see that it is um obfuscated badly so uh but we managed to recover a function which mainly rely on an AES crypto and some other transformation or data. Uh to make it more clear we can show you an older version which is different but without any obfuscation. But the whole process is just the same. In this older version there are nothing but an AES encryption which was different from the new version. But the overall logic was different. So we can see that the encryption is not the same as the previous version which is still the same. So the P2P info is a P2P info you can see in the slide is uh encrypted information. And the P2P CFGX here is a plain tech decryption by calling decrypt function. And the key was generated by the function generate secure key and generate loop key. This picture shows a decrypt function which we can see the AES code. Uh the decryption here. Yeah. To decrypt the data we need to get the ES encryption keys which rely on the source string array and the M secure random. A secure string array can be gotten from the BLE packet. What about the M secure random? It's its name contains random. However we think that uh it must must not be the random number because the sender and the receiver must be uh have the same uh number of this. So we found that it was stored in some XML file and it is fixed. That's interesting here. So now the whole encryption can be break and we can recover data directly. This is a decrypt process for older version of the app. The latest version was far more complicated. But we managed to uh reverse it. So we can see the reverse internalize. But uh it is similar in the design. We break it too and we will show you the output. Hmm. The upper image shows that we covered P2P info old version. The second image here it shows that we covered P2P info new latest version. So we can see the SSID and password are golden bars. So everything uh they transfer. So we can see the SSID and password are golden bars. So everything they transfer. will be get direct pass. Based on the recovered password we can join the network and get the transfer files through ARP spoofing. And let's show you two demos. Here, the right phone take picture. Then he will send the picture to the left phone. And then he will send the picture to the left phone. And the computer act as an attacker. So we can see the info that was collected there. Then the left phone got a notification and then when he click the accept here, we can see that the computer is now receiving the message. And then the left phone will get it too. And this is a photo we just take picture of that. Yeah. Here is demo two. It is the process is a little different but there are some more interesting here. So something very interesting I think. The left phone want to share picture to the right phone. And we can see that the picture was gotten by us. You can see the pop out on the computer. We checked it's the latest version when we recorded the video. So we can see that the picture was also gone. When transfer apps actually, this is the picture. Yeah. And this shows the what you use in, all apps you installed on your phone. When sharing apps, a one, two, sharing photo here, he will send all you installed, all the apps you installed on your phone to the other phone. And we it's a terrible info leak here, I think. Next, let's move on to the second category, main and middle attacks related to vulnerability. In nearby sharing apps, when the senders want to select a receiver, he can see profile picture, device name, URL ID and so on. Our question is, how can you authenticate that it is a real one? We found that it is very tricky. In this slide, we can see that we can emulate a receiver by use a BLE scan sender app to send advertising and scan response packets. The left phone shows a profile picture of someone, but it is actually a, um, picture of the receiver. So, we can see that the receiver is a BLE sender app, yeah. Then, the receiver will be shown on the sender screen. And in this picture, we modify a real device to spoof another device. There are two active receivers here, but the sender can only see one device. So, when he wants to send a file, he will never know which device it will be sent to. Now, we can spoof another real device. Then, the attacker can accomplish perfect main and middle attack when emulated a fake receiver and a fake sender. As we can see here, if A sends B a file, there will be 50% chance that the file will be sent to the attacker. And the chances can be improved by many ways. Now, a perfect main and middle attack can be designed like this. Uh, A can find that, uh, that, uh, the attacker because the attacker will not send a scan response to A by our design. B can find the attacker because B is not in discovery mode. Then, and then the attacker can distinguish between A and fake A, B and fake B. B, because he can choose to block or receive any message. So, the normal user A and B can feel anything. Uh, this is a demo. We didn't implement the whole process or the main message. We did it in the middle here due to time limitation. In this demo, we just verify that the sender can distinguish between a real and a fake receiver. So, our main and middle attack will work properly. Here we can see the normal user send a file. And sometimes the users, uh, the normal user get the file and sometimes the attackers get the file. So, we can see that the attacker will get the file. So, here, the attacker will get the file here. Oh, yeah. Now, let's take a look at the main and middle attack. So, the main and middle attack, the main and middle attack go through the third category. Logic vulnerabilities. First, let's think about a question. How to design a secure process to establish connection between sender A and the receiver B. We think it should be like this. User A requests to send and B accepts. And then the link will be established. Then A sends the file and B will receive it. So, this is how the receive it successfully. But actually, most nearby sharing apps will establish the WiFi connection as soon as the sender A just sends the request. But why the app developers choose an unsecure way? We think that they might have their own consideration here. More clicks often means less convenience. So the developers don't want their users to double confirm. And the receiver, uh, often want to see a thumbnail about the file to decide whether accept the file or not. So convenience wins and sometimes security lose. Firstly, the non-confirmed connection brings more attack surface here and the attackers can now establish the WiFi or WiFi P2P connection without any interaction. So, uh, this is a good example of how the network works. It will open those four attacks to exploit other vulnerabilities and even achieve zero click attack here. Just exploit the, uh, f-file image protocol here. Secondly, we can hijack the victim's network. In these two cases shown on this slide, we can see that when transfer, uh, transfer files that, uh, one device creates a WiFi hotspot and the other device, uh, connects to it directly. However, it is not this easy to hijack network successfully. First, if attackers want to hijack the network, they must be the hotspot server. Can we choose to be a server? We found it, that we can. For some apps, the senders are definitely the server creator. It is ok, because here, the attackers are always senders. For non- Mobile iOS officers, we are many other apps, we found that when an app running on Android 7 and another app running on Android 8 want to establish a connection, Android 7 is always the server because some compatibility issues here. Secondly, we will make the other user to connect to my WIFI without, without interaction. Can we do that? We found, yes. Because it was designed like this. Yeah. Let's do a demo here. The WIFI team just check his internet access and he just opened the file transfer apps and just leave it here or make it in background and just turn, turn the off, turn the screen off here. The attacker request to send him file. And then when victims open his browser. And then when victims open his browser. And then he'll be hijacked. Yeah. Finally, it's our fourth category. Other vulnerabilities. We will share three examples here. One, accept automatically via WIFI P2P. Two, directory transversal. And three, remote code, remote file management vulnerabilities. So, we will share three examples here. In this case, when sharing files, this app will establish a WIFI P2P connection. We can see that when other device want to join them, it will need to pro, pro, provide the correct password. However, when we use WIFI P2P protocol to directly connect it, we found that anyone can join them without any confirmation here. And the normal users, we won't feel anything. So, we'll get the file directly. So, this is our third category. The second logic vulnerability example. And in this case, it is a directory transversal vulnerability. The file transfer was accomplished by web server. So, the senders may create a web server and send the receiver a URL to get. Then, um, the receiver can modify it to get any files here. Let's show the demo here. The right phone is the sender. Then, he got a secret image. But he want to send another normal image to the left phone. But here, the left phone will get anything he wants. And in this case, we will share a file management related vulnerability. If the file is not in the same area, we may change the name of the phone. This is a message that we received. For example, if an app want to open the FTP server, computer within the same local area network can manage the file in smartphone. We found that many apps didn't have any authentication here and security design. Any idea have read and write permissions here. So, if attackers are in the same length, they can get and write all your files here. This is a very easy is a summary of vulnerabilities in nearby sharing apps. First, non-confirmed b- before Wi-Fi connection established. Two, not well protected access to Wi-Fi or Wi-Fi P2P. Three, unsecured transport. And finally, no anti-spoofing at all. Those vulnerabilities patterns affect nearly all the nearby sharing apps. We finished our four common vulnerabilities. And now we present you our security story about nearby sharing apps. With, um, the red X means no security measures at all. The yellow O means have security measures but can be bypassed here. There are no one green here. But I will show no one here. Um, there are little security measures such as access control when Wi-Fi, uh, was established here. Then we did a security story for top ten startup party nearby sharing apps. And the results are shown here. Um, most of them are vulnerable too. Only 20% of them can prevent sniffle attack. And only 10% of them can prevent spoofing. And notice that this is the test results on Android 8. If we tested them on Android 7 or lower, nearly all of them will be vulnerable. Because Android allow the app to create, uh, uh, hotspot with their self-defined password on Android 7. So when Android 7 and Android 8 or connection, make a connection. The Android 7 will always uh be the server and will be vulnerable. Yeah. Finally, let's talk about the mitigation. This is our four devices, uh advices about mitigations. Sorry. First, we need more secure WiFi and WiFi P2P key exchange. And two, we need, we need transport encryption. And three, it must be designed to pro-prevent spoofing. And finally, there are other small tips. First, the app must have secure WiFi and WiFi P2P key exchange. So we recommend that the app transfer the key over a secure channel such as NFC, certificate based key exchange. So we recommend that the app exchange mechanism and the internet. On the other hand, the PIN code is a good choice too. Now, nearly all apps transfer files without any transport layer encryption. When we recommended that the app use TLS HTTPS instead of TCP HTTP and transferring keys over the internet securely or pre-exchange keys over the internet, we recommend that the app should be used for contacts. It is not very easy to prevent spoofing. We prevent a method here, we present here, but uh we use a certificate based authentication. When the app launch for the first time, it will get a unique ID distributed by a server and corresponding certificate signed with pre-defined trust anchor. So, attacker can use this method to prevent spoofing. So, the app can't sign the unique ID correctly. We can make sure that the device has, can distinguish between the real user and the attackers. There are some other tips. First, we must prevent attacker from joining the network and state file sharing turned off by default and turned off the, off them and after a period of idle time. And confirm before connection established. And finally, do not establish connection automatically with users who are not familiar. This is our recommended design. When users are logged in, we recommend pre-exchange public keys and authenticate automatically for contacts. And exchange keys through the server when there are internet access for other peers. When your users are not logged in or have no internet access at all, we recommend PIN code NFC to exchange keys. PPC and DVHuman here is easy to deploy and um have some security measures. So if you have any questions, please here but it is not very recommended because it can prevent main and middle attack. Now this is our concluding. We analyzed the attack vectors on nearby sharing apps and did the first comprehensive research about them. And we found many vulnerabilities here and we categorized in several comment attack methods and finally, we present some effective mitigation methods here. Thank you. Now the mitigations will be deployed on many apps here but we can't tell which app, uh, is secure. Because we will not see any because the window didn't want to say that, sorry about that.