$ dex2jar-2.0\\d2j-dex2jar.bat Android-InsecureBankv2\\InsecureBankv2.apk
dex2jar로 디컴파일하여 얻은 jar 파일을 jd-gui 툴로 열면 다음과 같이 java 소스코드들을 얻을 수 있다.
암호화, 복호화 로직은 CryptoClass.class 코드에서 확인할 수 있다.
CryptoClass 코드에 있는 복호화 코드를 사용해서, superSecretPassword를 복호화해보자.
superSecretPassword의 암호화된 값은 이전에 WebView 취약점에서 얻었다.
superSecurePassword를 디코딩하는 앱을 작성해보자.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:text="AES cipherText:"/>
<TextView
android:id="@+id/cipherText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:text="PlainText:"/>
<TextView
android:id="@+id/plainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:id="@+id/decodeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Decode cipherText"
android:layout_gravity="center"/>
</LinearLayout>
MainActivity.java
package com.cookandroid.insecurebankv2_weakcrypto;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class MainActivity extends AppCompatActivity {
TextView cipherText, plainText;
Button decodeBtn;
byte[] cipherData;
String plainPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Decode superSecretPassword");
final byte[] ivBytes = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
final String key = "This is the super secret key 123";
final String superSecretPassword = "DTrW2VXjSoFdg0e61fHxJg==";
cipherText = (TextView)findViewById(R.id.cipherText);
plainText = (TextView)findViewById(R.id.plainText);
decodeBtn = (Button)findViewById(R.id.decodeButton);
decodeBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
try{
byte[] arrayOfByte = key.getBytes("UTF-8"); // unicode 문자열을 bytecode로 인코딩
cipherData = aes256decrypt(ivBytes, arrayOfByte, Base64.decode(superSecretPassword.getBytes("UTF-8"), Base64.DEFAULT));
plainPassword = new String(cipherData, "UTF-8");
}catch(UnsupportedEncodingException e){
e.printStackTrace();
}catch(InvalidKeyException e){
e.printStackTrace();
}catch(NoSuchAlgorithmException e) {
e.printStackTrace();
}catch(NoSuchPaddingException e){
e.printStackTrace();
}catch(InvalidAlgorithmParameterException e){
e.printStackTrace();
}catch(IllegalBlockSizeException e){
e.printStackTrace();
}catch(BadPaddingException e){
e.printStackTrace();
}finally {
cipherText.setText(superSecretPassword);
plainText.setText(plainPassword);
}
}
});
}
public static byte[] aes256decrypt(byte[] paramArrayOfbyte1, byte[] paramArrayOfbyte2, byte[] paramArrayOfbyte3) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
IvParameterSpec ivParameterSpec = new IvParameterSpec(paramArrayOfbyte1);
SecretKeySpec secretKeySpec = new SecretKeySpec(paramArrayOfbyte2, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(2, secretKeySpec, ivParameterSpec);
return cipher.doFinal(paramArrayOfbyte3);
}
}
Decode 앱 실행
[Android Reversing] Sensitive Information in Memory (0) | 2021.07.06 |
---|---|
[Android Reversing] Application Patching (0) | 2021.07.06 |
[Android Reversing] Insecure Webview implementation (WebView 취약점) (0) | 2021.07.06 |
[Android Reversing] Insecure Content Provider access (Content Provider 취약점) (0) | 2021.07.06 |
Drozer 설치 (Windows) (0) | 2021.07.06 |