Giter Club home page Giter Club logo

okhttplogger-frida's Introduction

OkHttpLogger-Frida

  • Frida 实现拦截okhttp的脚本

使用说明

① 首先将 okhttpfind.dex 拷贝到 /data/local/tmp/ 目录下。 okhttpfind.dex源码链接

执行命令启动frida -U -l okhttp_poker.js -f com.example.demo --no-pause 可追加 -o [output filepath]保存到文件

② 调用函数开始执行

  • find() 要等完全启动并执行过网络请求后再进行调用
  • hold() 要等完全启动再进行调用
  • history() & resend() 只有可以重新发送的请求

函数:

  `find()`                                         检查是否使用了Okhttp & 是否可能被混淆 & 寻找okhttp3关键类及函数	
  `switchLoader(\"okhttp3.OkHttpClient\")`         参数:静态分析到的okhttpclient类名
  `hold()`                                         开启HOOK拦截
  `history()`                                      打印可重新发送的请求
  `resend(index)`                                  重新发送请求

原理:

由于所有使用的okhttp框架的App发出的请求都是通过RealCall.java发出的,那么我们可以hook此类拿到requestresponse, 也可以缓存下来每一个请求的call对象,进行再次请求,所以选择了此处进行hook。 find前新增check,根据特征类寻找是否使用了okhttp3库,如果没有特征类,则说明没有使用okhttp; 找到特征类,说明使用了okhttp的库,并打印出是否被混淆。

抓取打印的样例

例子1
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
| URL: https://lng.***.com/api/collect
|
| Method: POST
|
| Headers:
|   ┌─Content-Type: application/octet-stream; charset=utf-8
|   ┌─Content-Length: 3971
|   └─User-Agent: Dalvik/2.1.0 (Linux; U; Android 8.1.0; AOSP on msm8996 Build/OPM1.171019.011) Resolution/1080*1920 Version/6.59.0 Build/6590119 Device/(google;AOSP on msm8996) discover/6.59.0
|
| Body:
|   hex[........]//省略了,太长了
|
|--> END  (binary body omitted -> isPlaintext)
|
| URL: https://lng.***.com/api/collect
|
| Status Code: 200 / 
|
| Headers:
|   ┌─date: Sat, 29 Aug 2020 10:09:28 GMT
|   ┌─content-type: text/json; charset=utf-8
|   ┌─content-length: 41
|   ┌─access-control-allow-origin: *
|   ┌─access-control-allow-credentials: true
|   ┌─access-control-allow-methods: GET,POST,OPTIONS,HEAD
|   └─access-control-allow-headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Client-Build,X-Client-Platform,X-Client-Version,X-Mx-ReqToken,X-Requested-With,X-Sign
| 
| Body:
|   {"code":0,"msg":"Success","success":true}
| 
|<-- END HTTP
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

