Http://www.cnblogs.com/jiaoxiake/p/6818786.html content is as follows
Introduction: Previous We analyzed the use of Android shelling dvmdexfileopenpartial under the principle of the breakpoint, using this method shelling has 2 disadvantages: 1. requires dynamic debugging 2. Anti-debug solutions to improve work efficiency, we do not want to waste precious time with the reinforcement of security engineers to do confrontation. As an efficient reverse analyst, the author is unable to endure, so I give you today to bring a new method of shelling--dexextractor shelling method. Resources Address: Dexextractor Source: Https://github.com/bunnyblue/DexExtractor DexExtractor shelling principle 1. A Dex file needs to be parsed into a DALIVK virtual function object Dvmdex, which must be called dexfile* dexfileparse (const u1* data, size_t length, int flags) during parsing. 2. dexfileparse function prototype is as follows: dexfile* dexfileparse (const u1* data, size_t length, int fla GS) data : The file is the first address of the Dex file that is optimized for data in memory. Length: The file is the length of the data in memory after the Dex file has been optimized. 3. dexextracctor is to rewrite the dexfileparse function, based on the original function, the data in the in-memory Dex file is Base64 encrypted and written to the mobile device's SD card 4. BASE64 encryption is used to hook up read.write functions for some hardening code. principle Analysis: According to the previous blog "Android shelling dvmdexfileopenpartial break the principle of shelling" analysis we know that a Dex file must be loaded through the dvmdexfileopenpartial function, Within this function call dexfileparse to parse the Dex file into dexfile We look at the Android source Dexfileparse implementation look at Dexextractor dexfilEparse implementation, you find that there are two lines more than the Android source code, and the two lines of coding format does not conform to the characteristics of a good programmer, there is no code alignment, this is the author intentionally for it, causing the attention of the code reader. dexhacker is a class that Dexextraor author customizes. You will find that you will call the Dexhacker class of Weitedex2encode, parse into this you here keyword encode, why need encryption, so we continue to analyze function writedex2encoded. can see that using Base64 to encrypt Dex files, encrypted dex is stored in the SD card, and the file name is related to the application.Note: Here we see the encrypted Dex file saved to the SD card and we know that this operation requires Android app to have permission to add a write SD card to this app:
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
Here we have a question: Why encrypt the Dex file, and then decrypt it, isn't that more of a hassle? 1. This is mainly to combat the reinforcement strategy, now some reinforcement platform, such as the Bang-bang reinforcement, Dex's memory dump to detect the shelling, specifically, the hook modifies the current process of read, write read-write related functions, once read is detected, Write read-write-related functions have the dump behavior of the Dex file in action to prevent Dex's memory dump from being handled. Dexextractor the author of the shelling tool consider that in order to get rid of this memory dump of the confrontation, the original Dex file data needs to be Base64 encrypted, after encryption, there is no Dex file format features. 2. This decryption tool is also in the GitHub directory Decode.jar, usage: Java-jar Decode.jar dexdir; It is important to note that Dexdir is the directory after we pull out Dex, remember the directory, not the corresponding Dex file Oh! Shelling steps of dexextractor shelling method As I have seen a bull using Dexextrator shelling example: http://www.wjdiankong.cn/apk%e8% 84%b1%e5%a3%b3%e5%9c%a3%e6%88%98%e4%b9%8b-%e5%a6%82%e4%bd%95%e8%84%b1%e6%8e%89%e6%a2%86%e6%a2%86%e5%8a%a0%e5% 9b%ba%e7%9a%84%e4%bf%9d%e6%8a%a4%e5%a3%b3/write very well, very detailed, simple refining out, shelling steps. 1, install Dexextractor function to Android device, We analyze the principle of dexextractor, we need to rewrite the function dexfileparser
- In the Android source code (AOSP), add the Dexextractor feature, and then compile the build system.img, but this system.img only uses the rest of Google phones and simulators (if you don't want to compile, Here is a modified system.img:Https://pan.baidu.com/s/1jG3WQMU, this file is Android4.4 system)
- If you don't have a Google phone and don't want to use the simulator, you can replace the phone system with the Libdvm.so,dexextractor GitHub available (ARM, X86 two versions)
- You use your phone to support the cm/lineageos/themuppets system, you can download their source code, and then use the Dexextractor source rewrite function dexfileparse, and then compile, brush the machine. (I support this, but the author has not done so, the initiative is all in our hands)
2, add write SD card permission. If your application does not have SD card permissions, then you will need to add <uses-permission android:name= "android.permission.WRITE_EXTERNAL_ in Androidmanifest.xml. STORAGE "/>, and then re-signing in the back of the build. 3, check the shelling process corresponding to the log, tag is DALVIKVM. Find information segments such as Create file end. Find the Dex file path after shelling. 4 . Export the Dex file after shelling in SD card to local, and use the Decode.jar tool to decrypt it. 5 . After decryption the DEX format Odex, so in order to use JADX convenient to view the code logic, you can use the Smali.jar tool to convert it to Dex file.
Dexextractor principle analysis of Android shelling [Zhuan]