简单算法分析
本帖最后由 lakshmi 于 2016-1-20 14:52 编辑刚刚接触Android 动态调试,于是决定用@Ericky 大牛 的帖子练手:http://www.52pojie.cn/thread-454527-1-1.html,第一次分析Android算法,大牛勿喷{:1_935:}。
首先(大牛都说了没有反调试,就不装逼走过场了)运行apk,随便输入验证码,弹出Sorry, Fish!
接着用JEB分析apk文件查找特征字符串“Sorry, Fish!”,找到验证过程,发现验证函数EatRice
于是在libxy.so, 找到函数如下,动态调试发现程序首先判断 输入字符串的第一个字符是否是 'X'(0x58), 第二个字符是否是'#'(0x23), 字符串长度是否为7, 如果不满足这些条件则等待3s然后 返回0。 由此判断验证码格式应该为:"X#-----", 其中"-"表示暂时未知的字符。此处假定该字符串的名字为szA.
调试程序发现程序会将szA,szA, szA, szA, szA分别进行运算,并与相应的结果进行比较,如果结果都正确,才算成功。
szA 计算过程
szA 计算过程
szA 计算过程
szA 计算过程
szA 计算过程
具体算法就不描述了,具体看程序吧, 接下来说说破解过程吧,由于算法中涉及到了一些移位和反馈,因此倒推的难度比较高(个人认为), 但算法中是每两位一次进行运算而且每一位都是可见字符(0x21~0x7e),因此,此处的思路是逐位爆破,
此例中,在计算szA时,szA = '#'是已知的。则可以爆破出szA,
在szA的计算过程中szA已知, 则可计爆破出szA,
以此类推,则可爆破出每一位的值,
而计算时间复杂度也应该是O(1), 即最多(0x7e-0x21)*5 = 0x1d1 次运算即可算出答案,
接下来是破解程序:
#include "stdafx.h"
#include <Windows.h>
//最后两位计算过程
intsub_4B27B238(char *a1, int a2)
{
int v2; // r7@1
int v3; // r3@1
int v4; // r4@1
int v5; // r2@1
unsigned int v6; // r6@2
v2 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
while ( a2 )
{
v6 = *(BYTE *)a1;
v4 += (v6 >> 2) * v4 * v6 + 0x2FF54B62;
v2 += 32 * v6 * v2 * v6 + 0x58ECCC20;
v3 = v3 + 8 * v6 * v3 * v6 - 0x69C631BE;
v5 = v5 + 2 * v6 * v5 * v6 - 0x4B4D073E;
--a2;
a1++;
}
return v4 + v5 + v3 + v2;
}
int _tmain(int argc, _TCHAR* argv[])
{
//初始化
CHAR szA = {0};
szA = 'X';
szA = '#';
DWORD dwStartFlag = 0x21;
DWORD dwEndFlag = 0x7f;
DWORD dwR6 = 0, dwR0 = 0, dwR2=0, dwR3 = 0;
DWORD dwR7 = 0x0f8c9;
DWORD dwR4 = 0, dwR5 = 0, dwR1 = 0;
DWORD dwIndex;
//计算szA
for (DWORD dwTemp = dwStartFlag; dwTemp < dwEndFlag; dwTemp++ )
{
szA = (CHAR)dwTemp;
dwIndex = 0;
dwR7 = 0x0f8c9;
dwR4 = 0;
dwR5 = 0;
dwR1 = 0;
dwR6 = 0;
while (dwIndex < 2)
{
dwR6 *= dwR7;
dwR6 += szA;
//printf("%c\n", szA);
dwR1 = 0x05c6b7;
dwR7 *= dwR1;
dwIndex++;
}
dwR4 = (DWORD)((int)dwR6 >> 0x1f);
dwR5 = dwR6 + dwR4;
dwR5 = dwR5 ^ dwR4;
//printf("%x\n", dwR5);
if (dwR5 == 0x78689F66)
{
printf("%c\n", dwTemp);
break;
}
}
//计算szA
for (DWORD dwTemp = dwStartFlag; dwTemp < dwEndFlag; dwTemp++ ){
dwIndex = 0;
dwR5 = 0x4e67c6a7;
dwR4 = 0;
dwR1 = 0;
dwR6 = 0;
dwR7 = 0;
dwR2 = 0;
szA = (CHAR)dwTemp;
while(dwIndex < 2){
dwR7 = dwR5 << 5;
dwR0 = dwR5 >> 2;
dwR0 += (dwR7 + szA);
dwR5 ^= dwR0;
dwIndex++;
}
dwR0 = DWORD((int)dwR5 >> 0x1f);
dwR2 = dwR5 + dwR0;
dwR2 ^= dwR0;
if(dwR2 == 0x5B578B6A)
{
printf("%c\n", dwTemp);
break;
}
}
//计算szA
for (DWORD dwTemp = dwStartFlag; dwTemp < dwEndFlag; dwTemp++ ){
dwIndex = 0;
dwR4 = 0;
dwR1 = 0;
dwR6 = 0;
dwR7 = 0;
dwR5 = ~dwR7;
dwR2 = 0;
szA = (CHAR)dwTemp;
while(dwIndex < 2){
dwR0 = dwR7 << 4;
dwR6 = dwR0 + szA;
dwR0 = 0x0f;
dwR2 = dwR0 << 0x1c;
if(dwR7 == 0){
dwR7 = dwR6;
}
else
{
dwR0 = 0xffffffff;
dwR6 &= dwR0;
dwR7 = dwR7 >> 0x18;
dwR7 ^= dwR6;
}
dwIndex++;
}
dwR0 = DWORD((int)dwR7 >> 0x1f);
dwR4 = dwR7 + dwR0;
dwR4 ^= dwR0;
if(dwR4 == 0x2d8){
printf("%c\n",dwTemp);
break;
}
}
//计算szA
for (DWORD dwTemp = dwStartFlag; dwTemp < dwEndFlag; dwTemp++ ){
dwIndex = 0;
dwR5 = 0;
dwR4 = 0;
dwR6 = 0;
dwR3 = 0;
dwR7 = ~dwR4;
dwR2 = (0x0f << 0x1c);
//printf("dwR2: %x\n", dwR2);
szA = (CHAR)dwTemp;
while(dwIndex < 2){
dwR5 = szA + dwR4;
dwR6 = dwR5;
dwR6 = dwR6 & dwR2;
dwR4 = dwR5;
//printf("%x\n", dwR5);
//("dwR6: %x\n",dwR6);
if(dwR6 != 0){
dwR4 = dwR6 >> 0x18;
dwR4 ^= dwR5;
}
dwR5= dwR5 | 0x0fffffff;
dwR5 ^= dwR2;
//printf("dwR5: %x\n", dwR5);
dwR5 &= dwR4;
dwR4 = dwR4 << 4;
//printf("dwR5: %x\n", dwR5);
dwIndex++;
}
dwR3 = DWORD((int)dwR5 >> 0x1f);
dwR2 = dwR5 + dwR3;
dwR2 ^= dwR3;
//printf("%x\n",dwR2);
if(dwR2 == (0x0f << 6)){
printf("%c\n", dwTemp);
break;
}
}
//计算szA
for (DWORD dwTemp = dwStartFlag; dwTemp < dwEndFlag; dwTemp++ ){
szA = (CHAR)dwTemp;
dwR0 = 0;
dwR2 = 0;
dwR0 = (DWORD)sub_4B27B238(szA + 5, 2);
dwR2 =DWORD((int)dwR0 >> 0x1f);
dwR0 = dwR0 + dwR2;
dwR0 ^= dwR2;
if(dwR0 == 0x2f0c12ec){
printf("%c\n", dwTemp);
break;
}
}
printf("%s\n", szA);
运行结果:
静态的时候可以跟着分析,但是动态调试的时候,找不到libxy.so,也就无法从EatRice函数下断点,楼主可否解答一下 赞,顶一下 楼主大神,我还没有开始学安卓逆向,想请教一个小问题,手机上那个CF我想修改一个角色的速度,每次搜到的地址都不一样,搜的时间又长,很麻烦,可不可以在他的安装包里修改一下,把速度的初始值修改成我想要的,可以吗?楼主 又一个大牛出来了。 又要出现一个大牛了 好强悍,都玩手机破解了 支持大神 赞一个 好强悍,玩手机破解{:301_1005:} 厉害,我要好好学习了 不错的writeup还是有算法程序,赞一个