例子2
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
| URL: http://****/searchByKeywork
|
| Method: POST
|                                                                                                                    
| Headers:
|   ┌─Content-Type: application/x-www-form-urlencoded
|   └─Content-Length: 20
|
| Body:
|   userId=*****&keyword=run
|
|--> END 
|
| URL: http://****/searchByKeywork
|
| Status Code: 200 / 
|
| Headers:
|   ┌─Content-Type: application/json;charset=UTF-8
|   ┌─Transfer-Encoding: chunked
|   └─Date: Sat, 29 Aug 2020 10:18:50 GMT
| 
| Body:
|   {"code":1000,"message":"成功","result":[{"id":"jqjcRQFO2","name":"RUN","remark":"","shareKey":"dRbkPjn
|   J2sjVJTP0G","cover":null,"list":null,"index":0,"note":"更新至20200123期"}]}
| 
|<-- END HTTP
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

okhttp_find结果样例

 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 被 混 淆 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Start Find~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Find Result~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Cls_Call = "فمضﺝ.ثيغه";
var Cls_CallBack = "فمضﺝ.ﺙلﺩج";
var Cls_OkHttpClient = "فمضﺝ.ﻙﺫتك";
var Cls_Request = "فمضﺝ.ﺵكـﻅ";
var Cls_Response = "فمضﺝ.صرفج";
var Cls_ResponseBody = "فمضﺝ.ضتﻭذ";
var Cls_okio_Buffer = "ﻭﻍﺫﻉ.ﺵﺱﻭع";
var F_header_namesAndValues = "ﻝبـق";
var F_req_body = "ﺵﺱﻭع";
var F_req_headers = "بﺙذن";
var F_req_method = "ﺯﺵتﻝ";
var F_req_url = "ﻝبـق";
var F_rsp$builder_body = "ﻝجﻭق";
var F_rsp_body = "ﺹﻅﻍز";
var F_rsp_code = "ﻝجﻭق";
var F_rsp_headers = "غﻝزث";
var F_rsp_message = "فمضﺝ";
var F_rsp_request = "ثيغه";
var M_CallBack_onResponse = "onResponse";
var M_Call_enqueue = "ﻝبـق";
var M_Call_execute = "wait";
var M_Call_request = "";
var M_Client_newCall = "ﻝبـق";
var M_buffer_readByteArray = "ﺹﻅﻍز";
var M_contentType_charset = "ﻝبـق";
var M_reqbody_contentLength = "contentLength";
var M_reqbody_contentType = "contentType";
var M_reqbody_writeTo = "writeTo";
var M_rsp$builder_build = "ﻝبـق";
var M_rspBody_contentLength = "contentLength";
var M_rspBody_contentType = "contentType";
var M_rspBody_create = "create";
var M_rspBody_source = "source";
var M_rsp_newBuilder = "بﺙذن";


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Find Complete!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

详情见动图吧!如有问题,请 issues

  • 因为okhttp_poker.js覆盖了okhttp_cat.js的所有功能,所以放弃了okhttp_cat.js

免责声明

  • 仅做学习交流! 请勿商用!!
  • 若因使用本服务与相关软件官方造成不必要的纠纷,本人概不负责!
  • 本人纯粹技术爱好,若侵相关公司的权益,请告知删除!

特别感谢

okhttplogger-frida's People

Contributors

siyujie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

okhttplogger-frida's Issues

Error: writeTo(): argument types do not match any of

print request error : Error: writeTo(): argument types do not match any of:
.overload('okio.g')
at X (frida/node_modules/frida-java-bridge/lib/class-factory.js:563)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:966)
at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:547)
at printerRequest (/okhttp_poker.js:171)
at printAll (/okhttp_poker.js:106)
at (/okhttp_poker.js:89)
at (frida/node_modules/frida-java-bridge/lib/vm.js:16)
at perform (frida/node_modules/frida-java-bridge/index.js:193)
at buildNewResponse (/okhttp_poker.js:98)
at (/okhttp_poker.js:510)
at apply (native)
at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:613)
at (frida/node_modules/frida-java-bridge/lib/class-factory.js:592)

佬,报错了,拿不到Request Body
快手10.0.23,原生安卓7

bug 报错

Error: java.lang.ClassNotFoundException: Didn't find class "okio.Buffer" on path: DexPathL
ist[[dex file "/data/local/tmp/okhttpfind.dex"],nativeLibraryDirectories=[/system/lib, /ve
ndor/lib]]
at (frida/node_modules/frida-java-bridge/lib/env.js:124)
at (frida/node_modules/frida-java-bridge/lib/class-factory.js:443)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:812)
at _make (frida/node_modules/frida-java-bridge/lib/class-factory.js:112)
at use (frida/node_modules/frida-java-bridge/lib/class-factory.js:63)
at use (frida/node_modules/frida-java-bridge/index.js:246)
at (/okhttp_poker.js:606)
at (frida/node_modules/frida-java-bridge/lib/vm.js:11)
at perform (frida/node_modules/frida-java-bridge/index.js:193)
at hold (/okhttp_poker.js:623)
at (:1)
at eval (native)
at fridaReplEvaluate (/okhttp_poker.js:800)
at apply (native)
at (frida/runtime/message-dispatcher.js:13)
at c (frida/runtime/message-dispatcher.js:23)

