记一次 Hook 与 抓包
网友说有个 APP 直接去抓包抓不着,于是我又可以水一篇。
问
用了 sslkiller 也没有报网络错误;
- 可见不是 SSL Pinning,猜测只是没走代{过}{滤}理。
日志中暴露了关键字;
- 可以用来快速定位。
望
下载,反编译,kkp
利用朋友提供的、日志中暴露的关键字定位到网络请求的位置,发现 cz.msebera.android.httpclient
谷歌发现好像是对 android-async-http 的一种封装(?)
不管它是什么吧,走进去发现会 new 了一个 com.loopj.android.http.AsyncHttpClient
这个就很眼熟了,直接搜 proxy 发现:
public void setProxy(String arg4, int arg5) {
this.httpClient.getParams().setParameter("http.route.default-proxy", new HttpHost(arg4, arg5));
}
这还有什么好说的,hook 之,然后在构造之后反射调用 setProxy,让它走我需要的代{过}{滤}理。
这里又有一个问题,我们知道这些乱七八糟多种多样的 httpClient 通常默认都要校验证书,那就继续尝试搜 cert,发现:
private static SchemeRegistry getDefaultSchemeRegistry(boolean arg5, int arg6, int arg7) {
if(arg5) {
AsyncHttpClient.log.d("AsyncHttpClient", "Beware! Using the fix is insecure, as it doesn\'t verify SSL certificates.");
}
if(arg6 < 1) {
arg6 = 80;
AsyncHttpClient.log.d("AsyncHttpClient", "Invalid HTTP port number specified, defaulting to 80");
}
if(arg7 < 1) {
arg7 = 443;
AsyncHttpClient.log.d("AsyncHttpClient", "Invalid HTTPS port number specified, defaulting to 443");
}
SSLSocketFactory v0 = arg5 ? MySSLSocketFactory.getFixedSocketFactory() : SSLSocketFactory.getSocketFactory();
SchemeRegistry v1 = new SchemeRegistry();
v1.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), arg6));
v1.register(new Scheme("https", ((SocketFactory)v0), arg7));
return v1;
}
Beware! Using the fix is insecure, as it doesn\'t verify SSL certificates.
???太直白啦,那就让这个参数一直传入 true 好了,(其实看代码可以知道 false 的时候会调用 SSLSocketFactory.getSocketFactory,用 justtrustme 之类的工具也可以过掉)。
切
打开 AS 撸代码吧:
Class<?> cls = XposedHelpers.findClass("com.loopj.android.http.AsyncHttpClient", lpparam.classLoader);
Log.e(TAG, cls.toString());
XposedBridge.hookAllConstructors(cls,
new XC_MethodHook() {
protected void afterHookedMethod(XC_MethodHook.MethodHookParam mhparam) throws Throwable {
super.afterHookedMethod(mhparam);
de.robv.android.xposed.XposedHelpers.callMethod(mhparam.thisObject, "setProxy",
"192.168.125.2",
8888
);
}
}
);
//getDefaultSchemeRegistry
Class[] cArgs = {boolean.class, int.class, int.class};
Method m = cls.getDeclaredMethod("getDefaultSchemeRegistry", cArgs);
m.setAccessible(true);
Log.e(TAG, m.toString());
XposedBridge.hookMethod(m, new XC_MethodHook() {
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam mhparam) throws Throwable {
super.beforeHookedMethod(mhparam);
mhparam.args[0] = true;
}
});
安装上测试,成功√
闻
这里的闻不是听,是闻到隔壁炖的鸡汤好香啊。