【Android 逆向】【攻防世界】Ph0en1x-100

android,逆向,攻防,世界,ph0en1x · 浏览次数 : 33

小编点评

The code you provided is an example of a mobile application cracking an encrypted APK. It uses the Java Native Interface (JNI) to interact with the native code of the APK. **Here's a summary of what the code does:** 1. **APK Installation:** The APK is installed on the phone. 2. **Flag Retrieval:** - The code retrieves the flag from the APK using the `getFlag()` method. - The `getFlag()` method uses the `encrypt()` method to encrypt the flag and then compares the encrypted flag to the original flag. 3. **Result Display:** - If the flags match, a success message is displayed. - If the flags don't match, a failed message is displayed. **Key Concepts:** - **JNI:** The code uses the JNI to interact with the native code of the APK. - **Native Methods:** The `encrypt()` and `getFlag()` methods are native methods that perform the encryption and flag retrieval operations. - **Key Transformation:** The key is transformed to a different encoding using the `encrypt()` method. - **Regular Expression:** The code uses a regular expression to extract the flag from the encrypted key. **Output:** The code will display a success message if the flags match, and a failed message if they don't match. **Note:** This code is illegal and should not be used for malicious purposes.

正文

1. apk 安装到手机,老套路需要输入flag

2. jadx 打开apk,没有加壳

......
    public void onGoClick(View v) {
        String sInput = this.etFlag.getText().toString();
        if (getSecret(getFlag()).equals(getSecret(encrypt(sInput)))) {
            Toast.makeText(this, "Success", 1).show();
        } else {
            Toast.makeText(this, "Failed", 1).show();
        }
    }
......

从这里可以看出 getFlag() 应该是等于 encrypt(sInput) ,那么getSecret只是干扰项就不用看了
这两个方法是native方法, 先用objection 看一下 getFlag返回的是什么

com.ph0en1x.android_crackme on (xiaomi: 8.1.0) [usb] # android hooking watch class_method com.ph0en1x.andr
oid_crackme.MainActivity.getFlag --dump-return
(agent) Attempting to watch class com.ph0en1x.android_crackme.MainActivity and method getFlag.
(agent) Hooking com.ph0en1x.android_crackme.MainActivity.getFlag()
(agent) Registering job 0003115686069. Type: watch-method for: com.ph0en1x.android_crackme.MainActivity.getFlag                                                                                                     
com.ph0en1x.android_crackme on (xiaomi: 8.1.0) [usb] # (agent) [0003115686069] Called com.ph0en1x.android_crackme.MainActivity.getFlag()
(agent) [0003115686069] Return Value: "ek`fz@q2^x/t^fn0mF^6/^rb`qanqntfg^E`hq|"

# 那么知道getFlag 返回的是"ek`fz@q2^x/t^fn0mF^6/^rb`qanqntfg^E`hq|"

3. IDA 打开so 看看 encrypt

jstring __fastcall Java_com_ph0en1x_android_1crackme_MainActivity_encrypt(JNIEnv *env, jobject obj, jstring key)
{
  const char *key_chars; // r4
  const char *i; // r5

  key_chars = (*env)->GetStringUTFChars(env, key, 0);
  for ( i = key_chars; i - key_chars < strlen(key_chars); ++i )
    --*i;
  return (*env)->NewStringUTF(env, key_chars);
}

分析可知, 加密算法位相当于每个字符都减一的字符

4. 写出还原算法

key = 'ek`fz@q2^x/t^fn0mF^6/^rb`qanqntfg^E`hq|'

ret = ''
for char in key:
    tmp = ord(char)
    print(tmp)
    tmp += 1
    t_char = chr(tmp)
    ret += t_char

print(ret)

#日志
flag{Ar3_y0u_go1nG_70_scarborough_Fair}

成功获得flag

与【Android 逆向】【攻防世界】Ph0en1x-100相似的内容:

【Android 逆向】【攻防世界】Ph0en1x-100

1. apk 安装到手机,老套路需要输入flag 2. jadx 打开apk,没有加壳 ...... public void onGoClick(View v) { String sInput = this.etFlag.getText().toString(); if (getSecret(get

【Android 逆向】【攻防世界】基础android

1. 下载并安装apk,提示要输入密码 2. apk拖入到jadx中看一下 this.login.setOnClickListener(new View.OnClickListener() { // from class: com.example.test.ctf02.MainActivity.1

【Android 逆向】【攻防世界】android2.0

这是一道纯算法还原题 1. apk安装到手机,提示输入flag,看来输入就是flag 2. jadx 打开apk查看 this.button.setOnClickListener(new View.OnClickListener() { // from class: com.example.test

【Android 逆向】【攻防世界】APK逆向

1. apk安装到手机,提示输入flag 2. jadx打开apk 定位到checkSN方法 public boolean checkSN(String userName, String sn) { if (userName != null) { try { if (userName.length(

【Android 逆向】【攻防世界】人民的名义-抓捕赵德汉1-200

1. 这一题下载下来是个jar文件,感觉很android关系不大,但还是放在了mobile这个分类下了 2. 直接java jar运行,提示需要输入密码 # java -jar 169e139f152e45d5ae634223fe53e6be.jar Enter password: 1234 Inc

【Android 逆向】【攻防世界】ill-intentions

1. apk 安装到手机, 啥输入框都没有 2. apk拖入到jadx中看看 public class MainActivity extends Activity { @Override // android.app.Activity public void onCreate(Bundle save

【Android 逆向】【攻防世界】boomshakalaka-3

1. apk 安装到手机,是一个cocos2dx 写的打飞机的游戏 题目描述跟得分有关(题目描述: play the game, get the highest score) 2. jadx 打开apk public class FirstTest extends Cocos2dxActivity

【Android 逆向】【攻防世界】easy-apk

apk 安装到手机,随便输入点内容,提示错误 2. apk 拖入到jadx中看看 public class MainActivity extends AppCompatActivity { /* JADX INFO: Access modifiers changed from: protected

【Android 逆向】【攻防世界】app1

1. apk安装到手机, 老套路了 2. jadx打开 this.btn.setOnClickListener(new View.OnClickListener() { // from class: com.example.yaphetshan.tencentgreat.MainActivity.1

【Android 逆向】【攻防世界】app2

1. 手机安装apk,随便点击,进入到第二个页面就停了 2. jadx打开apk,发现一共有三个activity,其中第三个activity: FileDataActivity 里面有东西 public class FileDataActivity extends a { private TextV