Exploit database

GH-15c5bc82a645186235e570cbaed15511

rxinnotrstar/cve-2019-2215-formipad4-new-gui

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2019-2215

37 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files24

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

app/src/main/java/rxi/root/the/mipad4/cve20192215/core/SuChannel.java

Java · 9,941 bytes
package rxi.root.the.mipad4.cve20192215.core;

import android.content.Context;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

/**
 * SU 通道:探测、跑命令、导出诊断。
 *
 * 为什么单独一个类(2026-11-09):
 * 界面要回答两个不同的问题——「有没有 root」和「SU 还能不能干活」。
 * 前者看文件与探测结果就够,很便宜;后者必须真的执行一次 su -c id,较慢。
 * 两者混在一起,界面每秒刷新时就会反复起进程。
 *
 * 所有方法都不抛异常,失败用返回值表达。
 */
public final class SuChannel {

    /** 通道状态。level 是给界面用的三档。 */
    public static final class Status {
        public static final int LEVEL_NONE = 0;      // 没有 SU
        public static final int LEVEL_HALF = 1;      // 部署过但通道异常
        public static final int LEVEL_OK = 2;        // 可用

        public int level = LEVEL_NONE;
        public boolean suBinary;
        public boolean daemonsu;
        public boolean magisk;
        public String detail = "";
    }

    /** 一次命令执行的结果。 */
    public static final class Result {
        public int rc = -1;
        public String output = "";
        public long elapsedMs;
        public boolean timedOut;
    }

    private SuChannel() {
    }

    /**
     * 快速判据,不执行任何命令。界面每秒调它没有负担。
     * 注意:这只是「看起来有」,真正的可用性要用 authCheck。
     */
    public static Status status() {
        Status s = new Status();
        s.suBinary = RootProbe.suBinaryExists();
        s.daemonsu = RootProbe.superSuChannelPresent();
        s.magisk = new java.io.File("/sbin/magisk").exists()
                || new java.io.File("/debug_ramdisk/magisk").exists();
        if (s.suBinary && (s.daemonsu || s.magisk)) {
            s.level = Status.LEVEL_OK;
            s.detail = s.magisk ? "Magisk 通道已就绪" : "SuperSU 通道已就绪";
        } else if (s.suBinary || s.daemonsu || s.magisk) {
            s.level = Status.LEVEL_HALF;
            s.detail = s.suBinary ? "有 su 但守护进程不在" : "守护进程在但 su 不可见";
        } else {
            s.level = Status.LEVEL_NONE;
            s.detail = "尚未部署 root";
        }
        return s;
    }

    /**
     * 真跑一次 su -c id。要在后台线程调用,最长等 8 秒。
     *
     * 判据是输出里的 uid=0 而不是退出码:被 SuperSU 拒绝时 su 也常常返回 0,
     * 只是随后打印 denied。这一点 0.62 那次吃过亏。
     */
    public static Result authCheck(Context c) {
        return run("id", 8000);
    }

    public static boolean isAuthorized(Result r) {
        if (r == null) return false;
        return r.rc == 0 && r.output != null && r.output.contains("uid=0");
    }

    /** 执行一条 shell 命令。命令由 /sbin/su -c 跑,所以是 root 身份。 */
    public static Result run(String command, long timeoutMs) {
        Result r = new Result();
        long t0 = System.currentTimeMillis();
        Process p = null;
        try {
            p = new ProcessBuilder("/sbin/su", "-c", command)
                    .redirectErrorStream(true).start();
            final StringBuilder sb = new StringBuilder();
            final Process fp = p;
            Thread reader = new Thread(() -> {
                try (BufferedReader br = new BufferedReader(
                        new InputStreamReader(fp.getInputStream(), StandardCharsets.UTF_8))) {
                    String line;
                    while ((line = br.readLine()) != null) {
                        sb.append(line).append('\n');
                        if (sb.length() > 256 * 1024) break;
                    }
                } catch (Throwable ignored) {
                }
            }, "su-read");
            reader.start();
            boolean done = p.waitFor(timeoutMs, java.util.concurrent.TimeUnit.MILLISECONDS);
            r.timedOut = !done;
            if (!done) {
                try { p.destroy(); } catch (Throwable ignored) { }
            }
            reader.join(1500);
            r.rc = done ? p.exitValue() : -1;
            r.output = sb.toString().trim();
        } catch (Throwable t) {
            r.rc = -1;
            r.output = "执行失败:" + t;
        } finally {
            r.elapsedMs = System.currentTimeMillis() - t0;
            if (p != null) {
                try { p.destroy(); } catch (Throwable ignored) { }
            }
        }
        return r;
    }

