A software reinforcement method and system based on Android mobile terminal

By strengthening APK files with a single click on Android mobile devices, and utilizing shell templates and secure SO library technology, the problem of easily tampered local layer SO files is solved, achieving efficient security strengthening of mobile applications.

CN118133247BActive Publication Date: 2024-11-29ZHEJIANG SHUTWIN TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410249997.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-05
Publication Date
2024-11-29
Estimated Expiration
2044-03-05

AI Technical Summary

Technical Problem

The local layer SO files of existing Android applications are easily tampered with and reverse-engineered, resulting in insufficient security. Existing hardening techniques can be easily repaired after being decrypted in memory, and cannot effectively protect critical logic.

Method used

This tool enables one-click APK file hardening directly on Android mobile devices. It recompiles, decompresses, encrypts, and signs the APK using a shell template, generating a hardened APK. Combined with Hook technology and a secure SO library, it prevents tampering and reverse engineering.

Benefits of technology

It enables one-click hardening on mobile devices without the need for a computer. The generated hardened APK has anti-dexDump, SO file encryption, anti-tampering and anti-debugging functions for the shell program, thus improving the security of mobile applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118133247B_ABST
    Figure CN118133247B_ABST
Patent Text Reader

Abstract

The present invention discloses a software reinforcement method and system based on an Android mobile terminal, and relates to the technical field of software reinforcement. It includes: S1, obtaining the original APK of the software to be reinforced; S2, obtaining the corresponding shell DEX file; S3, decompressing the original APK to obtain the original DEX file and the original SO file; S4, parsing and extracting the original DEX file; S5, parsing and encrypting the original SO file and libsec.so; S6, saving the obtained shell DEX signature value and the libsec.so shell DEX signature value into the encrypted class.bin file; S7, repacking and signing to generate the reinforced APK. The present invention directly completes the entire reinforcement process on the Android mobile terminal, without the participation of the computer terminal, and can achieve one-key signing after reinforcement and install it on the mobile terminal.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software reinforcement, and in particular to a software reinforcement method and system based on an Android mobile terminal. Background Art

[0002] Since Android applications are mainly developed in Java, which has rich semantics, the classes.dex file in the APP can be easily disassembled into a Smali file by attackers, and then specific logic is modified or malicious code is inserted for secondary packaging. At the same time, it is well known that for the running speed and security of the APP, developers usually put the core algorithm logic of the APP in the Native layer and implement it with more efficient C / C++. Compared with Java, development using C / C++ has a higher level of security and is not easy to be decompiled and reverse analyzed.

[0003] The proportion of application-level SO files in an APK is increasing. At the same time, the malicious behavior of malicious applications has also shifted from the Java layer to the native layer. Currently, signature verification and key logic will also appear in the native layer. At this time, if the SO files compiled by the native layer are not effectively protected, attackers can easily locate the key logic and tamper with it, thereby repackaging it.

[0004] Android hardening technology mainly goes through the following stages: dynamic loading; in the development stage, the program is divided into two parts: loader and key logic (Payload), and they are packaged separately; the loader part (Loader) will run first during runtime, releasing the key logic (Payload), and then Java's dynamic loading technology will load and transfer control. The defect of this technology is that the dynamic loading mechanism requires the key logic (Payload) part to be decompressed and released to the file system. No landing loading; main process:

[0005] 1) Loader is loaded by the system;

[0006] 2) The system initializes the StubApplication (shell application) in the Loader;

[0007] 3) StubApplication decrypts and loads the original DEX file (Payload);

[0008] 4) StubApplication finds the original Application object from the original DEX file (Payload), creates and initializes it;

[0009] 5) Replace all references to the StubApplication object in the system with the original Application. This step is implemented using JAVA's reflection mechanism.

[0010] The drawback of this technology is: file-level encryption, which brings the problem that the Payload in memory is continuous. Instruction extraction: clear the function content (Code Item) in the original DEX during the release phase and remove it to a separate file; restore the function content to the corresponding function body during the run phase. The drawback of this technology is: traverse and trigger all functions to obtain all function contents. Finally, it can be reassembled into a complete DEX file. Instruction conversion / VMP: use a custom interpreter to complete the execution of the code. The open source nature of Android allows attackers to study and analyze the loading process of Dex instructions and the optimization process of Dex files by the virtual machine, so as to find the class loading restore point that appears during the system loading process, and further attack and analyze the protection methods of overall encryption and encryption of partial class loading methods. The security so library (libsec.so) is the so file in the shell template. Its core function is to ensure the normal operation of the hardened apk. For the local SO files in the APP, the SO files are currently mainly protected by encryption and shelling. However, based on the characteristic that they will be decrypted when running in memory, through dynamic debugging, memory dump is performed according to the starting address of the SO file in memory, and then the SO file can be restored by repairing it, and then further reverse analysis can be performed.