hold()失败

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Start Find~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Find Result~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var Cls_Call = "okhttp3.e";
var Cls_CallBack = "okhttp3.f";
var Cls_OkHttpClient = "okhttp3.x";
var Cls_Request = "okhttp3.z";
var Cls_Response = "okhttp3.b0";
var Cls_ResponseBody = "okhttp3.c0";
var Cls_okio_Buffer = "okio.c";
var F_header_namesAndValues = "a";
var F_req_body = "d";
var F_req_headers = "c";
var F_req_method = "b";
var F_req_url = "a";
var F_rsp$builder_body = "g";
var F_rsp_body = "g";
var F_rsp_code = "c";
var F_rsp_headers = "f";
var F_rsp_message = "d";
var F_rsp_request = "a";
var M_CallBack_onFailure = "onFailure";
var M_CallBack_onResponse = "onResponse";
var M_Call_enqueue = "E3";
var M_Call_execute = "execute";
var M_Call_request = "W";
var M_Client_newCall = "a";
var M_buffer_readByteArray = "a1";
var M_contentType_charset = "b";
var M_reqbody_contentLength = "a";
var M_reqbody_contentType = "b";
var M_reqbody_writeTo = "h";
var M_rsp$builder_build = "c";
var M_rspBody_contentLength = "contentLength";
var M_rspBody_contentType = "contentType";
var M_rspBody_create = "create";
var M_rspBody_source = "source";
var M_rsp_newBuilder = "s";

这是find()找到后的
通过修改okhttp_poker.js填入后
再次执行hold()
提示

TypeError: cannot read property 'overload' of undefined
    at <anonymous> (/okhttp_poker.js:609)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:12)
    at perform (frida/node_modules/frida-java-bridge/index.js:192)
    at hold (/okhttp_poker.js:623)
    at <eval> (<input>:1)
    at eval (native)
    at fridaReplEvaluate (/okhttp_poker.js:800)
    at apply (native)
    at <anonymous> (frida/runtime/message-dispatcher.js:13)
    at c (frida/runtime/message-dispatcher.js:23)

类似已关闭issue Error: invoke(): argument types do not match any of:

Error: invoke(): argument types do not match any of:
.overload('java.lang.Object', '[Ljava.lang.Object;')
at X (frida/node_modules/frida-java-bridge/lib/class-factory.js:563)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:966)
at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:547)
at onResponse (/okhttp_poker.js:538)
at apply (native)
at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:613)
at (frida/node_modules/frida-java-bridge/lib/class-factory.js:592)

hold后可以抓到请求 但是app一直在转圈 并回显了这个错误 (新版 旧版都测试过)

Error: File not found on Frida 14.2.2

frida14.2.2 加载错误
Resuming main thread! [VTR AL00::com.xxxx.xxxx]-> Error: File not found at load (frida/node_modules/frida-java-bridge/lib/class-factory.js:1177) at <anonymous> (/okhttp_poker.js:774) at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:12) at _performPendingVmOps (frida/node_modules/frida-java-bridge/index.js:237) at <anonymous> (frida/node_modules/frida-java-bridge/index.js:229) at apply (native) at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:613) at <anonymous> (frida/node_modules/frida-java-bridge/lib/class-factory.js:592)

使用最新的okhttp4.10.0有问题闪退,但是在3.12.0就没问题

创建一个简单的demo,引用okhtt3版本3.12.0, 可以正常使用和获取数据,但是当引用版本为最新,例如4.10.0后,就闪退了。
打上日志后发现是在
function getFieldValue(object, fieldName)
方法里面的
var FieldClazz = Java.use(fieldValue.$className)
出问题了,直接闪退,即使使用try都不行捕获日志。此时field.$className的值为okhttp3.Headers(两个版本的值都是一样,不知道最新版为什么运行到这里会闪退)。

