Jarvis OJ reverse之androideasy wp

这是一道我第一次解出的安卓逆向类CTF题目,下面记录并分享一下思路。

一,把文件下载下来,打开是一个apk文件,用jeb反编译(找到MainAcitivity,然后右键Decompile即可)得到java代码。

package com.a.sample.androidtest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View$OnClickListener;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private EditText editText;
    private byte[] s;

    public MainActivity() {
        super();
        this.s = new byte[]{113, 123, 118, 112, 108, 94, 99, 72, 38, 68, 72, 87, 89,
		72, 36, 118, 100, 78, 72, 87, 121, 83, 101, 39, 62, 94, 62, 38, 107, 115, 106};
    }

    public boolean check() {
        boolean v2 = false;
        byte[] v0 = this.editText.getText().toString().getBytes();
        if(v0.length == this.s.length) {
            int v1 = 0;
            while(v1 < this.s.length) {
                if(v1 >= v0.length) {
                    break;
                }

                if(this.s[v1] == (v0[v1] ^ 23)) {
                    ++v1;
                    continue;
                }
                else {
                    return v2;
                }
            }

            v2 = true;
        }

        return v2;
    }

    protected void onCreate(Bundle arg4) {
        super.onCreate(arg4);
        this.setContentView(2130968603);
        this.editText = this.findViewById(2131427415);
        this.findViewById(2131427416).setOnClickListener(new View$OnClickListener(this) {
            public void onClick(View arg4) {
                if(MainActivity.this.check()) {
                    Toast.makeText(this.val$context, "You got the flag!", 1).show();
                }
                else {
                    Toast.makeText(this.val$context, "Sorry your flag is wrong", 1).show();
                }
            }
        });
    }
}

二,分析代码。

这里调用了很多安卓类,会给一开始的我造成一些压力困扰。但我们只关心主要算法部分就行,onCreate的作用是判定传给check()的是True还是False,True则得到flag。回到check(),要想返回True,则要执行if内的语句,^是一个异或运算,显而易见,该部分是说 数组s里的每个数值v0中的每个数与23进行异或运算后的数值相等。v0就是我们要求的flag的数字表示。通过写个脚本逆着来就ok了。

脚本如下

s=[113, 123, 118, 112, 108, 94, 99, 72, 38, 68, 72, 87, 89,
72, 36, 118, 100, 78, 72, 87, 121, 83, 101, 39, 62, 94, 62,
38, 107, 115, 106]
length=len(s)
print(length)
key=[]
flag=''
for i in range(length):
    key.append(s[i]^23)
for j in range(length):
    flag+=chr(key[j])
print(flag)

猜你喜欢

转载自blog.csdn.net/XiangLanLee/article/details/84135240