[0011] Therefore, it is an urgent problem for those skilled in the art to propose a software reinforcement method and system based on Android mobile terminal to solve the difficulties existing in the prior art. Summary of the invention

[0012] In view of this, the present invention provides a software reinforcement method and system based on an Android mobile terminal, which can realize the generation of a reinforced APK file from an unreinforced APK file directly on the mobile terminal with one click, which is convenient to use and eliminates the tedious steps from the mobile terminal to the computer terminal and then to the mobile terminal.

[0013] In order to achieve the above object, the present invention adopts the following technical solution:

[0014] A software reinforcement method based on an Android mobile terminal comprises the following steps:

[0015] S1. APK acquisition step: obtaining the original APK of the software to be hardened;

[0016] S2, shell template back compilation step: analyze the original APK of the software to be hardened to obtain the corresponding shell DEX file and libsec.so file;

[0017] S3, original APK decompression step: decompress the original APK to obtain the decompressed files, including but not limited to: original DEX files and original SO files;

[0018] S4, assets file generation step: parse and extract the original DEX file obtained in S3, and save the result in the corresponding assets file;

[0019] S5, lib file generation step: parse and encrypt the original SO file and libsec.so in S3, and save the encrypted files in the corresponding lib file;

[0020] S6, file adding step: Generate the shell DEX signature value and the core SO signature value according to the corresponding shell DEX file and libsec.so file obtained in S2, and save the obtained core SO signature value and shell DEX signature value into the encrypted class.bin file;

[0021] S7, packaging and hardening step: repackage and sign the corresponding shell DEX file in S2, the corresponding assets file in S4, the corresponding lib file in S5, and the encrypted class.bin file in S6 to generate the hardened APK.

[0022] In the above method, optionally, the specific contents of S2 include:

[0023] Decompile the original APK to obtain the smali file of the original APK and the AndroidManifest file in text format, analyze whether the AndroidManifest has the application and select the corresponding shell template smali file. If there is an application component in the AndroidManifest, select the shell template smali file with the application component. If there is no application component in the AndroidManifest, select the shell template smali file without the application component, obtain the shell template smali file and make corresponding modifications, and finally obtain the shell template file, compile the obtained shell template file back into a shell APK, and decompress it to obtain the shell DEX file.

[0024] The above method is optional, and the specific steps in S4 are as follows:

[0025] S401: Parse the original DEX file obtained in S3;

[0026] S402: extracting the code segment from the original DEX file, encrypting and saving the code segment;

[0027] S403: extract and save the corresponding metadata to obtain the hollowed-out DEX file;

[0028] S404: compress and save the hollowed-out DEX file obtained in S403;

[0029] S405: Save the files in S402-S403 to the assets directory.

[0030] In the above method, optionally, the specific content of S5 includes:

[0031] Parse the original SO file and libsec.so obtained from S3, parse the eif file format, and use key transformation technology to protect the key;

[0032] Among them, the shell SO file libsec.so is encrypted and a signature is generated through the Jni_Onload function and saved; the code segment of the original SO file is encrypted and saved; both are saved in the lib file.

[0033] In the above method, optionally, the hardened APK generated in S7 includes:

[0034] The original APK is run through secondary loading, and the hollowed-out and encrypted content is restored using Hook technology.

[0035] A software reinforcement system based on an Android mobile terminal, including a decompilation tool, executes any one of the above-mentioned software reinforcement methods based on an Android mobile terminal, including:

[0036] Data acquisition module, shell template back compilation module, original APK decompression module, assets file generation module, lib file generation module and packaging reinforcement module;

[0037] Among them, the data acquisition module is connected to the shell template back-compilation module and the original APK decompression module respectively, the APK decompression module is connected to the assets file generation module and the lib file generation module respectively, and the assets file generation module, the lib file generation module and the shell template back-compilation module are all connected to the packaging reinforcement module.

