攻防世界 easyjava 解题思路
一、jadx分析
通过jadx打开apk文件,查看其MainActivity可以发现大概逻辑为,传入的flag为flag{XXXXXXX}的样式,然后flag{}包裹的字符串经过逐字符加密后需要等于wigwrkaugala,加密函数主要由两个类来控制,a类和b类,于是分析这两个类
分析类b的主要功能为获取传入字符串在this.b中的索引,根据它的值再获取其在this.a中的索引返回,结束后this.a和this.b的第一位移动到最后一位
分析类a可以发现,其逻辑跟类b差不多,其主要功能是根据传入的值,寻找其在this.a中的索引,根据其获得的值,取到this.b中对应位置的字符。值得注意的是,类a中的this.a和this.b不会变动,只要字符串长度不超过25。
二、整体逻辑分析
根据三个类,可以分析出其最终加密逻辑为:
初始化b.a和a.a->传入字符->获取字符在b.b中对应索引->获取得到的值在b.a中对应索引(同时b.a和b.b的第一位移动到最后一位)->获取得到的值在a.a中对应的索引->获取以得到的值为索引对应在a.b中的值。
用python复现加密函数代码如下:
a_str = [i for i in "abcdefghijklmnopqrstuvwxyz"] # a.b
a = [21, 4, 24, 25, 20, 5, 15, 9, 17, 6, 13, 3, 18, 12, 10, 19, 0, 22, 2, 11, 23, 1, 8, 7, 14, 16] # a.a
b_str = [i for i in "abcdefghijklmnopqrstuvwxyz"] # b.b
b = [17, 23, 7, 22, 1, 16, 6, 9, 21, 0, 15, 5, 10, 18, 2, 24, 4, 11, 3, 14, 19, 12, 20, 13, 8, 25] # b.a
def encode(input):
result = a_str[a.index(b.index(b_str.index(input)))]
b.append(b.pop(0))
b_str.append(b_str.pop(0))
return result
所以根据其逻辑可以反推出解密逻辑为:
初始化b.a和a.a->传入字符->获取字符在a.b中对应索引->获取以得到的值为索引对应在a.b中的值->获取以得到的值为索引对应在b.a中的值->获取以得到的值为索引对应在b.b中的值(同时b.a和b.b的第一位移动到最后一位)。
用python复现解密函数代码如下:
a_str = [i for i in "abcdefghijklmnopqrstuvwxyz"] # a.b
a = [21, 4, 24, 25, 20, 5, 15, 9, 17, 6, 13, 3, 18, 12, 10, 19, 0, 22, 2, 11, 23, 1, 8, 7, 14, 16] # a.a
b_str = [i for i in "abcdefghijklmnopqrstuvwxyz"] # b.b
b = [17, 23, 7, 22, 1, 16, 6, 9, 21, 0, 15, 5, 10, 18, 2, 24, 4, 11, 3, 14, 19, 12, 20, 13, 8, 25] # b.a
def decode(input):
result = b_str[b[a[a_str.index(input)]]]
b.append(b.pop(0))
b_str.append(b_str.pop(0))
return result
三、编写解密脚本
最终完整的解密脚本如下(把循环中的decode换成encode则为加密脚本)
a_str = [i for i in "abcdefghijklmnopqrstuvwxyz"] # a.b
a = [21, 4, 24, 25, 20, 5, 15, 9, 17, 6, 13, 3, 18, 12, 10, 19, 0, 22, 2, 11, 23, 1, 8, 7, 14, 16] # a.a
b_str = [i for i in "abcdefghijklmnopqrstuvwxyz"] # b.b
b = [17, 23, 7, 22, 1, 16, 6, 9, 21, 0, 15, 5, 10, 18, 2, 24, 4, 11, 3, 14, 19, 12, 20, 13, 8, 25] # b.a
def decode(input):
result = b_str[b[a[a_str.index(input)]]]
b.append(b.pop(0))
b_str.append(b_str.pop(0))
return result
def encode(input):
result = a_str[a.index(b.index(b_str.index(input)))]
b.append(b.pop(0))
b_str.append(b_str.pop(0))
return result
encode_str = "wigwrkaugala"
decode_str = ""
for i in encode_str:
decode_str += decode(i)
print(decode_str)
得到解密的字符串为:venividivkcr
最终flag为:flag{venividivkcr}