0. 抓包?Or 修改APP?
安卓APP本质上就是发送URL+一堆参数的一个客户端而已,而其中一般有两个重要的参数:TOKEN(标识用户的唯一性),另一个是防止逆向而设计的一个参数(往往由其它参数通过一个算法算出)。
今天我们的目的就是抓到TOKEN,如果可以抓包,那就是简单了。但是安卓7.0以后新增了证书验证,只信任系统证书,而不信任用户证书,导致无法抓包。
为了方便的获得这个TOKEN参数,我想到了修改APP让它自己吐出TOKEN。怎么修改哪?当然是像维修房子一样加减点东西。
大概过程就是:解开APP,smali层面修改代码(对话框弹出TOKEN,或copy到剪贴板上),重新打包回APP。
1. 解开APP
我选用的工具是apktool
C:\>apktool
Apktool v2.4.1 - a tool for reengineering Android apk files
with smali v2.3.4 and baksmali v2.3.4
Copyright 2014 Ryszard Wiśniewski <brut.alll@gmail.com>
Updated by Connor Tumbleson <connor.tumbleson@gmail.com>usage: apktool
-advance,--advanced prints advance information.
-version,--version prints the version then exits
usage: apktool if|install-framework [options] <framework.apk>
-p,--frame-path <dir> Stores framework files into <dir>.
-t,--tag <tag> Tag frameworks using <tag>.
usage: apktool d[ecode] [options] <file_apk>
-f,--force Force delete destination directory.
-o,--output <dir> The name of folder that gets written. Default is apk.out
-p,--frame-path <dir> Uses framework files located in <dir>.
-r,--no-res Do not decode resources.
-s,--no-src Do not decode sources.
-t,--frame-tag <tag> Uses framework files tagged by <tag>.
usage: apktool b[uild] [options] <app_path>
-f,--force-all Skip changes detection and build all files.
-o,--output <dir> The name of apk that gets written. Default is dist/name.apk
-p,--frame-path <dir> Uses framework files located in <dir>.For additional info, see: http://ibotpeaches.github.io/Apktool/
For smali/baksmali info, see: https://github.com/JesusFreke/smaliC:\>apktool d xxx.apk
你会发现创建出了一个文件夹,里面有很多smali做后缀的文件。
Smali是用于Dalvik(Android虚拟机)的反汇编程序实现。它是一种宽松式的Jasmin/dedexer语法,是Davlik的寄存器语言,语法上和汇编语言相似。Smali支持注解、调试信息、行数信息等基本Java的基本特性,可以说是很接近Java编译在JVM上的中间语言,一般用来做Android程序的逆向工程。
2. 修改smali文件
找一个不太重要的Activity, 比如设置(SettingActivity)。先添加获得TOKEN的代码,如果你知道哪个变量就是TOKEN那就不必获得了。
注意:下面的代码仅仅是示例,不是万能的。你可能需要学习一点smali语法。
###get Token
invoke-static {}, Lcom/ultimavip/framework/net/a;->c()Lcom/ultimavip/framework/bean/TokenInfo;
move-result-object v0
move-object p1, v0
invoke-virtual {p1}, Lcom/ultimavip/framework/bean/TokenInfo;->getAccessToken()Ljava/lang/String;
move-result-object v0
###end, get Token
然后copy到剪贴板上:
###copy to clipboard
const-string p1, "clipboard"
invoke-virtual {p0, p1}, Lcom/xxx/activity/SettingActivity;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;
move-result-object p1
check-cast p1, Landroid/content/ClipboardManager;
const-string v1, "Label"
invoke-static {v1, v0}, Landroid/content/ClipData;->newPlainText(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Landroid/content/ClipData;
move-result-object v0
invoke-virtual {p1, v0}, Landroid/content/ClipboardManager;->setPrimaryClip(Landroid/content/ClipData;)V
###end, copy to clipboard
3. build新的APP
c:\> apktool b [folder_above]
最后把APP上传到手机试试点“设置” ,然后到微信黏贴试试。
资料:
1. http://ibotpeaches.github.io/Apktool/
2. https://github.com/JesusFreke/smali