[0038] It can be seen from the above technical solution that, compared with the prior art, the software reinforcement method and system based on Android mobile terminal of the present invention has the following beneficial effects:

[0039] 1. The reinforcement method and system disclosed in the present invention can generate target files by one-click reinforcement;

[0040] 2. Existing reinforcement methods are all completed on the PC side, while the invention can complete the entire reinforcement process directly on the Android mobile terminal without the need for the PC side to participate;

[0041] 3. Compared with the lack of signature modules in the reinforcement systems on the market, this reinforcement system can be signed with one click after reinforcement and installed on the mobile terminal. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0043] Figure 1 A flowchart of a software reinforcement method based on an Android mobile terminal provided by the present invention;

[0044] Figure 2 A structural block diagram of a software reinforcement system based on an Android mobile terminal provided by the present invention;

[0045] Figure 3 A data flow diagram of a software reinforcement mobile terminal operation based on an Android mobile terminal is provided by the present invention. DETAILED DESCRIPTION

[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0047] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0048] The present invention can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, distributed computing environments including any of the above devices or devices, etc.

[0049] Reference Figure 1 As shown, the present invention discloses a software reinforcement method based on an Android mobile terminal, comprising the following steps:

[0050] S1. APK acquisition step: obtaining the original APK of the software to be hardened;

[0051] S2, shell template back compilation step: analyze the original APK of the software to be hardened to obtain the corresponding shell DEX file and libsec.so file;

[0052] S3, original APK decompression step: decompress the original APK to obtain the decompressed files, including but not limited to: original DEX files and original SO files;

[0053] S4, assets file generation step: parse and extract the original DEX file obtained in S3, and save the result in the corresponding assets file;

[0054] S5, lib file generation step: parse and encrypt the original SO file and libsec.so in S3, and save the encrypted files in the corresponding lib file;

[0055] S6, file adding step: Generate the shell DEX signature value and the core SO signature value according to the corresponding shell DEX file and libsec.so file obtained in S2, and save the obtained core SO signature value and shell DEX signature value into the encrypted class.bin file;

[0056] S7, packaging and hardening step: repackage and sign the corresponding shell DEX file in S2, the corresponding assets file in S4, the corresponding lib file in S5, and the encrypted class.bin file in S6 to generate the hardened APK.

[0057] Furthermore, the specific contents of S2 include:

[0058] Decompile the original APK to obtain the smali file of the original APK and the AndroidManifest file in text format, analyze whether the AndroidManifest has the application and select the corresponding shell template smali file. If there is an application component in the AndroidManifest, select the shell template smali file with the application component. If there is no application component in the AndroidManifest, select the shell template smali file without the application component, obtain the shell template smali file and make corresponding modifications, and finally obtain the shell template file, compile the obtained shell template file back into a shell APK, and decompress it to obtain the shell DEX file.

[0059] Specifically, based on the original APK, its description class file is analyzed to generate the corresponding shell dex file for packaging into the shell APK.

[0060] Furthermore, the specific steps in S4 are as follows:

[0061] S401: Parse the original DEX file obtained in S3;

[0062] S402: extracting the code segment from the original DEX file, encrypting and saving the code segment;

[0063] S403: extract and save the corresponding metadata to obtain the hollowed-out DEX file;

[0064] S404: compress and save the hollowed-out DEX file obtained in S403;

[0065] S405: Save the files in S402-S403 to the assets directory.

[0066] Specifically, the extracted code segment is encrypted and saved in the codedata.txt file, the extracted metadata is saved in the codeinfo.txt file, and the hollowed-out DEX file is compressed and saved as classes.dex.

[0067] Furthermore, the specific contents of S5 include:

[0068] Parse the original SO file and libsec.so obtained from S3, parse the eif file format, and use key transformation technology to protect the key;

[0069] Among them, the shell SO file libsec.so is encrypted and a signature is generated through the Jni_Onload function and saved; the code segment of the original SO file is encrypted and saved; both are saved in the lib file.

[0070] Specifically, the shell SO file libsec.so is encrypted and a signature is generated through the Jni_Onload function, and saved as the encrypted libsec.so file. The code segment of the original SO file is encrypted and saved as the encrypted SO file.

