One app security detection (360 Shell + algorithm analysis + data transfer injection)

Source: Internet
Author: User
Tags decrypt sqlite database python script


Recently to a certain app for security testing, the whole process takes several days, the most time-consuming is to write a relay script to achieve the automatic encryption and decryption process data, and the process encountered many small problems, toss for a long time.

1.360 shelling
Because apps are fortified, the best way to get more valuable information or to analyze the encryption algorithm for a packet is to look at the key cryptographic functions of the source code, all the first steps are to shell the app.
There seems to be a 360-reinforced shell on the web, but it is customary to use the previous way of shelling: Android-sdk-windows simulator and DDMS.
(1), view the reinforcement method
View the app reinforcement method, you can see is 360 reinforcement

(2) New simulator
Create a new native emulator using the Android SDK:

Then start our new simulator named 360, which takes a long time to start. )
Change how the system starts in the development mode in the setup:

Change the runtime to art mode, and then restart the emulator.

(3) Shelling
Install the hardened app to the emulator using the ADB debugging tool after the simulation reset: adb install xxx.apk
And then run the Android surveillance program DDMS

All of the app's port and log information will be displayed here.

Then run the app we just installed, and the log will display the Harvey:dex file Name-->/data/data/app package name/.jiagu/xxx.dex

will automatically decrypt the hardened Dex and dump it into the. Jiagu directory, we directly use ADB to copy the entire Jiagu directory to our computer: adb pull/data/data/ d:/aa/
With a lot of Dex files, we can reverse-compile Dex.

2. Encryption algorithm Analysis
Use Jd-gui to reverse-compile Dex to see key encryption codes.

Generally in the encryption algorithm to judge, usually the easiest way is to search the keyword directly: login, password, AES, DES, Sign, token, RSA and other keywords.

You can see that part of the encryption is AES encryption, and the encrypted offset IV is plaintext in the string. There are other algorithms for RAS algorithms: Using the server's public key to encrypt part of the data to the server.

Although the code is confused, the basic method is probably still understood.

3. Dynamic Data analysis
In the HTTPS communication of app, to capture the traffic of HTTPS, you need to install BP or FD certificate on the simulator.
(1) Decrypt HTTPS data
The data that decrypts HTTPS requires the xposed framework and the Justtrustme plug-in.

Now BP listens to all IP or intranet IP addresses

Open the test emulator test to see if the packet is caught. Run the app to view grab data:
Full encryption of data sent:

Returns full encryption of data:

You can see three ciphertext sent on each request and three cryptographic algorithms to validate the data together.

(2) Dynamic analysis of communication data
Static analysis before the encryption algorithm only know the approximate algorithm, there is no specific verification of encryption information, here through dynamic analysis can be clear encryption algorithm and key.
Use the Inspeckage plugin to hook up the app's related function methods (I'm not sure what the function is, I can see a lot of useful information).
The approximate functions are:
Feature one: Get basic information about the app
"1" Permission: Request permission (requested Permissions), custom permission (APP Permissions)
"2" Component: exported and non-exported components (activity, Service, broadcast Receiver, Content Provider)
"3" Shared library (shared libraries)
"4" logo bit: Debuggable,allow Backup
"5" Other: Uid,gids,package etc.

Function Two: View the behavior of the application in real time
"1" Shared Preferences (logs and files)
"2" serialization (serialized)
"3" Crypto (encrypted), Hash
"4" SQLite database
"5" HTTP, WebView, IPC, etc.
"6" Hooks (custom hook)

Function Three: Other operations

"1" Open any activity component (export and non-export)
"2" calls the provider component (export and non-export)
"3" To open, stop, restart the application

Approximate usage:
Run Inspeckage to open the app you want to monitor.

Click Start app, computer client run: adb forward tcp:8008 tcp:8008
Browser Open Local

Click on to start listening,

You can see that the partially encrypted data is encrypted by AES plus the dynamic key and the fixed IV. There are 2 other types of encryption in the packet.

4. Encrypt and decrypt the script
To tamper with a packet, you must decrypt the original ciphertext and then modify the data in the encrypted send server
Know that the algorithm is now encrypted with the Python script to decrypt the data.
AES's aes/cbc/pkcs5padding encryption:

Aes/cbc/pkcs5padding decryption with an online bar:

This algorithm decryption does not require a script, directly decrypt a clear text, and then repeatedly modify the plaintext and then through the encryption script to send the modified data. The data returned by the server is ciphertext and requires a script to decrypt it. There are other 2-paragraph encryption algorithms that don't give examples.

5. Data transfer Injection
Because the entire app communication uses HTTPS encrypted transmission, and each packet request is dynamic KEY+IV encryption, and the other 2 pieces of encryption in the packet can be changed at any time to normal send the server to resolve.
If you want to test the loopholes such as ultra vires or injection, and to get data through injection, manual words will be exhausted, all to achieve data transfer.
The whole process: first local request clear text data to the relay server-"relay server to the request package all kinds of encryption check-" Send the server---"Decrypt the server response-" Send the client.
Because all cryptographic algorithms are supported by Python scripts, the Basehttprequesthandler is implemented using Python, and HTTP requests are sent with URLLIB2.
Approximate code:

This was then a load balanced IP depressed for a long time, log in on the app all normal, but the relay script to go to the data has been mentioned not to login, for a long time to find the problem, and finally found that every once in a while away from the IP (IP address does not know what the rules, not the online F5 rules),
And the difference is not the same character, has not been found, resulting in a long delay. Then the IP and before the cookie must have a space, MD before feeling all the right, return is always prompted not to time out, I have a character to find a problem ....
The relay script uses the proxy to facilitate my data to go directly to BP, because the data that BP goes can communicate with the server directly https. My Python script doesn't want to do any more HTTPS certificates, sent directly to BP,BP to the server.
Then run injection holes directly: Python "" is OK.

At the end of the paper, attach a test effect chart:

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.