Timer(阿里CTF)----bugku

打开下载看到是安卓文件,直接拿模拟器运行下看是什么东西

看起来这个程序是让我们修改文件让时间为0得到flag,或者是一直等时间得flag。接下来分析源代码
1.因为我是新手,所以一般看安卓反编译就看main类的代码

public MainActivity() {
        super();
        this.beg = (((int)(System.currentTimeMillis() / 1000))) + 200000;    ###获取当前时间,并且化整,+20万秒
        this.k = 0;        ###k值0
        this.t = 0;
}

public static boolean is2(int arg4) {    ##is2类带入抑制整型值arg4
        boolean v1 = true;    ##设置v1为1
        if(arg4 > 3) {    ##判断arg4是否大于3
            if(arg4 % 2 != 0 && arg4 % 3 != 0) {    ##arg4的2取余和arg4的3取余不等于0
                int v0 = 5;      
                while(true) {      ##必须进行的循环
                    if(v0 * v0 <= arg4) {    ##判断v0的平方是否小于或等于arg4
                        if(arg4 % v0 != 0 && arg4 % (v0 + 2) != 0) {
                            v0 += 6;
                            continue;
                        }

                        return false;
                    }
                    else {
                        return v1;
                    }
                }

                return false;
            }

            v1 = false;
        }
        else if(arg4 <= 1) {
            v1 = false;
        }

        return v1;
}

protected void onCreate(Bundle arg7) {
        super.onCreate(arg7);    ##super是指向父类的一个指针
        this.setContentView(2130968600);
        View v2 = this.findViewById(2131492944);
        View v3 = this.findViewById(2131492945);
        Handler v0 = new Handler();
        v0.postDelayed(new Runnable(((TextView)v3), ((TextView)v2), v0) {
            public void run() {
                MainActivity.this.t = System.currentTimeMillis();      ###System.currentTimeMillis获取当前系统时间
                MainActivity.this.now = ((int)(MainActivity.this.t / 1000));      ###System.currentTimeMillis获取当前系统时间的取余求秒
                MainActivity.this.t = 1500 - MainActivity.this.t % 1000;
                this.val$tv2.setText("AliCTF");
                if(MainActivity.this.beg - MainActivity.this.now <= 0) {    ##如果beg的值-当前时间,小于或等于0就能得出flag,也就是说我们要改此处让直接能够判断得出显示flag的步骤
                    this.val$tv1.setText("The flag is:");      ##从这里看出会出现flag
                    this.val$tv2.setText("alictf{" + MainActivity.this.stringFromJNI2(MainActivity.this.k) + "}");      ##获得flag与k的值有关,k为flag的内容,stringFromJNI2是一个二进制源文件,能够判断是否计算了正确的次数,所以我们知识单单改if判断是没有用的,k的计算没有算出正确的结果
                }

                if(MainActivity.is2(MainActivity.this.beg - MainActivity.this.now)) {    把beg的值-now值带入到is2中为arg4
                    MainActivity.this.k += 100;      ###k=k+100
                }
                else {
                    --MainActivity.this.k;      ##k=k-1
                }

                this.val$tv1.setText("Time Remaining(s):" + (MainActivity.this.beg - MainActivity.this.now));
                this.val$handler.postDelayed(((Runnable)this), MainActivity.this.t);    ##当t为多少毫秒的时候会调用postDelayed,持续进入循环,也就是循环200000次就能打印flag
            }
        }, 0);
    }

2.根据上面的分析,当beg的时间-new的时间=0或小于0都可以得出flag,flag的值是由k计算得来的

package test;

public class test1 {
	
	
	   public static boolean is2(int arg4) {    ##计算k值的过程
	        boolean v1 = true;
	        if(arg4 > 3) {
	            if(arg4 % 2 != 0 && arg4 % 3 != 0) {
	                int v0 = 5;
	                while(true) {
	                    if(v0 * v0 <= arg4) {
	                        if(arg4 % v0 != 0 && arg4 % (v0 + 2) != 0) {
	                            v0 += 6;
	                            continue;
	                        }

	                        return false;
	                    }
	                    else {
	                        return v1;
	                    }
	                }
	            }

	            v1 = false;
	        }
	        else if(arg4 <= 1) {
	            v1 = false;
	        }

	        return v1;
	    }
	   
		public static void main(String args[])
		{
			int time = 200000;    初始的time为200000,也就是代表beg的时间
			int k = 0;
			while(time > 0){      ###根据源文件进行修改而来的
				if(is2(time)){
					k += 100;
				}
				else
					k--;
				
				time--;
			}
			
			System.out.println(k);
		}
	   
}

3.我们计算得出k的值为

4.我们此时使用安卓aker,我们要改两处,一个是if判断,一个是直接使用的k值

此时我们拿到模拟器运行看看

5.强制赋值k


得出了flag

posted @ 2021-02-27 15:28  网抑云黑胶SVIP用户  阅读(399)  评论(0编辑  收藏  举报