Java Socket抓包的一个实现方式
本文为看雪论坛优秀文章
看雪论坛作者ID:virjar
>>>> 证书检查
证书检查
>>>> 双向证书认证
双向证书认证
>>>> App设置不走系统代理
App设置不走系统代理
>>>> SSL Socket Hook代码重入问题
SSL Socket Hook代码重入问题
>>>> TCP粘包拆包
TCP粘包拆包
>>>> GZIP压缩
GZIP压缩
支持所有基于java Socket对象的流量抓包 不需要考虑证书问题,包括证书检查,证书双向认证等。 不需要考虑网络库代码混淆问题。 不需要考虑代码设置不走系统代理的问题 支持数据报文内容和代码堆栈绑定(这个功能我觉得非常重要) 支持http1.x协议自动美化,包括处理分段,处理压缩 支持非http协议监控(本身抓包基于socket的,本来就和http没关系),并且同样支持绑定堆栈. 提供数据识别美化插件机制,http1.x美化功能就是通过改机制实现 提供数据报文数据监控插件机制,可将报文序列化到文件,输出到控制台等。
>>>> 依赖
依赖
compileOnly 'de.robv.android.xposed:api:82'
>>>> 开启模块
开启模块
sailfish:/data/data/com.virjar.ratel.demoapp/app_ratel_env_mock/default_0/data/app_socket_monitor # ls -alh
total 2.8M
drwx------ 2 u0_a71 u0_a71 12K 2019-10-22 17:02 .
drwx------ 4 u0_a71 u0_a71 4.0K 2019-10-22 14:34 ..
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:36 1571758577427_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:37 1571758613992_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:37 1571758650913_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:38 1571758687933_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:39 1571758730303_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:39 1571758767663_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:40 1571758804249_socket.txt
-rw------- 1 u0_a71 u0_a71 33K 2019-10-22 15:40 1571758840846_socket.txt
sailfish:/data/data/com.virjar.ratel.demoapp/app_ratel_env_mock/default_0/data/app_socket_monitor
Socket request local port:41752 remote address:47.94.106.20:80
StackTrace:java.lang.Throwable
at com.virjar.ratel.api.inspect.socket.OutputStreamWrapper.check(OutputStreamWrapper.java:111)
at com.virjar.ratel.api.inspect.socket.OutputStreamWrapper.write(OutputStreamWrapper.java:68)
at okio.Okio$1.write(Okio.java:79)
at okio.AsyncTimeout$1.write(AsyncTimeout.java:180)
at okio.RealBufferedSink.flush(RealBufferedSink.java:216)
at okhttp3.internal.http1.Http1Codec.finishRequest(Http1Codec.java:166)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:72)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall.execute(RealCall.java:69)
at com.virjar.ratel.demoapp.SocketMonitorTest.doTest(SocketMonitorTest.java:51)
at com.virjar.ratel.demoapp.SocketMonitorTest.access$000(SocketMonitorTest.java:16)
at com.virjar.ratel.demoapp.SocketMonitorTest$1.run(SocketMonitorTest.java:25)
GET /natChannelStatus?group=sekiro-demo HTTP/1.1
X-User-Experience-ID: aa54710f-7383-4a09-8923-3e897d3e1bbf
X-Channel-ID: ANDROID
X-API-Key: l7xx8389a5ba9eb24ae68bad068bd1860bfc
User-Agent: SouthwestAndroid/6.10.2 android/8.1.0
Accept-Encoding: gzip
Host: sekiro.virjar.com
Connection: Keep-Alive
Socket response local port:41752 remote address:47.94.106.20:80
StackTrace:java.lang.Throwable
at com.virjar.ratel.api.inspect.socket.InputStreamWrapper.check(InputStreamWrapper.java:145)
at com.virjar.ratel.api.inspect.socket.InputStreamWrapper.read(InputStreamWrapper.java:100)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall.execute(RealCall.java:69)
at com.virjar.ratel.demoapp.SocketMonitorTest.doTest(SocketMonitorTest.java:51)
at com.virjar.ratel.demoapp.SocketMonitorTest.access$000(SocketMonitorTest.java:16)
at com.virjar.ratel.demoapp.SocketMonitorTest$1.run(SocketMonitorTest.java:25)
HTTP/1.1 200
Server: nginx
Date: Tue, 22 Oct 2019 15:39:04 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
{"status":0,"message":null,"data":[],"clientId":null,"ok":true}
sailfish:/data/data/com.virjar.ratel.demoapp/app_ratel_env_mock/default_0/data/app_socket_monitor
>>>> 备注
备注
看雪ID:virjar
https://bbs.pediy.com/user-791488.htm
推荐文章++++
* ollvm源码分析 - Pass之SplitBaiscBlocks