The algorithm for Little Red Book’s shield parameter is calculated in libshield.so, so we need to analyze it from this so file.

Grab a bag and have a look.

Algorithm source screenshots at the bottom… Can be used as a reference!

Load the libshield.so file with IDA and find the function offset with Jni_load



Sub_2E1F4 is for verifying the signature of an app, for direct NOP, and for sub_736B0 is for calling some methods of Java’s OkHttp class through JNI. SUB_7306 is a dynamically registered function.

!

Locate the address off_8E0D0, as shown in the figure for each function.

!

Analyze the role of each function

InitializeNative function

! [Uppass…]



The initializeNative function initializes some classes that JNI calls Java methods. It is recommended to rename the variables. The classes begin with C_ and the methods begin with M_ for subsequent analysis.

The initialize function



The initialize function reads the value with the key main_hmac from the s.xml file.



The main function of sub_AAAC is to aes value and device_id to get a key, and store the key at PTR + 0x28C. If the value returned by sub_AAAC is 1, The new SHIELD algorithm is used, and the old S1-S12 algorithm is used.

Intercept function

The intercept is the logical part of SHIELD’s algorithm,



The value of PTR +650 is used to determine which algorithm to use. SUB_ABB8 is the new version and SUB_AD14 is the old version

!

The sub_1fbb0 function performs XOR on the key of the sub_AAAC function by 0x36 and 0x5c. Here, it is boldly surmised that SHIELD uses HMACMD5 algorithm. The sub_1fbb0 function initializes the key and the sub_1fc52 function MD5 on the URL. SUB_1FC7E is to wrap up the previous two steps to calculate the true SHIELD.



A1 +12 like this is a function pointer and I’m dynamically debugging to get the function address. Use MD5 with a magic change.

AES Decrypt method



AES Encrypt method



In the process of encryption and decryption, TBOX1-4 is used for encryption, TBOX5-8 is used for decryption, T is used for the first 9 rounds, and SBOX is used for the last round.

At this point, the initialize function analysis is completed.

Next, look at the intercept function. After debugging, we know that the program runs this branch



Let’s start with the 105B0 function, which performs MD5 operations on the requested data.



MD5 Update function



Enter the sub_404E8 function, initialize the structure, and save the information



Continue to the data processing, look at the string related information guess a function function



Encrypt the data after processing.

Initialize the encryption table



Encryption functions, simple XOR operations



After the encryption of the data processing, according to the relevant string guess, specific data debugging.

Finally, base64 encoding and concatenating the data is the value of SHIELD.





Finally get a new version of SHIELD, algorithm restore as follows, some code is more sensitive, not put out



Those of you who have worked with SHIELD probably know that it’s divided into S1-S12, and there’s a very distinct feature here



So much for the analysis of SHIELD, I hope you friends can take this post as a reference, algorithm source code welcome private communication or leave your questions in the comment area!