ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [์•ˆ๋“œ๋กœ์ด๋“œ ๋ฆฌ๋ฒ„์‹ฑ] ์ฝ”๋“œ์—”์ง„ (CodeEngn) Mobile App 01 ๋ฒˆ
    SECURITY/Android Reversing 2022. 2. 9. 16:15


    CodeEngn ์— Moblie App ๊ด€๋ จ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์„œ, ์ด๋ฅผ ํ’€์–ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

    ๋‹ค์Œ ๋งํฌ์—์„œ ๋ฌธ์ œ ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. (https://ch.codeengn.com/)

     

     

    ์••์ถ•์„ ํ’€ ๋•Œ๋Š” ๋ฌธ์ œ์— ์จ์žˆ๋Š” ๋Œ€๋กœ, File Password (codeengn) ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

     

     

    ์••์ถ•์„ ํ’€๋ฉด apk ํŒŒ์ผ์ด ํ•˜๋‚˜ ๋‚˜์˜จ๋‹ค.

    ๋จผ์ € ์ด apk ๋ฅผ emulator ์— ์„ค์น˜ํ•ด๋ณด์•„์•ผ๊ฒ ๋‹ค.

     

    ์ฐธ๊ณ ๋กœ, emulator ๋ฅผ shell ์—์„œ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š”๋ฐ, ๋จผ์ € emulator ํ”„๋กœ๊ทธ๋žจ์„ ์ฐพ์•„์•ผ ํ•œ๋‹ค.

    ๋‚˜์˜ ๊ฒฝ์šฐ \AppData\Local\Android\Sdk\emulator ์— ์žˆ์—ˆ๊ณ , ๋‹ค์Œ ์นœ๊ตฌ๋ฅผ ์ฐพ์œผ๋ฉด ๋œ๋‹ค.

     

     

    ํ•ด๋‹น ํด๋”์˜ ๊ฒฝ๋กœ์—์„œ ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋กœ emulator ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณด๊ณ  ํŠน์ • emulator ๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

    $ emulator -list-avds
    $ emulator -avd Nexus_5X_API_28

     

    ์ด์ œ ์‹คํ–‰๋œ ์—๋ฎฌ๋ ˆ์ดํ„ฐ์— ์ € apk ๋ฅผ ๊น”์•„๋ณด์ž.

    apk ๋Š” ๋“œ๋ž˜๊ทธ-๋“œ๋กญ์œผ๋กœ ์—๋ฎฌ๋ ˆ์ดํ„ฐ์— ๊น” ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด apk ๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฟœ๋Š”๋‹ค.

     

     

    ์Œ.. ์ผ๋‹จ jadx ๋กœ apk ๋ฅผ ๋””์ปดํŒŒ์ผ ํ•ด๋ณด์•˜๋‹ค.

     

    Security ๋กœ ์–ด๋–ค string ์„ ๋ณตํ˜ธํ™”ํ•˜๋Š”๋ฐ, ์ด๋ฅผ ์ถœ๋ ฅํ•ด์ฃผ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

    apk ๋งŒ ์‹คํ–‰์‹œํ‚ค๋ฉด ์ด๋ฅผ ๋ฐ”๋กœ ๋ณผ ์ˆ˜ ์žˆ์„ํ…๋ฐ, Security ์†Œ์Šค๋ฅผ ๋ณด๊ณ  ๋ณตํ˜ธํ™” ํ•ด๋ด์•ผ๊ฒ ๋‹ค.

     

    ์ญ‰ ๋ณด๋‹ˆ key ๊ฐ€ 128bit ์ด๊ณ , 16 byte ๋ฅผ ์œ„ํ•œ padding ์„ ์ฃผ๊ณ  iv ๋ฅผ ๋„ฃ์–ด์ฃผ๋Š” ๊ฒƒ์„ ๋ณด์•„ํ•˜๋‹ˆ

    AES-128 ๋กœ ์•”๋ณตํ˜ธํ™”๋ฅผ ํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค. (mode ๋Š” CBC?)

     

    python ์—์„œ Crypto ๋กœ AES-128 ์•”๋ณตํ˜ธํ™”๋ฅผ ์ ์šฉํ•ด ๋ณด์•˜๋Š”๋ฐ, ๊ฒฐ๊ณผ๊ฐ€ ์ด์ƒํ•˜๊ฒŒ ๋‚˜์˜ค๋Š” ๊ฑธ๋กœ ๋ด์„œ๋Š” KISA ๋ž‘ ์ข€ ๋‹ค๋ฅธ ๋ฐฉ์‹์ธ๊ฐ€๋ณด๋‹ค.

     

     

    ๊ทธ๋ž˜์„œ KISA ์—์„œ ์ œ๊ณตํ•˜๋Š” ์•”ํ˜ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜๋„ ๋œฏ์–ด๋ณด์•˜๋‹ค.

    KISA ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์†Œ์Šค๋ฅผ ์ œ๊ณตํ•ด์„œ, JAVA ์†Œ์Šค๋ฅผ ์ด์šฉํ•ด์„œ ํ•ด๋‹น ์•”ํ˜ธ๋ฌธ์˜ ๋ณตํ˜ธํ™”๋ฅผ ์ˆ˜ํ–‰ํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.

     

    https://seed.kisa.or.kr/kisa/Board/17/detailView.do

     

    ์†Œ์Šค ํŒŒ์ผ์— JAVA ์ฝ”๋“œ๋กœ CBC ๋‚ด์šฉ์ด ์žˆ๋‹ค.

    // KISA_SEED_CBC.java
    public static byte[] SEED_CBC_Encrypt( byte[] pbszUserKey, byte[] pbszIV, byte[] message, int message_offset, int message_length ) { ... }
    public static byte[] SEED_CBC_Decrypt( byte[] pbszUserKey, byte[] pbszIV, byte[] message, int message_offset, int message_length ) { ... }

     

    ์ด ๋‘ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณตํ˜ธํ™”๋ฅผ ํ•ด๋ณผ ๊ฒƒ์ด๋‹ค.

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด apk ๋ฅผ ๋””์ปดํŒŒ์ผํ•œ ์ฝ”๋“œ์—์„œ ์•”๋ณตํ˜ธํ™”๋ฅผ KISA_SEED_CBC.java ์˜ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ ์ ˆํžˆ ๋ฐ”๊ฟ”์ฃผ์—ˆ๋‹ค.

    import java.math.BigInteger;
    
    public class SimpleAppSecurity {
    	public static final byte[] key = {51, -46, 79, -113, 8, 34, 121, -15, -23, -13, -108, 55, 10, -44, 5, -119};
        public static final byte[] iv = {38, -115, 102, -89, 53, -88, 26, -127, 95, -70, -39, -6, 54, 25, 37, 19};
    
        public static String EncryptStr(String encText) {
            String encText2;
            if (encText == null || encText.equals("")) {
                encText2 = "";
            } else {
                byte[] plainText = encText.trim().getBytes();
                byte[] cipherText = KISA_SEED_CBC.SEED_CBC_Encrypt(key, iv, plainText, 0, plainText.length);
                encText2 = new String(new BigInteger(cipherText).toString(16));
            }
            return encText2.trim();
        }
    
        public static String DecryptStr(String decText) {
            if (decText == null || decText.equals("")) {
                return "";
            }
            byte[] cipherText = new BigInteger(decText.trim(), 16).toByteArray();
            byte[] plainText = KISA_SEED_CBC.SEED_CBC_Decrypt(key, iv, cipherText, 0, cipherText.length);
            return new String(plainText).trim();
        }
        
        public static void main(String[] args) {
        	// DecryptStr("-1aaa755a1e60915baff1d4cb64cb221a0000000000000000000000000000");
        	String result = DecryptStr("-1aaa755a1e60915baff1d4cb64cb221a");
        	System.out.println(result);   	
    	}
    }

     

    ๊ฒฐ๊ณผ๋กœ flag ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

     

     

    ์ฃผ์˜ํ•  ์ ์€ ๋’ค์— padding ์ธ 000...000 ์€ ๋นผ๊ณ  ๋ณตํ˜ธํ™”๋ฅผ ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

     

     

    apk ๋ฅผ ๋””์ปดํŒŒ์ผํ•ด์„œ ์†Œ์Šค ๋‚ด์šฉ์„ ๋ณด๊ณ  ์•”ํ˜ธ๋ฌธ์„ ํ‘ผ ๊ฒƒ์€ ๋งž์œผ๋‚˜

    Android ๋ฌธ์ œ๋ฅผ Crypto + Code ๋Š๋‚Œ์œผ๋กœ ํ’€์–ด๋ฒ„๋ ค์„œ ์ •์„์„ ์‚ดํŽด๋ณด๋ ค๊ณ  apk ๋ฅผ ๋‹ค์‹œ ๋œฏ์–ด๋ณด์•˜๋‹ค.

     

     

    ๊ทธ๋Ÿฌ๋‹ค ํŒŒ์ผ๋“ค์„ ๋ณด๋ฉด class ๊ฐ™์ด ํŒŒ์ผ ๋ช…์ด ์ผ๋ฐ˜์ ์ธ apk ๋ž‘ ๋‹ค๋ฅธ ๊ฒƒ์„ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.

    ์ขŒ: L01 apk / ์šฐ: L02 apk

    • AndroidManIfests.xml -> AndroidManifest.xml
    • class.dex -> classes.dex
    • resource.arsc -> resources.arsc

     

    ์ด๋ ‡๊ฒŒ ๋ฐ”๊ฟ”์ฃผ๊ณ  ์••์ถ•์‹œํ‚จ ํ›„ ํ™•์žฅ์ž๋ฅผ apk ๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋œ๋‹ค.

    ์ด๊ฑธ ์—๋ฎฌ๋ ˆ์ดํ„ฐ์— ๊น”์•„์ฃผ๋ฉด ๋˜๋Š”๋ฐ ... ๊ทธ๋ž˜๋„ ์—ด๋ฆฌ์ง€ ์•Š์•„์„œ ์ผ๋‹จ์€ ๋ณด๋ฅ˜ํ•˜๊ณ  ์žˆ๋‹ค.

     

    ๋Œ“๊ธ€

Designed by Tistory.