Hello everyone, I will continue to talk about some of the situations that will occur in other applications. Another situation is that there will be a loophole in the instant communication software. Many instant communication software support one user to send a file to another user during the operation. And this file is not just a picture or audio file. It can be another kind of document or binary file. And this kind of file will retain the original file name after it is sent. If this file name is not fully verified during the download process, it may save this file to any path after the file is downloaded. This will cause a loophole and cause some subsequent effects. How to find such files in the instant communication software? First, we need to send a file with a malicious file name. Then we need to ask the target user to click and download this file. One of the most difficult processes is how to send such a file. Because in the process of implementing the instant communication software, it directly takes the relevant file from the file processor or some other components, and then obtains the file name. It does not support directly specifying the file name of the target. So we need to send a file with a malicious file name through some intermediaries or hooks or re-packaging. It is possible to send such a file through intermediaries. Because we found that in the process of analyzing a certain instant communication software, it used some requests to pass the file name through Base64 and some code through HTTPS. However, we did not find such a case in the actual application process. So it's just that intermediaries have a possibility. There may be such a situation in other applications. Through the way of hooking, we have a relatively rich harvest. In the whole series of Tencent QQ, whether it is QQ Team or QQ International or Weiliao, it can all be done through a way of hooking. When we send a file, there is a file manager entity in the middle. In such a file entity, we hook this thing down and send a file name to it. Replace it with a file name that we need to specify with a dot-dot-dot. Then send it to the end. The end will display such a file. After it is downloaded, it will be stored in one of the paths we specified. However, there will be some limitations in the process of using this loophole. This limitation is due to some problems with the Java API itself. When it downloads, it downloads to a temporary folder on the SD card. A temporary path below. After downloading, use the RenameTo API to make a copy. However, this RenameTo API is a very strange API. It can be said to be an incomplete API. When it copies from one file system to another file system, it will cause a return false. So the copy is unsuccessful. If the target file exists or the target folder does not exist, it may also return false. When Tencent QQ is in this code, it does not perform the operation of tolerance. After it fails to copy, it will throw an abnormality directly. Then say this abnormality is RenameFileFail, RenameFileError such a situation. If it has the means of tolerance to ensure that this file can be copied normally, this is actually an opportunity. But we can't say that this loophole can't be used. Although it can only be traversed under the SD card, for example, in M.2.0 2017, MWR has already used such a loophole in their use of Samsung phones. It is to rewrite an INI configuration file on the SD card, and then change the HTTP of the server in this file to point to their own, and then do a middleman attack, which achieves the effect of being able to install a malicious application. So although this looks very fierce, but it is also possible to produce some beneficial effects. Then, what do we need to pay attention to in the process of hooking to modify this file name? In fact, the most important thing is to find a suitable location to place such a hook. Such a suitable location may usually be a class of a definition. This class includes some relevant information about the file that needs to be transmitted, such as the file name, file size, etc. However, such a class requires us to manually, for example, how to get this file when it starts, and then store it and read it to what data structure to do some analysis. There is another way, it may store these files in a data structure such as a standard map in Java, and then take it out when it is sent and put it in the corresponding request. We can complete the entire analysis process through a manual trace. Of course, we have also explored a process related to automating this process, that is, it may be possible to do such a method through 5-point analysis. There are some problems with static 5-point analysis. For example, there are some problems with the hidden call, such as the multi-line of this bind. For dynamics, we have a simpler way, which is to hook up the relevant file name. For example, we want to send a file name 1, and then we can hook up all the files to read and write, and then print out the return number. Through this multi-stage binding, we can reproduce the entire process and find some points of such a hook. In addition to this hook, there may also be a method of re-packaging or re-producing. If this application is not mixed very seriously, we can use reverse analysis to specify its relevant source code. In the process of sending files, maybe its file name is already specified in a certain function, in a certain amount of power. For example, CVE-2017-17715. This is a loophole found by Project Zero in Telegram Messenger, which is also a pass-through. When sending files to other users or in the group, a file with a dot-dot-bar can be sent. When the file is downloaded, it will also be affected. This loophole is re-packaged or re-produced by Natalia. It is directly specified in the APK, and then re-packaged and modified. When running, a malicious file name is sent. Of course, in addition to the above scenario, there may also be a cloud disk. When the cloud disk file is downloaded, there will be some problems. For example, when the cloud disk is stored, the existing file name must not be stored in the server. It should be in the form of a hash file. Then, through some searches, the actual file name is unzipped. Then, this file name may not be very standardized or filtered by some dot-dot-bar. Then we also have a chance. There are also some manual backups or restores. This may also happen. Then let's talk about the third link, which is some useful skills. Next, we will talk about some actual loopholes. Before using, we need to figure out a few problems. One of them is what kind of loopholes we can classify as. I have divided it into three categories. The first category is a single cross-path loophole. In this kind of loophole, most of it is caused by the output of the component plus some logical loopholes. For example, this container provider and this file copy. The second category is a cross-path loophole that can directly cover any file. This is widely used. In the last year's Mobile Pong Tournament, there were two cases like this. This is also the most commonly used one. There may be a cross-path loophole in Zip. The third category is some other categories. We can download something. But in the process of downloading, due to some business needs, it will check whether this file exists. If this file exists, it will be renamed. In this case, it will not cause a copy of any file. In this case, it is usually difficult to use, but there is no way. We will have a related introduction later. This is a classic code that is renamed after the file is downloaded. It usually adds some extra characters before the original file is traced. In addition to this loophole classification, we also need to figure out which files are used in the application. In the process, which files are used? The first category is a very general file. Basically, all applications will have it. It is Share Preference. There are many configurations in XML files. These configurations may have some related information. Then there is Circulate Database. This type of file contains some related data, such as contacts, etc. In recent years, Android applications on the market are getting bigger and bigger. They have more and more functions. In order to ensure that the size of the initial package is small enough, some complex functions, such as video playback and image analysis, will be loaded as a plug-in. It will be loaded dynamically. It will even be dynamically updated. Then there is the Rippedin mechanism. There are many Rippedin frameworks developed in China. Because there is no Google Play, it produces such a relatively... Then there may be some binary files such as WatchServer. Such binary files will have some protection process, etc. In addition, there will also be some configuration files, such as the INI file mentioned earlier, or some files on the SD card outside the sandbox. We all have the opportunity to use these files. First, let's look at a case like CVE-2018-8084. This is a path traversal on a domestic browser. It is in the process of decompression, which is to download a zip package, and then manually decompress it. There is no correct verification of the content in this zip package. Then it will lead to... It can travel to any path. At the same time, this app is a browser app. So it supports... It supports some video files. It supports playing some videos online. So it has a lot of SO files that exist in the form of inserted keys. For example, this libvplayer.so is a very good coverage target. We pass... We pass this... libvplayer.so gni-onload function rewrite. Then in this... Just download one of our... a shell. And then execute it. We can... When it plays a video, to get a shell. The interesting thing is that this loophole... After replacing this libvplayer, This app can still run normally. That is, the user has no perception. And in the process of decompression of this app, It also can't see this kind of loophole. So this loophole is still quite good. The second case is... It also uses a plugin. But it is... This... It can't... Directly cover these files. This loophole is in the web browser master. A path... When it downloads the plugin, There is a loophole. That is, a user sends to another user... When sending an app with a malicious file name, A malicious plugin, If it clicks to download, So when it downloads the next time, No... When it re-opens the app next time, There is a possibility that it will cause... An attack on RCE. The specific situation of this loophole is like this. That is... Well... In the process of forcing use, Because when we are in the file hook, We will find... It has a file called FinalCore.java. Then before this FinalCore.java, It will first detect this... NewCore.java... Such a file. Well... Let's confirm this... Related logic code. It depends on where these two files are read. There are two ways. Because the application of NetEase Mailbox Master, It is... It has some mixed encryption. That is, its string of characters is at least mixed. For example, this A.C. Through some static methods, You can... Decrypt this algorithm. This is not a simple Base64 decode. It has some other steps. Then... You can also directly hook this A.C. Give its related results to... The return value. It can be dynamically decrypted. Anyway, we end up... Located here. The general logic is... Before loading this FinalCore.java, It will first check... Does this NewCore.java exist? If this NewCore.java exists, Rename it. Rename to this FinalCore.java. This business... When NetEase Mailbox Master first opened the screen, It has an ad. This ad has an update function. The update of this ad... Of course, it is not possible to download it every time. Reinstall such an application. And then update it. It can be dynamic. Push something. So it led to this loophole. We... Therefore, although we are in the process of re-downloading, It will be re-named. So we don't have this... The right to cover any file. But we can put such a NewCore.java. Then when it is downloaded next time, You may get a share. In order to ensure the normal operation of this application, That is, to ensure that this exploit is good enough, We need to do some follow-up operations on the downloaded file. For example, If we want to ensure its function, We can only insert some Smarty codes in it. Then get a share. The usual method is... Generally speaking, We generate such a share through Joseph or Metasploit. Then extract a share code from it. Finally, insert it into this related code. In the process of loading this DexPlusLoader, In the process of this hook, We can tell which types are being loaded. Then in these types of structure functions, Or some with context functions, We can insert this related payload star code. To get a remote reverse share. In addition to the plug-in, Maybe the application itself also has some related codes. There is a loophole. For example, Natali found this... There is such a loophole in the traversal code in Telegram. It can't cause any file coverage. However, it is in this KGNet structure. KGNet is a network related structure that manages Telegram. It has a configuration file. In the process of loading the configuration file, It has a back-up mechanism. That is to say, It will first check if this .bak file exists. If this .bak file exists, Restore it. This is usually due to... This... In order to co-operate, Some related logic is set. Therefore, In the process of exploring this loophole, Found that if you write to this .bak file, It may lead to this... The file is in the process of analysis. Because of some format problems. Because there are also some loopholes in it. Such a loophole. It will lead to a crash. So... So there will be some impact. Then it also... In this KGNet.dat file, It also... Set this... Related to Telegram... An IP port of the server. So there is a potential possibility. If this Telegram protocol is... After you figure it out, It may be possible to make a session hijack. But in this case, Some more in-depth analysis may be needed. But if such a loophole is used, Specific applications are needed. To analyze in detail. And... It may be difficult to have some... It is difficult to have some output. We found... A more universal way of use. In AOSP's original... Share preference. Such a very universal... A file type in the middle. It also has... Similar to this KGNet module. A backup mechanism. That is to say... Before it loads each... Share preference... XML file. It will first check this related... Does BAK exist? If it exists, it is RESTORE. After RESTORE, it can cause... An indirect write-in. That is to say, although we can't cover... Cover this XML. But we can write an XML... To BAK. In this way, when it loads... This loadSharePreference... It will also work. It is equivalent to... Covering this XML. Causing any share preference to be covered. In the case of Telegram... We can see... There is an XML called UserConfig. There is an XML called UserConfig. There is an XML called UserConfig. There is an XML called UserConfig. There is an XML called UserConfig. There will be its ID... FirstName... PhoneNumber... These things. After we cover this file... What effect can it cause? After covering TGNet and UserConfig at the same time... Can make this target user's... Account... Replace it with our own account. That is to say... It is like a... When other users send a file... We can see it here in real time. It creates a session hijack effect. Then... It also has a device binding effect. That is to say... It logs in there. Then I re-log in here. It can no longer... It can no longer forcibly... A offline. No matter whose account it logs in later... Because we have implemented... A device binding operation. As long as we forcibly log in here... It will offline there. No matter whose account it logs in. We can take a look at this... It is a common... Replacement of SharedPreference. What effect can it cause? This... In SharedPreference... Usually there will be some... Very important effects. For example, some links of HTTP. It may contain some... Download address of the plug-in. Update address. There will be some updates. There will be some... Some links of APK. If we change these places... It may cause RCE. Or... There is a way to fish. Then it may specify some plug-ins. Or... A version code itself. If we lower it... That is to say... It was originally 6.1. You change it to 6.0. Then in the next check update... There will be an update. Then according to... Some links of HTTP. It may... Implement this attack. That is to say... Run the update logic. There are some related... Hashi files. You want to download an... SO. But it may be through an HTTPS. It has already downloaded the SO MD5. Even if you replace it... It is also... In the process of complete verification... It will fail. So if we... After replacing all these things... You can implement the whole attack. And then... There may be some server-related codes. For example, in some browsers... It will have some DNS cache. Some IP port. Even some proxy. After modifying these things... It can also achieve... Some cool effects. The third... One point we can pay attention to is... Android's Rebooting. That is... In the middle of the path traversal loop... This kind of loop... This kind of file also has... A great opportunity. Rebooting is... In the application... When you don't need to reinstall... It can be very fast and convenient... Put this resource file... Even... Dex files, SO files... Some updates... It can be used to quickly repair... Some emergency booting... In some cases... It is widely used in large applications. In China... All major manufacturers have some related frameworks. For example, Tencent... There are many... For example, Tink... SuperHardPrint... And... WeChat Reading... Ali... Meituan... Rebooting will introduce some new problems. That is... It is difficult for us to guarantee... The completeness of the downloaded code... We can control it. That is... It may be tampered with... Or it may load some... Some codes that we can't control. In this case... It may lead to the execution of arbitrary codes. This is a very dangerous effect. In our... For... In our process of debugging the mailbox application... We also found that... In the QQ mailbox... There are also related... Related path traversal loopholes. It can't cause arbitrary files to be covered. But it has a Rebooting mechanism. Let's take a look at a related implementation of its Rebooting mechanism. When it is updated... It will download this... Download this link. Then do some signature verification. After the signature verification... There may be some MD5 verification. In the middle of these processes... There is no problem. Then it will put this... The DEX file inside... To a specific folder. This specific folder... Is specified in an XML. Up to this point... There is no problem. Because we can't control all of these. But when it is... Rebooting... It has some... Very dangerous operations. It uses a list file operation. That is to say, it will put this... Under the Rebooting path... All the DEX files... List them all. Then download them one by one. There is no way to do this. Because a lot of... Now this kind of... DEX files... There are some shortcomings. The number of methods supported by DEX files... Is limited. So it needs... Multi-DEX support. Such a mechanism. So there will be a lot of DEX. In order to integrate this change... The way they came up with... Is to use such a list file... To make a list. Then make an attack. And make a download. At the same time, at the level of DEX... There is no way to do... Signature verification. Because in this file... There is no information related to the application signature. So we can... Like this... DEX... DEX is... M-O-A-I patch... Under this path... Write a DEX of any kind. That is to use... The method we introduced in the online email master... This kind of SMARTY input method. Input a file. Then write it in. When it is executed next time... You can get a reverse email. The reverse file of the mailbox... I think the effect of the application is still great. Not only can you do this... Dragon attack. That is to say... Copy all his mails at the same time. So that we can see all his emails. You can fake his identity and send emails. It can even cause insect effects. That is... For each contact person... Each such contact person... Send more such files... There is still a certain range of influence. But we just mentioned... This is a problem with the hot pudding mechanism. So... Will only this old version be affected? Because there is no pudding in the new version. So there is no pudding path. We found in the middle of the analysis... He has such a... A pudding-specific XML file. Inside... This... When to hit the pudding... Pudding link... What path will pudding be placed under? And this... Related... Such a patch key... If you replace this file... That is... Can reach this... Multi-stage... Requires more... An interaction of cycles... But it can eventually reach such a... In the middle of the new version... Can also be used... Finally, let's talk about... How to do a fix. Before that... We just talked about this... Some common files... For example, the SQLite database... This file can actually... In a situation where it cannot be covered... To be covered... Because we can... Write a journal file... Under the db path... When it rolls back in time... It will have a... The effect of rolling back... Can put this... A change in the database... Is to modify it back... Indirectly create a... Any coverage of a db file... And finally, let's talk about how to fix it. Fix, in fact... The most critical step is... To do a... To do a... A bit of a test... First of all, we have to ensure that this file name... It is... To standardize it... Use this... Use this... Or... Such a standardized file... Read it out... And then... See if its db path... Is it... Under the path we need to write... If it exceeds... It is a path... A process that may exist... If we add this line of code... Is to be able to... Can cancel this path...