Error: writeTo(): argument types do not match any of

print request error : Error: writeTo(): argument types do not match any of:
.overload('okio.g')
at pe (frida/node_modules/frida-java-bridge/lib/class-factory.js:549)
at frida/node_modules/frida-java-bridge/lib/class-factory.js:951
at printerRequest (/okhttp_poker.js:171)
at printAll (/okhttp_poker.js:106)
at /okhttp_poker.js:89
at frida/node_modules/frida-java-bridge/lib/vm.js:11
at frida/node_modules/frida-java-bridge/index.js:304
at buildNewResponse (/okhttp_poker.js:98)
at /okhttp_poker.js:510

okhttpfind

请问okhttpfind的作用是什么呢?
可以直接写Java.use('okhttp3.OkHttpClient')吗?
我测试的时候直接写Java.use('okhttp3.OkHttpClient')发现只能hook到APP自身的流量,而无法hook到APP集成的第三方库的流量,求给小白指条路,不明白是为什么会这样,万分感谢!

某团执行hold后,Error: invoke(): argument types do not match any of

........... hookRealCall : okhttp3.RealCall
Error: invoke(): argument types do not match any of:
.overload('java.lang.Object', '[Ljava.lang.Object;')
at X (frida/node_modules/frida-java-bridge/lib/class-factory.js:563)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:966)
at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:547)
at onFailure (/okhttp_poker.js:540)
at apply (native)
at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:613)
at (frida/node_modules/frida-java-bridge/lib/class-factory.js:592)

switchLoader("okhttp3.x") 問題

不太確定我的使用方法是否正確,想詢問一下。

啟動Frida後,因為目標的APP是混淆過的,所以我使用Find()來尋找classname

var Cls_CallBack = "okhttp3.f";
var Cls_OkHttpClient = "okhttp3.x";
var Cls_Request = "okhttp3.aa";
var Cls_Response = "okhttp3.ac";
...

然後使用switchLoader方法來切換class,不過似乎失敗。

[Google Pixel::com.xxx.xxx]-> switchLoader("okhttp3.x")
Error: java.lang.ClassNotFoundException: Didn't find class "okhttp3.x" on path: DexPathList[[dex file "/data/local/tmp/okhttpfind.dex"],nativeLibraryDirectories=[/system/lib, /vendor/lib]]

Switch ClassLoader To :  dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.xxx.xxx-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx-1/lib/arm, /data/app/com.xxx.xxx-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]]


Switch ClassLoader Complete !

[Google Pixel::com.xxx.xxx]-> hold()
Error: java.lang.ClassNotFoundException: Didn't find class "okhttp3.OkHttpClient" on path: DexPathList[[dex file "/data/local/tmp/okhttpfind.dex"],nativeLibraryDirectories=[/system/lib, /vendor/lib]]
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/env.js:124)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/class-factory.js:443)
    at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:812)
    at _make (frida/node_modules/frida-java-bridge/lib/class-factory.js:112)
    at use (frida/node_modules/frida-java-bridge/lib/class-factory.js:63)
    at use (frida/node_modules/frida-java-bridge/index.js:245)
    at <anonymous> (/okhttp_poker.js:604)
    at <anonymous> (frida/node_modules/frida-java-bridge/lib/vm.js:12)
    at perform (frida/node_modules/frida-java-bridge/index.js:192)
    at hold (/okhttp_poker.js:623)
    at <eval> (<input>:1)
    at eval (native)
    at fridaReplEvaluate (/okhttp_poker.js:800)
    at apply (native)
    at <anonymous> (frida/runtime/message-dispatcher.js:13)
    at c (frida/runtime/message-dispatcher.js:23)