[0071] The encryption of SO files mainly involves the encryption of the text segment in the decompressed SO file. By analyzing the ELF file format, the starting address and size of the text segment in the SO file can be obtained, and then the segment is encrypted, and the encrypted SO library is hidden in the Assets directory. When running the hardened apk, the files in the Assets directory are restored to SO library files in advance; then through the inline_Hook of the find_library function, the find_library function will be executed when the application is loaded. After loading the SO library into the memory, the first address of the text in the virtual address space after loading can be obtained by intercepting the return value, so as to decrypt the memory section and restore the real text segment code.

[0072] Furthermore, the hardened APK generated in S7 includes:

[0073] The original APK is run through secondary loading, and the hollowed-out and encrypted content is restored using Hook technology.

[0074] Specifically, when the hardened apk is running, the hollowed-out dex file is backfilled in the memory by reloading the class loader classloader, thereby realizing the normal operation of the apk.

[0075] The hardened apk has the functions of anti-memory DexDump, SO file encryption, shell program anti-tampering, and anti-debugging; among them, (1) anti-memory DexDump is mainly divided into two steps. The first step is to extract the DEX file code segment (code segment) of the APK for encryption, and dynamically decrypt it during class loading, so as to prevent static attacks on the DEX file directly; the second step is to hinder the compilation process of the Dex2Oat process, so that the entire Dex fails to be loaded into the memory, and the Dex2Oat process cannot be compiled and executed, and can only dynamically load the class execution code through interpretation and execution. In the application startup process, after the hardened apk is started, the class loader ClassLoader will be replaced first to control the class loading process, and the code field information of the DEX file will be backfilled during the loading process, so as to realize the normal operation of the application. The above functions are implemented in the secure SO library.

[0076] (2) The encryption of SO files mainly involves the encryption of the text segment in the decompressed SO file. By analyzing the ELF file format, the starting address and size of the text segment in the SO file can be obtained, and then the segment is encrypted, and the encrypted SO library is hidden in the Assets directory. When running the hardened apk, the files in the Assets directory are restored to SO library files in advance; then, through the inline_Hook of the find_library function, the find_library function will be executed when the application is loaded. After loading the SO library into the memory, the first address of the text in the virtual address space after loading can be obtained by intercepting the return value, so as to decrypt the memory section and restore the real text segment code.

[0077] The anti-debugging function is divided into Java layer anti-jdb debugging and Native layer anti-ptrace debugging, which are mainly implemented in the security SO library. The Java layer anti-debugging method uses the select polling method, which polls the port of the current process by starting a thread to determine whether there is a port number being debugged and monitored. If so, it will immediately exit the operation. The Native layer anti-debugging uses the characteristics of ptrace. A thread can only be attached to one thread through the ptrace command. Start the thread in advance to attach to the process, thereby preventing it from being attached and debugged by other threads.

[0078] and Figure 1 Correspondingly, the present invention also discloses a software reinforcement system based on an Android mobile terminal, which executes any of the above-mentioned software reinforcement methods based on an Android mobile terminal, such as Figure 2 Shown include:

[0079] Data acquisition module, shell template back compilation module, original APK decompression module, assets file generation module, lib file generation module and packaging reinforcement module;

[0080] Among them, the data acquisition module is connected to the shell template back-compilation module and the original APK decompression module respectively, the APK decompression module is connected to the assets file generation module and the lib file generation module respectively, and the assets file generation module, the lib file generation module and the shell template back-compilation module are all connected to the packaging reinforcement module.

[0081] Specifically, with Figure 3 As shown, in this embodiment, a data flow diagram of the reinforced mobile terminal operation is disclosed:

[0082] (1) To harden the application startup, copy the core files (encrypted original dex files, encrypted SO file code segments, encrypted secure SO libraries, signatures of secure SO libraries and shell programs, etc.) in the resources directory of the APK compressed package to the sandbox directory of the application;

[0083] (2) Execute the initialization _attribute_ function of the security SO library (libsec.so) to complete the decryption of the JNI_OnLoad function in the security SO library. At the same time, through the inline_Hook of the find_library function, the find_library function will be executed when the application is loaded. After loading the SO library in the original apk (stored in the core file under the sandbox directory) into the memory, the first address of the text in the virtual address space after loading can be obtained by intercepting the return value, so as to decrypt the memory segment and restore the real text segment code.

[0084] (3) Execute the JNI_OnLoad function of the security SO library to start the file integrity verification function. The verification function is completed by checking the signatures of the security library SO and the shell program (stored in the core file in the sandbox directory) with the signatures (i.e. MD5) of the running shell program and libsec.so.

