frida自定义url调用okhttp

function hook_shield(){
    var Builder  =Java.use("okhttp3.Request$Builder")
    Builder.header.implementation = function(key,value){
        if(typeof this.build().url!="undefined"&&this.build().url().toString().indexOf("search/user")>-1){
            var encryptUrl = this.build().url().toString();
            var devnulUrl= encryptUrl.replace("xiaohongshu.com","baidu.com");
            console.log("key,value:===>",key,value)
            return this.url(devnulUrl).header(key,value);
            
        }
        return this.header(key,value)
    }
    Builder.addHeader.implementation = function(key,value){
        console.log("addHeader key,value:==>",key,value)
        return this.addHeader(key,value)
    }

    var RealInterceptorChain = Java.use("okhttp3.internal.http.RealInterceptorChain")
    RealInterceptorChain.proceed.overload("okhttp3.Request").implementation = function(request){
        if(typeof request.url!="undefined" && typeof request.newBuilder!="undefined" &&typeof request.newBuilder().url!="undefined"){
            var myurl = "https://www.xxxx.com/api/sns/v3/search/user?keyword=%E7%BE%8E%E9%A3%9F&page=2&page_size=20&search_id=ssssxxx"
            var newRequest = request.newBuilder().url(myurl).build();
            var response = this.proceed(newRequest)
            var chainObject = this;
            return response;
        }
    }
}

function hook_java(){
    Java.perform(function(){
        var XhsHttpInterceptor = Java.use("com.xxx.shield.http.XhsHttpInterceptor")
        XhsHttpInterceptor.intercept.overload("okhttp3.Interceptor$Chain","long").implementation = function(x,y){
            var result = this.intercept(x,y)
            console.log("x,y:===>",x,y)
            console.log("result:===>",result)
            return result;
        }
        hook_shield()


});
}

function main(){

    hook_java();
    hook_native();
}

function hook_native(){

}
setImmediate(main)
posted @ 2022-01-21 17:46  公众号python学习开发  阅读(822)  评论(0编辑  收藏  举报