    /**
     * 带标准输入的执行。用于把一大段文本直接灌给 su,不经过任何临时文件。
     *
     * 为什么需要它(2026-11-09):把快照写到 App 私有目录再让 App 读,
     * 走不通——root 建的文件 SELinux 标签缺 c512,c768 类别,App 打开被拒。
     * 走管道则完全不涉及文件属性。
     */
    public static Result runWithInput(String command, String input, long timeoutMs) {
        Result r = new Result();
        long t0 = System.currentTimeMillis();
        Process p = null;
        try {
            p = new ProcessBuilder("/sbin/su", "-c", command)
                    .redirectErrorStream(true).start();
            final StringBuilder sb = new StringBuilder();
            final Process fp = p;
            Thread reader = new Thread(() -> {
                try (BufferedReader br = new BufferedReader(
                        new InputStreamReader(fp.getInputStream(), StandardCharsets.UTF_8))) {
                    String line;
                    while ((line = br.readLine()) != null) {
                        sb.append(line).append('\n');
                        if (sb.length() > 512 * 1024) break;
                    }
                } catch (Throwable ignored) {
                }
            }, "su-read-in");
            reader.start();
            try (java.io.OutputStreamWriter w = new java.io.OutputStreamWriter(
                    p.getOutputStream(), StandardCharsets.UTF_8)) {
                w.write(input == null ? "" : input);
                w.flush();
            } catch (Throwable t) {
                android.util.Log.i("SuChannel", "stdin write failed: " + t);
            }
            boolean done = p.waitFor(timeoutMs, java.util.concurrent.TimeUnit.MILLISECONDS);
            r.timedOut = !done;
            if (!done) {
                try { p.destroy(); } catch (Throwable ignored) { }
            }
            reader.join(1500);
            r.rc = done ? p.exitValue() : -1;
            r.output = sb.toString().trim();
        } catch (Throwable t) {
            r.rc = -1;
            r.output = "执行失败:" + t;
        } finally {
            r.elapsedMs = System.currentTimeMillis() - t0;
            if (p != null) {
                try { p.destroy(); } catch (Throwable ignored) { }
            }
        }
        return r;
    }

    /**
     * 导出 SuperSU 的授权库与配置,给开发者分析用。
     *
     * 为什么要这么做:逐应用预授权必须往它的库里写记录,而库的结构在 APK 里查不到
     * (扫过 classes.dex 与 daemonsu,只有 su_access / su_code 这套广播协议,没有 SQL)。
     * 与其猜字段,不如把真库原样拷出来看一次。
     *
     * 原生落点 /data/local/tmp/supersu_dump/,界面会再复制一份到
     * /sdcard/Android/data/<包名>/files/dump/ 供用户直接查看。含:
     *   ls.txt       两个目录的文件清单
     *   prefs.xml    shared_prefs 全文
     *   *.db         数据库原文件(原样拷贝,proot 里能用 python 打开)
     */
    public static File dumpSuperSu(Context c) {
        /* 上一次的失败原因(01:14 日志):
         *   sush: can't create .../dump.txt: No such file or directory
         * 根因是重定向本身在 mkdir 之前发生——`( ... ) > /path/file` 在子 shell 启动时就打开目标,
         * 目录还不存在就直接失败,整段命令一行都没跑。
         *
         * 现在改成:先在重定向之外建目录,再进子 shell 写文件。
         * 落点也从 /sdcard 换成 /data/local/tmp:su 进程的挂载命名空间里 /sdcard 是否可写不可靠,
         * 而 /data/local/tmp 是 root 一定可写的,shell 身份也能读,方便后续搬运。 */
        String dir = "/data/local/tmp/supersu_dump";
        String script =
                "mkdir -p " + dir + "\n"
                + "chmod 777 " + dir + "\n"
                + "if [ ! -d " + dir + " ]; then echo 'MKDIR_FAILED' > /data/local/tmp/supersu_dump_err.txt; chmod 666 /data/local/tmp/supersu_dump_err.txt; exit 9; fi\n"
                + "( set -x\n"
                + "echo '== id =='; id\n"
                + "echo '== dir =='; ls -la /data/data/eu.chainfire.supersu\n"
                + "echo '== databases =='; ls -la /data/data/eu.chainfire.supersu/databases\n"
                + "echo '== shared_prefs =='; ls -la /data/data/eu.chainfire.supersu/shared_prefs\n"
                + "echo '== copy db =='\n"
                + "for f in /data/data/eu.chainfire.supersu/databases/*; do cp -f \"$f\" " + dir + "/ ; done\n"
                + "echo '== copy prefs =='\n"
                + "for f in /data/data/eu.chainfire.supersu/shared_prefs/*; do cp -f \"$f\" " + dir + "/ ; done\n"
                + "echo '== done =='\n"
                + ") > " + dir + "/dump.txt 2>&1\n"
                + "echo \"RC=$?\" >> " + dir + "/dump.txt\n"
                + "chmod -R 777 " + dir + "\n";
        Result r = run(script, 25000);
        android.util.Log.i("SuChannel", "dump rc=" + r.rc + " out=" + r.output);
        return new File(dir + "/dump.txt");
    }
}