另外我有嘗試第二種方法,將find()的結果替換okhttp_poker.js中的變數。可以成功的呼叫hold()並且成功的intercept http封包,但在intercept收到的body顯示TypeError: not a function,不太確定是否有正確使用,再麻煩指教,謝謝。

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
| URL: https://xxx.xxx.com/xxx/xxx?xxx=xxx
|
| Method: GET
|
| Request Headers: 12
|   ┌─userkey: xxx
|   ┌─areaid: 1
|   ┌─appid: 10
|   ┌─channelId: xxx
|   ┌─deviceId: xxx
|   ┌─User-Agent: xxx/5.4.5 Android/7.1.1 (Google Pixel)
|   ┌─channelid: xxx
|   ┌─useridx: xxx
|   ┌─deviceType: android
|   ┌─androidId: xxx
|   ┌─version: 5.4.5
|   └─bundleid: com.xxx.xxx
|
|--> END
|
| URL: https://xxx.xxx.xxx/xxx/xxx?xxx=xxx
|
| Status Code: 200 / OK
|
| Response Headers: 12
|   ┌─Server: nginx
|   ┌─Date: Thu, 31 Dec 2020 09:01:00 GMT
|   ┌─Content-Type: application/json; charset=utf-8
|   ┌─Content-Length: 1128
|   ┌─Connection: keep-alive
|   ┌─Cache-Control: public, max-age=446
|   ┌─Expires: Thu, 31 Dec 2020 09:09:26 GMT
|   ┌─Last-Modified: Thu, 31 Dec 2020 08:59:26 GMT
|   ┌─Vary: *
|   ┌─X-AspNetMvc-Version: 5.2
|   ┌─X-AspNet-Version: 4.0.30319
|   └─X-Powered-By: ASP.NET
|
| Response Body:
print response error : TypeError: not a function
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

print response error : TypeError: not a function

┌─access-control-allow-origin: *
| ┌─access-control-allow-methods: GET,POST,OPTIONS,PUT,DELETE
| ┌─access-control-allow-headers: *
| ┌─access-control-allow-credentials: false
| ┌─access-control-max-age: 86400
| ┌─x-b3-spanid: 576a4a993db7a726
| ┌─x-nike-zhenghe-version: v4.9.0
| ┌─x-nike-zhenghe-cli-version: v9.5.1
| ┌─x-nike-zhenghe-count: 118381
| ┌─x-nike-zhenghe-timing-ms: 4
| └─x-nike-zhenghe-target-host: public.prod.commerce.origin.nike.com.cn
|
| Response Body:
print response error : TypeError: not a function
hold()后提示该错误。返回数据的协议头存在 但是body报错

Check failed: found_virtual Didn't find oat method index for virtual method: java.math.BigDecimal android.icu.math.BigDecimal.toBigDecimal()

Abort message: 'art/runtime/class_linker.cc:2761] Check failed: found_virtual Didn't find oat method index for virtual method: java.math.BigDecimal android.icu.math.BigDecimal.toBigDecimal()'
eax 00000000 ebx 00002557 ecx 00002557 edx 00000006
esi ffff96cc edi ffff9550
xcs 00000023 xds 0000002b xes 0000002b xfs 0000006b xss 0000002b
eip f7f1bd30 ebp ffff95d0 esp ffff94e8 flags 00000296

Error: invalid argument value

Error: invalid argument value
at frida/node_modules/frida-java-bridge/lib/env.js:166
at frida/node_modules/frida-java-bridge/lib/env.js:544
at frida/node_modules/frida-java-bridge/lib/class-factory.js:776
at frida/node_modules/frida-java-bridge/lib/class-factory.js:703
at getWrapper (/okhttp_poker.js:327)
at /okhttp_poker.js:506
at je (frida/node_modules/frida-java-bridge/lib/class-factory.js:633)
at frida/node_modules/frida-java-bridge/lib/class-factory.js:616

hook过程出现了这个错误,导致软件内动作都在加载中没有拿到返回结果。

app闪退了

Spawned com.xunmeng.pinduoduo. Resuming main thread!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.