一點(diǎn)資訊signature分析
環(huán)境
app:4.9.6.1
Java層
抓包

jadx搜索"signature"

defpackage.bhl -> d

轉(zhuǎn)到com.yidian.news.util.sign.SignUtil.a

可以看到最終是調(diào)用了native函數(shù)signInternal。
frida hook一下
Java.perform(function(){
var signUtil = Java.use("com.yidian.news.util.sign.SignUtil");
signUtil.signInternal.implementation = function(ctx, s1) {
console.log("s1=", s1);
var ret = this.signInternal(ctx, s1);
console.log("ret=", ret);
return ret;
}
})

輸入的構(gòu)造可以參考上面defpackage.bhl-j函數(shù)是如何調(diào)用d函數(shù),并結(jié)合抓包的結(jié)果
so層
ida打開libutil.so,函數(shù)窗口搜索"Java"

說明是靜態(tài)注冊(cè),進(jìn)入signInternal函數(shù)

sub_EAC

sub_C50

emm,里面調(diào)用的函數(shù)有點(diǎn)多,一時(shí)間不知道干什么,先從輸出開始倒推吧。
從signInternal可以看到v24是返回結(jié)果,而它是在sub_EAC的第4個(gè)參數(shù)參與計(jì)算的;
然后再看sub_EAC的a4,a4由v9賦值,而v9=v8,v8由v12賦值,v12是sub_C50的第2個(gè)參數(shù);
繼續(xù)分析sub_C50,可以看到a2在sub_3560參與了計(jì)算,所以應(yīng)該看看這個(gè)函數(shù)

好家伙,一看就是base64了,那個(gè)字符串就是碼表。
繼續(xù)倒推,sub_C50的輸入應(yīng)該是v19和v14,它在sub_4AF4參與了計(jì)算,查看一下

通過里面的字符串,我們猜測(cè)整體是一個(gè)RSA加密,然后再base64編碼,有一個(gè)tomcrypt需要上網(wǎng)查查

hook驗(yàn)證這兩個(gè)函數(shù)驗(yàn)證一下我們的猜想
function dump(name, addr, legnth) {
console.log("======================== " + name + " ============");
console.log(hexdump(addr, {length:legnth||32}));
}
var bptr = Module.findBaseAddress("libutil.so");
console.log("base_addr:", bptr);
function hook_4fa4(){
Interceptor.attach(bptr.add(0x4fa4+1), {
onEnter: function(args) {
this.arg2 = args[2];
console.log("0x4fa4");
console.log(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
console.log(args[7], args[8], args[9], args[10]);
// dump("0x4af4-arg0", args[0], parseInt(args[1]));
// dump("0x4fa4-arg2", args[2]);
console.log("0x4af4-arg3", args[3].readPointer());
// dump("0x4af4-arg10", args[10]);
},
onLeave: function(retval) {
dump("0x4fa4-arg2-ret", this.arg2, 8*16);
}
})
}
function hook_3560(){
Interceptor.attach(bptr.add(0x3560+1), {
onEnter: function(args) {
this.arg2 = args[2];
this.arg3 = args[3];
console.log("0x3560");
console.log(args[0], args[1], args[2], args[3]);
dump("0x3560-arg0", args[0], parseInt(args[1]));
},
onLeave: function(retval) {
dump("0x3560-arg2-ret", this.arg2, parseInt(this.arg3.readPointer()));
}
})
}
Java.perform(function(){
hook_4fa4();
hook_3560();
})

和CyberChef的結(jié)果能夠?qū)ι?/p>

既然是RSA加密,而且應(yīng)該是公鑰加密,我們需要找出公鑰。

在sub_C50看到有一長串形似base64的字符串,就先看看sub_33F8這個(gè)函數(shù)

sub_3318

應(yīng)該調(diào)用了base64解碼,猜測(cè)它就是公鑰,導(dǎo)入看看

好像不太對(duì),應(yīng)該不是公鑰。。

這時(shí)候發(fā)現(xiàn)下面還有一個(gè)base64解碼,這個(gè)的結(jié)果會(huì)不會(huì)是公鑰,hook看看
function hook_33F8(){
Interceptor.attach(bptr.add(0x33F8+1), {
onEnter: function(args) {
this.arg2 = args[2];
this.arg3 = args[3];
console.log("33F8");
console.log(args[0], args[1], args[2], args[3]);
},
onLeave: function(retval) {
dump("0x33F8-arg2-ret", this.arg2, parseInt(this.arg3.readPointer()));
}
})
}
Java.perform(function(){
hook_33F8();
})

我們把第二個(gè)的結(jié)果作為公鑰導(dǎo)入試試

導(dǎo)入成功!至此,我們找到了公鑰,也知道了輸入,只需要代碼實(shí)現(xiàn)來驗(yàn)證一下。
代碼實(shí)現(xiàn)
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
_PUB_KEY = bytes.fromhex('30819f300d06092a864886f70d010101050003818d0030818902818100cfd9263315c70cc19c42d39531c1e8ba8a315c3a824e1cf1c12b6a115fa6550d264cc5bee0847d4753adda6f1cdc5bff8e0bce393a5c42e57640f4066d7e0107758369106c9a087135ceee0bb168a8bd32e962157561af4ab3feb29d479c9f53fc0f738029a0ae0f70cb95ac0b09199695cd84a67c18b8922b11ffce9c1ec0d90203010001')
def rsa_encrypt(msg):
if isinstance(msg, str):
msg = msg.encode()
cipher = PKCS1_v1_5.new(RSA.import_key(_PUB_KEY))
content = cipher.encrypt(msg)
sign = base64.urlsafe_b64encode(content).decode()
sign = sign.rstrip('=')
return sign

其他

其實(shí)第一次base64解碼的結(jié)果,會(huì)經(jīng)過sub_380C函數(shù)處理,作為第二次base64的輸入。看看sub_380C

這是一個(gè)解密函數(shù),暫不清楚是AES還是DES,或者其他,mode是CTR,填充暫不清楚。
但是實(shí)際上,我們已經(jīng)無需關(guān)心這些,因?yàn)閺膄rida hook的結(jié)果來看,第二次base64的輸出是固定的,所以說代碼實(shí)現(xiàn)的時(shí)候直接從這里開始。
總結(jié)
從signature的輸入來看,只有一個(gè)reqid會(huì)變,那么把它固定下來是不是就可以不用處理signature的問題了,因?yàn)?code>reqid包含時(shí)間戳信息,它的有效期我沒有驗(yàn)證過。此外cookie里面還有個(gè)參數(shù)JSESSIONID,如果請(qǐng)求的時(shí)候沒有攜帶是沒有結(jié)果的,它的有效期我也沒有驗(yàn)證過,所以說,signature只是其中一環(huán)而已。
代碼僅供把玩。