[0085] (4) Execute the JNI_OnLoad function of the security SO library and start the anti-memory DexDump function. By hindering the compilation process of the Dex2Oat process, the entire Dex fails to be loaded into the memory, making it impossible for the Dex2Oat process to compile and execute, and can only dynamically load the class execution code through interpretation and execution. In the application startup process, after the hardened apk is started, the class loader ClassLoader will be replaced first to control the class loading process, and the code field information of the DEX file will be backfilled during the loading process. The application component life cycle function of the original application is started, and the original application is started normally.

[0086] Execute the JNI_OnLoad function of the security SO library to start the anti-java debugging and native debugging functions. The Java layer anti-debugging method uses the select polling method, which polls the port of the current process by starting a thread to determine whether there is a port number being debugged and monitored. If so, it will immediately exit the operation. The native layer anti-debugging uses the characteristics of ptrace. A thread can only be attached to one thread through the ptrace command. Start the thread in advance to attach to the process, thereby preventing it from being attached and debugged by other threads.

[0087] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0088] Professionals may further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, computer software, or a combination of both.

[0089] In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0090] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A software reinforcement method based on an Android mobile terminal, characterized in that: The following steps are involved: S1. APK acquisition step: obtaining the original APK of the software to be hardened; S2, shell template back compilation step: analyze the original APK of the software to be hardened to obtain the corresponding shell DEX file and libsec.so file; The specific contents of S2 include: Decompile the original APK to obtain the smali file of the original APK and the AndroidManifest file in text format. Analyze whether the AndroidManifest has the application and select the corresponding shell template smali file. If there is an application component in the AndroidManifest, select the shell template smali file with the application component. If there is no application component in the AndroidManifest, select the shell template smali file without the application component. Get the shell template smali file and make corresponding modifications to finally get the shell template file. Compile the obtained shell template file back into a shell APK and decompress it to get the shell DEX file. S3, original APK decompression step: decompress the original APK to obtain the decompressed files, including but not limited to: original DEX files and original SO files; S4, assets file generation step: parse and extract the original DEX file obtained in S3, and save the result in the corresponding assets file; S5, lib file generation step: parse and encrypt the original SO file and libsec.so in S3, and save the encrypted files in the corresponding lib file; S6, file adding step: Generate the shell DEX signature value and the core SO signature value according to the corresponding shell DEX file and libsec.so file obtained in S2, and save the obtained core SO signature value and shell DEX signature value into the encrypted class.bin file; S7, packaging and hardening step: repackage and sign the corresponding shell DEX file in S2, the corresponding assets file in S4, the corresponding lib file in S5, and the encrypted class.bin file in S6 to generate the hardened APK; The specific steps in S4 are as follows: S401: Parse the original DEX file obtained in S3; S402: extracting the code segment from the original DEX file, encrypting and saving the code segment; S403: extract and save corresponding metadata to obtain a hollowed-out DEX file; S404: compress and save the hollowed-out DEX file obtained in S403; S405: Save the files in S402-S403 to the assets directory; The specific contents of S5 include: Parse the original SO file and libsec.so obtained from S3, and use key transformation technology to protect the key; Among them, the shell SO file libsec.so is encrypted and a signature is generated through the Jni_Onload function and saved; the code segment of the original SO file is encrypted and saved; both are saved in the lib file.

2. According to a method for strengthening software based on an Android mobile terminal according to claim 1, it is characterized in that: The hardened APK generated in S7 includes: The original APK is run through secondary loading, and the hollowed-out and encrypted content is restored using Hook technology.

3. A software reinforcement system based on Android mobile terminal, characterized in that: Executing a software reinforcement method based on an Android mobile terminal as described in any one of claims 1-2, comprising: Data acquisition module, shell template back compilation module, original APK decompression module, assets file generation module, lib file generation module and packaging reinforcement module; Among them, the data acquisition module is connected to the shell template back-compilation module and the original APK decompression module respectively, the APK decompression module is connected to the assets file generation module and the lib file generation module respectively, and the assets file generation module, the lib file generation module and the shell template back-compilation module are all connected to the packaging reinforcement module.

Citation Information

Patent Citations

  • Android application software reinforcement protection method based on DexClassloader

    CN106650330A

  • Method and device for protecting APK

    CN111191195A