writeups by ch4nsec

[CodeEngn] Mobile L01 풀이

CodeEngn wargame Mobile L01 문제 풀이

#wargame#codeengn#mobile#android

CodeEngn Challenge에 등록되어 있는 모바일 L01 문제이다.

사용도구

jadx-gui, bluestack

풀이

codeengn_mobile_l01_1

일단 설치가 되지 않는다

AndroidManifest.xml을 못찾았다고 한다.

jadx를 이용해 디컴파일을 시도하여 뭐가 문제인지 확인해보았다.

codeengn_mobile_l01_2

있는데?

아..

codeengn_mobile_l01_3

이름에 장난질을 해놨다.

일단 이름을 수정해야 할 것 같다.

다른 파일도 이름이 조금씩 다르다.

codeengn_mobile_l01_4
Mobile L01
codeengn_mobile_l01_5
다른 apk 파일(정상)

일단 이름을 제대로 수정하고 다시 설치를 시도해보기로 하자.

AndroidManlfests.xml -> AndroidManifest.xml

class.dex -> classes.dex

resource.arsc -> resources.arsc

(파일 이름 변경은 그냥 apk 사본 따서 apk->zip으로 이름 수정 후 압축 해제하여 진행하였다. 이후 다시 압축하여 apk로 변환)

codeengn_mobile_l01_6

zipalign -p -f -v 4 ./mod.apk patched.apk

codeengn_mobile_l01_7

apksigner sign --ks .\keystore.jks --ks-pass pass:[password] patched.apk

codeengn_mobile_l01_8
오류는 그냥 무시해도 되더라.

adb install -r .\patched.apk

그러면 이렇게 성공적으로 FindKey1이라는 앱이 설치가 된다.

codeengn_mobile_l01_9
codeengn_mobile_l01_10
끝..?

뭐야 끝이네?

정말 더 없나 싶어서 jadx를 활용해 디컴파일을 시도해보았다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
    android:versionName="1.0"
    package="com.namdaehyeon.findkey1">
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17"/>
    <application
        android:theme="@style/AppTheme"
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:allowBackup="true">
        <activity
            android:label="@string/app_name"
            android:name="com.namdaehyeon.findkey1.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

일단 MainActivity 외에는 뭐가 없는 듯하다.

package com.namdaehyeon.findkey1;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/* loaded from: classes.dex */
public class MainActivity extends Activity {
    TextView aView;
    TextView bView;
    Button button;
    Button button2;
    TextView cView;

    @Override // android.app.Activity
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }

    @Override // android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public String myString() {
        Log.v("APKLOG", String.format("LOGLOG %s", "codeengn.com"));
        return "codeengn.com";
    }

    public void addListenerOnButton() {
        this.button = (Button) findViewById(R.id.button1);
        this.button.setOnClickListener(new View.OnClickListener() { // from class: com.namdaehyeon.findkey1.MainActivity.1
            @Override // android.view.View.OnClickListener
            public void onClick(View arg0) {
                AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
                alert.setPositiveButton("close", new DialogInterface.OnClickListener() { // from class: com.namdaehyeon.findkey1.MainActivity.1.1
                    @Override // android.content.DialogInterface.OnClickListener
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                alert.setTitle("Key");
                alert.setMessage(Security.DecryptStr("-1aaa755a1e60915baff1d4cb64cb221a0000000000000000000000000000"));
                alert.show();
            }
        });
    }
}

앱을 키면 버튼이 하나 나오고, 버튼을 누르면 어떤 문자열이 복호화되어 표시된다 라는 로직이다.

저게 flag가 맞나보다.

문제의 핵심은 apk의 필수 구성 요소가 없으면 작동하지 않는다는 점이라고 볼 수 있었다.

classes.dex라든가 resources.arsc라든가. 그리고 앱의 구조를 정의하고 있는 가장 중요한 AndroidManifest.xml까지.