一
前言
二
第一关
第一关:This app can only run on Russian devices.
var system = Java.use("java.lang.System");
system.getProperty.overload('java.lang.String').implementation = function (str) {
var re = this.getProperty(str);
return "Russia";
}
三
第二关
第二关:Must be on the user whitelist.
根据上面的图片,这一关的关键是System.getenv(“USER”) =getResources().getString(R.string.User)即可通过下一关。通过上一关的分析我知道getenv的类是java.lang.String用样的方法hook修改返回值即可。那返回值是什么呢?从getResources大概可以猜测是资源文件,再跳转到R.string.User。
得到 User = 0x7f0d0000 应该是标记内存地址指向了某个元素,相互映射的关系,我们再搜索 0x7f0d0000
果然再资源文件里面,我再进行搜索。发现 对应的user字符串:RkxBR3s1N0VSTDFOR180UkNIM1J9Cg==
var system = Java.use("java.lang.System");
system.getenv.overload('java.lang.String').implementation = function (str) {
console.log("system.getenv : ", str)
var re = this.getenv(str);
console.log("system.getenv.re : ", re)
return "RkxBR3s1N0VSTDFOR180UkNIM1J9Cg==";
}
四
第三关
第三关:User not recognized.
adb shell input text 'codenameduchess'
五
第四关
第四关:Incorrect password.
var LoginActivity = Java.use("com.tlamb96.kgbmessenger.LoginActivity");
LoginActivity["j"].implementation = function () {
var ret = this.j();
return true;
};
六
第五关
第五关:V@]EAASBu0012WZFu0012e,a$7(&am2(3.u0003
a():
private String a(String str) {
char[] charArray = str.toCharArray();
for (int i = 0; i < charArray.length / 2; i++) {
char c = charArray[i];
charArray[i] = (char) (charArray[(charArray.length - i) - 1] ^ '2');
charArray[(charArray.length - i) - 1] = (char) (c ^ 'A');
}
return new String(charArray);
}
再写算法之前,我们先了解下python的异或^运算。
chr()将数字(10进制)转化为中文
ord() 将中文转化为数字(10进制)
def a(str_m):
charArray2 = list(str_m)
for ii in range(0, int(len(charArray2) / 2)):
cc = charArray2[ii]
print("ii ", ii, cc, " charArray2[ii] :", len(charArray2) - ii - 1, charArray2[len(charArray2) - ii - 1],
chr(ord(charArray2[len(charArray2) - ii - 1]) ^ ord('2')), "charArray2[len(charArray2) - ii - 1] :",
len(charArray2) - ii - 1, chr(ord(cc) ^ ord('A')))
charArray2[ii] = chr(ord(charArray2[len(charArray2) - ii - 1]) ^ ord('2'))
charArray2[len(charArray2) - ii - 1] = chr(ord(cc) ^ ord('A'))
charArrayStr2 = "".join(charArray2)
print("charArrayStr2:", charArrayStr2)
return charArrayStr2
if __name__ == '__main__':
str_m = "abcdef" # UTWd"
# re = a(str_m)
var MessengerActivity = Java.use("com.tlamb96.kgbmessenger.MessengerActivity");
MessengerActivity["a"].implementation = function (str) {
console.log('a is called' + ', ' + 'str: ' + str);
var ret = this.a(str);
console.log('a ret value is ' + ret);
return ret;
};
结果:
a is called, str: abcdef
a ret value is TWV"#
求y : x ^ '值' = y
求x : y ^ '值' = x
def a_jie(str_m):
str_m_fanzhuan = str_m[::-1]
charArray2 = list(str_m_fanzhuan)
for ii in range(0, int(len(charArray2) / 2)):
cc = charArray2[ii]
charArray2[ii] = chr(ord(charArray2[len(charArray2) - ii - 1]) ^ ord('2'))
charArray2[len(charArray2) - ii - 1] = chr(ord(cc) ^ ord('A'))
charArrayStr2 = "".join(charArray2)
print("charArrayStr2:", charArrayStr2) # fedcba
# 再反转:
str_m_fanzhuan = charArrayStr2[::-1]
print(str_m_fanzhuan)
return str_m_fanzhuan
ss = "V@]EAASBu0012WZFu0012e,a$7(&am2(3.u0003"
re = a_jie(ss) # Boris, give me the password
返回结果:Boris, give me the password
七
第六关
private String b(String str) {
char[] charArray = str.toCharArray();
for (int i = 0; i < charArray.length; i++) {
charArray[i] = (char) ((charArray[i] >> (i % 8)) ^ charArray[i]);
}
for (int i2 = 0; i2 < charArray.length / 2; i2++) {
char c = charArray[i2];
charArray[i2] = charArray[(charArray.length - i2) - 1];
charArray[(charArray.length - i2) - 1] = c;
}
return new String(charArray);
}
def b(str_m):
charArray = list(str_m)
charArray2 = list(str_m)
for i in range(len(charArray)):
charArray[i] = chr((ord(charArray[i]) >> (i % 8)) ^ ord(charArray[i]))
print(i,charArray2[i],charArray[i])
print(charArray)
for i2 in range(int(len(charArray) / 2)):
c = charArray[i2]
charArray[i2] = charArray[(len(charArray) - i2) - 1]
charArray[(len(charArray) - i2) - 1] = c
print(i2,c, charArray[i2], len(charArray) - i2 - 1,charArray[(len(charArray) - i2) - 1])
print(charArray)
charArrayStr2 = "".join(charArray)
return charArrayStr2
char[] charArray = str.toCharArray();
for (int i = 0; i < charArray.length; i++) {
charArray[i] = (char) ((charArray[i] >> (i % 8)) ^ charArray[i]);
}
def b_jie(str_m):
str_m = " 00dslp}oQ 00 dks$|M 00h +AYQg 00P*!M$gQ 00"
charArray = list(str(str_m))
print(str_m)
charArray.reverse()
print(charArray)
for i in range(len(charArray)):
if i % 8 == 0:
print("_", end="")
continue
for ch in string.printable:
final_ch = chr((ord(ch) >> (i % 8)) ^ ord(ch))
if final_ch == charArray[i]:
print(ch, end="")
结果:
['x00', 'Q', 'g', '$', 'M', '!', '*', 'P', 'x00', 'g', 'Q', 'Y', 'A', '+', ' ', 'h', 'x00', 'M', '|', '$', 's', 'k', 'd', ' ', 'x00', 'Q', 'o', '}', 'p', 'l', 's', 'd', 'x00']
_ay I *P_EASE* h_ve the _assword_
总体来说hook的逻辑还是简单的,代码相信大家都能看得懂,唯一的难度就是a和b方法的加密算法的还原。
看雪ID:西贝巴巴
https://bbs.kanxue.com/user-home-961239.htm
# 往期推荐
2、Glibc-2.35下对tls_dtor_list的利用详解
球分享
球点赞
球在看
点击阅读原文查看更多
原文始发于微信公众号(看雪学苑):Frida 实战 KGB Messenger