
正文
Jarvis OJ - 爬楼梯 -Writeup
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Jarvis OJ - 爬楼梯 -Writeup
本来是想逆一下算法的,后来在学长的指导下发现可以直接修改关键函数,这个题做完有种四两拨千斤的感觉,记录在这里
转载请标明出处:http://www.cnblogs.com/WangAoBo/p/7222012.html
题目:
本来是想逆一下算法的,后来在学长的指导下发现可以直接修改关键函数,这个题做完有种四两拨千斤的感觉,记录在这里
转载请标明出处:http://www.cnblogs.com/WangAoBo/p/7222012.html
分析:
先看apk的外部特征,在模拟器中安装apk,如下:
每次点击 爬一层楼 按钮 以爬的楼层 会加1, 爬到了,看FLAG 按钮点击无效,于是猜测需要爬到指定的楼层才可以看到flag。
首先大致浏览apk的java代码(这里使用的是dex2jar+jd-jui的方法),代码的命名和逻辑都很清晰,MainActivity的代码如下:
package com.ctf.test.ctf_100; import android.os.Bundle;
import android.os.Debug;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random; public class MainActivity
extends AppCompatActivity
{
public int has_gone_int;
public int to_reach_int; static
{
if (!Debug.isDebuggerConnected()) {
System.loadLibrary("ctf");
}
} public void Btn_up_onclick(View paramView)
{
this.has_gone_int += 1;
paramView = "" + this.has_gone_int;
((TextView)findViewById(2131492948)).setText(paramView);
if (this.to_reach_int <= this.has_gone_int) {
((Button)findViewById(2131492950)).setClickable(true);#第一个setClickable
}
} public void btn2_onclick(View paramView)
{
((TextView)findViewById(2131492951)).setText("{Flag:" + get_flag(this.to_reach_int) + "}");
} public native String get_flag(int paramInt); protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(2130968601);
((Button)findViewById(2131492950)).setClickable(false);#第二个setClickable
this.has_gone_int = 0;
paramBundle = new Random();
for (this.to_reach_int = paramBundle.nextInt();; this.to_reach_int = paramBundle.nextInt())
{
if (this.to_reach_int < 0) {
this.to_reach_int *= -1;
}
if (5 < this.to_reach_int)
{
this.to_reach_int %= 32;
this.to_reach_int *= 16384;
((TextView)findViewById(2131492947)).setText("" + this.to_reach_int);
((TextView)findViewById(2131492951)).setText("");
return;
}
}
}
}
可以看到有这样一段:
结合之前的分析,可以推测该段代码的作用即为当 以爬的楼层(has_gone_int) 大于 要爬的楼层(to_reach_int) 时,设置 爬到了,看FLAG 按钮的属性为 可以点击的(setClickable) ,于此对应的还有:
于是我们可以设想修改 setClickable的属性永为ture ,这样就不用管 以爬的楼层(has_gone_int) 是否大于了 要爬的楼层(to_reach_int)
步骤:
先用APKTOOL BOX反编译apk:
打开反编译后的文件夹, 删除整个unknown文件夹 (听学长说这个和之后生成apk之后的签名有关),在 CFF 100\CFF 100\smali\com\ctf\test\ctf_100 中找到 MainActivity.smali ,即为MainActivity函数的smali
smali之于java就如同汇编之于C语言,因此我们只需要修改smali就可以修改app
用记事本打开,搜索关键字 setClickable ,找到了两处,刚好和java代码中的两处对应:
对比两处,推测V5和V3即为true或false的标记位,第一张图中的v3又永为0x1,因此只需要修改v5为1,找到V5的定义部分,修改其为0x1
保存,整个文件夹拖到APKTOOL BOX中,回编译APK
安装APK,会发现修改已经完成了,无论楼层是多少都可以直接拿到flag
于是flag即为 268796A5E68A25A1
需要先卸载没修改的程序才能安装修改后的程序,否则会报错
附一片smali的学习连接http://blog.csdn.net/u012573920/article/details/44034397







