Security risks and precautions for Android applications

Source: Internet
Author: User

Code obfuscation

Android Development In addition to some of the features of C/D + + encoding, the rest of the main use of Java coding development capabilities. Java applications are very easy to decompile, and Android is no exception. You can get the source code from the installation package by using a similar anti-compilation tool such as Apktool. Google has provided Android with a proguard obfuscation scheme to protect developers ' intellectual property, to increase post-compilation source reading, but it is only a matter of time for Android developers to develop old drivers and reverse engineers to interpret and restore source code.

Proguard is for Java application Protection, not specifically for Android applications, Android, although using Java development, but after all, not running on the JVM, so the installation package structure and common Java application is still a lot of difference. If you are worried about free Proguard, consider a fee-splitting scheme Dexguard, in addition to having Proguard functionality, includes resource obfuscation, string encryption, class encryption, and Dex file segmentation.

    • For Proguard, see: Https://www.guardsquare.com/en/proguard
    • For Dexguard, see: Https://www.guardsquare.com/en/dexguard
    • For the anti-compilation tool, see my old article: the Android Competitor analysis tool that you should try

While code obfuscation is the most basic protection, there are still many applications in the country, including some large-scale applications (not shown here).

Signature Verification

Android Black production inside, there is a called two times packaging, also known as repacking. That is, through the anti-compilation of the original application, you can get Smali source code, injected into it or modify the corresponding business logic, and then re-packaged with the new signature, and published to the application market, many unscrupulous developers in this way to crack some paid applications or inject advertising code to profit. Simply comb the basic process of repackaging:

    1. The use of Apktool reverse tool to solve the genuine application;
    2. Inject Smali code in a place;
    3. Using the IDE to generate signature files, and then signed by Jarsigner;
    4. Upload the application market;

In order to fight against two packs, you can increase the check signature detection in the key function entry in the application, and if the application signature is found to be non-genuine, force the app to close or restrict the user's use. When you add a signature check code, consider:

    1. In the JNI layer to verify the code, compared to the Java layer of code, the JNI layer of the reverse difficulty is greater;
    2. If you want to validate code in the Java layer, do not expose a long string of strings in one place, which is a very obvious hint for reverse engineers. It is considered that the string can be scattered and stored everywhere, which will increase the difficulty of cracking analysis;

Of course, do not assume that the JNI on the rest, for the JNI layer, the same can be injected into the code to brute force to crack your signature verification logic, but compared to the Java layer, the JNI layer is more expensive, so it can intercept a part of the reverse of the crooked idea.

Add shell

The principle of Packers is to encrypt the Dex file in the original application's installation package, and its main operating methods are as follows:

    1. Prepare the original application installation package (hereinafter referred to as the original apk) for the shell, and the installation package (hereinafter referred to as the Shell apk).
    2. Disassemble the original apk to get the various parts and encrypt the Dex file (hereinafter referred to as the original Dex);
    3. Combine the cryptographic original Dex and the Dex in the Shell apk into a new Dex file;
    4. Use special packaging tools to merge and generate encrypted apk;

This is done by hiding the Dex file in a way that ultimately uses ClassLoader to decrypt in memory and perform a dynamic load run. And if it is to modify the shell of the Dex file, it is mainly to extract Dexcode in the code after the bytecode instruction with 0 to fill, or modify the method properties and other operations, the repair time is the runtime in memory to do the corresponding correction work.

The installation package obtained through the shell without shelling operations, the reverse will not be able to get the real Dex files, there is no analysis. Here you can see the structure of an application using 360 reinforcement in the case of a pre-shelled installation package

There are only a few classes, and the Dex files in the real installation package are hidden, further complicating the reverse. About Packers, there are already many mature enterprise reinforcement program can be used, such as Bang Bang security, love encryption, 360 reinforcement and so on, if not specifically research this piece of developers to develop a set of shell solutions, obviously not too realistic.

The shell is only to improve the threshold of the reverse, for the lack of skills of the reverse developers, can only be dropped, and for the reverse of the veteran, shelling is also the problem of outsourcing time. In addition, the application of the shell to pay attention to platform compatibility issues, so that a well-known reinforcement products have appeared in the art of virtual machine incompatibility, and will affect the project using some of the hot repair technology.

Anti-dynamic debugging

Did you ever think you wouldn't be able to debug your Android app without getting the source code? However not, as long as the anti-compilation after get Smali code project, plus Smalidea debugging magic, minutes in the Android Studio debugging application to you see, the specific operation is not complicated, you can refer to my text at the end of the information provided. Even if you put the core code in the JNI layer, I can also sacrifice the artifact Ida Pro to continue debugging to you, not to mention, the actual development of the JNI layer can be put into the implementation of the core code is really limited.

In order to counter the dynamic debugging, you can consider the source code to arbitrarily interspersed with the relevant detection codes, in the detection of dynamic debugging, the direct process of suicide, abnormal exit the virtual machine, the general realization of the following:

    /** * Detect Dynamic Commissioning */PublicvoidDetecteddynamicdebug(){If(!Buildconfig.DEBUG){If(debug. ()) {//process suicide int mypid = android. Os.. (); android... (mypid//exception exit virtual machine system. (1} } }          /span>                

The above is just a simple example, many of the products on the market to do more dynamic debugging countermeasures.

Data protection

The main examples of data protection include the following:

    • Do not store login password (even if you encrypt) in the customer, preferably in the form of token;
    • Data transmission remember encryption;
    • Important data stored in the built-in storage, do not store external storage;
    • Encrypt important information stored in XML and database;
Resource Protection

Resource protection can also improve the difficulty of reverse analysis, but the individual feel that only the inverse small white effective, you can consider the introduction of trial, the current more well-known program is and the United States Regiment two, specifically see:

    • Install Pauli reduce 1m--android resource obfuscation packaging tool
    • The practice of confusing and protecting Android resources in US
Summarize

Application security of attack and defense is such a love to kill and complementary process, for the client can do security is limited, more or should be combined with back-office business analysis to achieve the corresponding confrontation mechanism, for small and medium-sized enterprises, there is no special security personnel to study the confrontation program, Choosing a proven reinforcement option on the market is a good choice. For large enterprises, the interior has already had its own Security center, naturally also has its own series of countermeasures, including the back end of the generation of each user's portrait to identify the user type and so on. Roughly is all these, the end of the text attached some good information, I hope this article can inspire you!

Security risks and precautions for Android applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.