前几天打CTF时遇到的一道安卓逆向,这里简单的写一下思路
- 首先用jadx打开apk文件,找到simplecheck处(文件名是simplecheck),可以看到基本逻辑就是通过函数a对输入的内容进行判断,如果正确就弹出You get it。
- 我们去类a里看一下可以发现这个就是一道简单的算法
- 判断的条件就是在这一个循环里,可以看到成功的条件是,而iArr[]为flag :
a[i2]== b[i2] * iArr[i2]* iArr[i2] + c[i2] * iArr[i2] + d[i2]
a[i2 + 1] == b[i2] * iArr[i2 + 1] * iArr[i2 + 1] + c[i2] * iArr[i2 + 1] + d[i2]
1 int i2 = 0; 2 while (i2 < c.length) 3 { 4 if (a[i2] != (((b[i2] * iArr[i2]) * iArr[i2]) + (c[i2] * iArr[i2])) + d[i2] || a[i2 + 1] != (((b[i2] * iArr[i2 + 1]) * iArr[i2 + 1]) + (c[i2] * iArr[i2 + 1])) + d[i2]) 5 { 6 return false; 7 } 8 i2++; 9 } 10 return true;
- 用python进行爆破
a.length指出flag的长度为35个,并且第一个值赋值为0,所以第一个循环从1到34。并且iArr[]里是byte,java中byte的范围从-128到127,所以第二个循环是0到127(ASCII从0开始)
1 int[] iArr = new int[a.length]; 2 iArr[0] = 0;
判断条件进行变化,使iArr变成一个变化值f,所以判断条件变为:
(a[m] == b[m-1] * f * f + c[m-1] * f + d[m-1])
(a[m] == b[m] * f * f + c[m] * f + d[m])
最后的爆破程序是
1 a= [0, 146527998, 205327308, 94243885, 138810487, 408218567, 77866117, 71548549, 563255818, 559010506, 449018203, 576200653, 307283021, 467607947, 314806739, 341420795, 341420795, 469998524, 417733494, 342206934, 392460324, 382290309, 185532945, 364788505, 210058699, 198137551, 360748557, 440064477, 319861317, 676258995, 389214123, 829768461, 534844356, 427514172, 864054312] 2 b= [13710, 46393, 49151, 36900, 59564, 35883, 3517, 52957, 1509, 61207, 63274, 27694, 20932, 37997, 22069, 8438, 33995, 53298, 16908, 30902, 64602, 64028, 29629, 26537, 12026, 31610, 48639, 19968, 45654, 51972, 64956, 45293, 64752, 37108] 3 c= [38129, 57355, 22538, 47767, 8940, 4975, 27050, 56102, 21796, 41174, 63445, 53454, 28762, 59215, 16407, 64340, 37644, 59896, 41276, 25896, 27501, 38944, 37039, 38213, 61842, 43497, 9221, 9879, 14436, 60468, 19926, 47198, 8406, 64666] 4 d= [0, -341994984, -370404060, -257581614, -494024809, -135267265, 54930974, -155841406, 540422378, -107286502, -128056922, 265261633, 275964257, 119059597, 202392013, 283676377, 126284124, -68971076, 261217574, 197555158, -12893337, -10293675, 93868075, 121661845, 167461231, 123220255, 221507, 258914772, 180963987, 107841171, 41609001, 276531381, 169983906, 276158562] 5 6 flag=""; 7 for m in range(1,34): 8 for f in range(0,127): 9 if (a[m] == b[m] * f * f + c[m] * f + d[m]) | (a[m] == b[m-1] * f * f + c[m-1] * f + d[m-1]) : 10 flag+=chr(f) 11 break 12 else: 13 pass 14 print(flag+"}")
- 结果为
Simplecheck.apk