InjuredAndroid 1-5

2021-02-14 Tide安全團隊
一、簡述


該項目來自 Kyle B3nac ,是一名全職安全研究員、CTF出題人、漏洞賞金獵人。

該項目是一個Android application靶場,基於漏洞挖掘、漏洞利用,以CTF的形式呈現。

作者建議反編譯apk來解題,那就jadx-gui吧。

前五題難度不大,適合初學者練手。

註:FLAG已作打碼處理

Github:https://github.com/B3nac/InjuredAndroid

作者對這個項目的介紹:https://twitter.com/B3nac/status/1317185026677641218?s=20

二、writeup1、XSSTEXT

XSSTEST is just for fun and to raise awareness on how WebViews can be made vulnerable to XSS.


當前Actvity為 XSSTextActivity ,反編譯,看一下程序對輸入值的處理過程:

    public void submitText(View view) {
        Intent intent = new Intent(this, DisplayPostXSS.class);
        intent.putExtra("com.b3nac.injuredandroid.DisplayPostXSS", ((EditText) findViewById(R.id.editText)).getText().toString());
        startActivity(intent);
    }

輸入的text作為參數直接傳給 com.b3nac.injuredandroid.DisplayPostXSS

public final class DisplayPostXSS extends C0459c {
    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        WebView webView = new WebView(this);
        setContentView((View) webView);
        String stringExtra = getIntent().getStringExtra("com.b3nac.injuredandroid.DisplayPostXSS");
        WebSettings settings = webView.getSettings();
        C2646d.m10664b(settings, "vulnWebView.settings");
        settings.setJavaScriptEnabled(true); // 開啟WebView的js執行
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadData(stringExtra, "text/html", "UTF-8");
    }
}

在該段代碼中,可以得到程序新建了一個WebView,並開啟了其執行JS的能力。
在這使用最簡單的xss payload: <script>alert('xss')</script> ,即可。

這個例子簡單直觀的展示了開發者如何導致WebView存在XSS漏洞。

2、 FLAG ONE - LOGIN

輸入字符串來驗證是否為FLAG

反編譯之後,可以看到點擊Button後的處理過程,輸入的字符串直接與明文FLAG進行對比:

輸入flag:

3、 FLAG TWO - EXPORTED ACTIVTY


繞過main activity 來調用其他可導出的activities

這裡使用dorzer:

dz> run app.activity.info -a  b3nac.injuredandroid
Package: b3nac.injuredandroid
  b3nac.injuredandroid.CSPBypassActivity
    Permission: null
  b3nac.injuredandroid.RCEActivity
    Permission: null
  b3nac.injuredandroid.ExportedProtectedIntent
    Permission: null
  b3nac.injuredandroid.QXV0aA
    Permission: null
  b3nac.injuredandroid.DeepLinkActivity
    Permission: null
  b3nac.injuredandroid.MainActivity
    Permission: null
  b3nac.injuredandroid.b25lActivity
    Permission: null
  b3nac.injuredandroid.TestBroadcastReceiver
    Permission: null
  com.google.firebase.auth.internal.FederatedSignInActivity
    Permission: com.google.firebase.auth.api.gms.permission.LAUNCH_FEDERATED_SIGN_IN

依次打開可被導出的組件:

dz> run app.activity.start --component b3nac.injuredandroid  b3nac.injuredandroid.ExportedProtectedIntent
dz> run app.activity.start --component b3nac.injuredandroid  b3nac.injuredandroid.CSPBypassActivity
dz> run app.activity.start --component b3nac.injuredandroid  b3nac.injuredandroid.QXV0aA
dz> run app.activity.start --component b3nac.injuredandroid  b3nac.injuredandroid.b25lActivity //this one 

4、FLAG THERE - RESOURCES


看一下Button被觸發後的處理流程:

    public final void submitFlag(View view) {
        EditText editText = (EditText) findViewById(R.id.editText2);
        C2646d.m10664b(editText, "editText2");
        if (C2646d.m10663a(editText.getText().toString(), getString(R.string.cmVzb3VyY2VzX3lv))) { // 對比
            Intent intent = new Intent(this, FlagOneSuccess.class);
            new FlagsOverview().mo6178L(true);
            new C1464j().mo6221b(this, "flagThreeButtonColor", true);
            startActivity(intent);
        }
    }

在這,使用apktool來反編譯apk

apktool d InjuredAndroid-1.0.10-release.apk -o injured

在values/strings可以看到cmVzb3VyY2VzX3lv的值:
輸入flag:

5、FLAG FOUR - LOGIN2

依然是輸入flag,進行驗證:

分析觸發Button時的處理邏輯:

    public final void submitFlag(View view) {
        EditText editText = (EditText) findViewById(R.id.editText2);
        C2646d.m10664b(editText, "editText2");
        String obj = editText.getText().toString(); //獲取輸入
        byte[] a = new C1461g().mo6220a();
        C2646d.m10664b(a, "decoder.getData()");
        if (C2646d.m10663a(obj, new String(a, C2672c.f6838a))) { // compare
            Intent intent = new Intent(this, FlagOneSuccess.class);
            new FlagsOverview().mo6175I(true);
            new C1464j().mo6221b(this, "flagFourButtonColor", true); 
            startActivity(intent);
        }
    }


依次分析

       byte[] a = new C1461g().mo6220a(); 

package b3nac.injuredandroid;

import android.util.Base64;

/* renamed from: b3nac.injuredandroid.g */
public class C1461g {

    /* renamed from: a */
    private byte[] f4478a = Base64.decode("NF9vdmVyZG9uZV9vbWVsZXRz", 0);
    //Base64.decode("NF9vdmVyZG9uZV9vbWVsZXRz", DEFAULT);  自行decode 得到flag

    /* renamed from: a */
    public byte[] mo6220a() {
        return this.f4478a;
    }
}

可得:a = Base64.decode("NF9vdmVyZG9uZV9vbWVsZXRz", 0); 

if函數的條件

C2646d.m10663a(obj, new String(a, C2672c.f6838a)) //比對obj(即輸入)和a的值

分析 C2672c.f6838a 函數

        Charset forName = Charset.forName("UTF-8");
        C2646d.m10666d(forName, "Charset.forName(\"UTF-8\")");
        f6838a = forName;

所以該函數可以簡化為:

C2646d.m10663a(obj, new String(a, "UTF-8")) //compare

輸入flag

三、Overview

整個靶場共18項,flag項共17個。

相關焦點