python之app逆向破解headers中的Authorization 身份验证 AES

下载好app 贝壳 2018-5-2 版本

1.还是先抓包

注册入口

2.用jadx-gui打开

直接用jadx-gui打开,因为没有加壳
并搜索关键字Authorization

点击右键 查找用例

3.开始Hook

从以下可以看出: 由 Appid + COLON_SEPARATOR + c 组成的,最后 Base64
所以从第一个入参开始跟踪
String encodeToString = Base64.encodeToString((GetAppId + Constants.COLON_SEPARATOR + DeviceUtil.c(sb.toString())).getBytes(), 2);

hook GetAppId 方法


得出Hook结果
多hook几次,一看肯定是固定的,不会变的参数

hook GetAppSecret 方法

com.homelinkndk.lib.JniClient

得出Hook结果
同样的道理,多hook几次,也是不会变的参数

跟踪 Constants.COLON_SEPARATOR

跟踪之后,发现 COLON_SEPARATOR 其实是 ":"

hook c 方法

com.homelink.midlib.util.DeviceUtil

得出Hook结果
d5e343d453aecca8b14b2dc687c381camobile_phone_no=13918238341request_ts=1606964312
首先想到的是,先用这些参数md5 或者 sha 在线加密下看看结果是不是一样的


通过在线加密方法得出 是SHA1 加密的结果
https://www.bejson.com/enc/sha/

4.用python实现

整个js 代码

Java.perform(function () {
    console.log('HOOK Start!!!');
    var Des3Encrypt = Java.use("com.homelink.midlib.util.DeviceUtil");//
    console.log(Des3Encrypt);
    // 加密
    Des3Encrypt.c.overload('java.lang.String').implementation = function (args1) {
        console.log("encryptByPublicKey args1:",(args1));
        //console.log("encryptByPublicKey args2:",args2);
        //console.log("encryptByPublicKey args3:",args3);
        //console.log("Encrypt args4:",args4);
        var result1 = this.c(args1);
        console.log("encryptByPublicKey result1=",result1);
        return result1;
    };
    var Des3Encrypt = Java.use("com.homelinkndk.lib.JniClient");//
    console.log(Des3Encrypt);
    Des3Encrypt.GetAppId.overload('java.lang.Object').implementation = function (args1) {
    console.log("splitString args1:",args1);
    //console.log("encryptByPublicKey args2:",args2);
    //console.log("encryptByPublicKey args3:",args3);
    //console.log("encryptByPublicKey args4:",args4);
    var result2 = this.GetAppId(args1,args2);
    console.log("encryptByPublicKey result2=",result2);
    return result2;
    };

    // 加密
     var Des3Encrypt = Java.use("com.homelinkndk.lib.JniClient");//
    console.log(Des3Encrypt);
    Des3Encrypt.GetAppSecret.overload('java.lang.Object').implementation = function (args1) {
        console.log("encryptByPublicKey args1:",args1);
        //console.log("encryptByPublicKey args2:",args2);
        //console.log("encryptByPublicKey args3:",args3);
        //console.log("encryptByPublicKey args4:",args4);
        var result3 = this.GetAppSecret(args1);
        console.log("encryptByPublicKey result3=",result3);
        return result3;
    };

})
def get_str_sha1_secret_str(res:str):
    """
    使用sha1加密算法,返回str加密后的字符串
    """
    sha = hashlib.sha1(res.encode('utf-8'))
    encrypts = sha.hexdigest()
    # print(encrypts)
    return encrypts

phone = '15751786649'
pwd = 'shqushuiw'
t = '1606981326'
Authorization =base64.b64encode(f'20180111_android:{get_str_sha1_secret_str(f"d5e343d453aecca8b14b2dc687c381camobile_phone_no={phone}password={pwd}request_ts={t}")}'.encode())
# print(Authorization)
app下载地址
链接:https://pan.baidu.com/s/1iHZZEV9IxQS8kHfNjhl5jg 
提取码:jsw8 
posted @ 2020-12-03 10:11  莫贞俊晗  阅读(1462)  评论(0编辑  收藏  举报