Exploit databaseDownload repository ZIP
GH-938716d7bb21279aed0a36a8553e75d3
wangs-official/opace6-cve-2026-64560
Sources for CVE-2026-64560
19 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files5
wangs-official/opace6-cve-2026-64560Revision 4558a3322bc6
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
tools/kallsyms_extract.py
Python · 8,698 bytes#!/usr/bin/env python3
"""Extract the kernel symbol table (kallsyms) from a raw uncompressed arm64 Image.
The tool is deliberately self-validating: every structure it uses is located by
fingerprint and then cross-checked against an independent structure, so a wrong
guess aborts instead of silently producing bogus addresses.
Validated against OnePlus 13 `6.6.118-android15-8-g9bc34d5b0c79-abogki537459655-4k`:
kallsyms_num_syms u32 count
kallsyms_names u8 len + u8 token indices, one record per symbol
kallsyms_markers u32 name-offset for every 256th symbol
kallsyms_token_table 256 NUL-terminated fragments
kallsyms_token_index u16 offsets into the token table
kallsyms_offsets u32 address delta from kallsyms_relative_base
kallsyms_relative_base u64 kernel image virtual base
Usage:
python tools/kallsyms_extract.py scratch/Image --json scratch/symbols.json
"""
from __future__ import annotations
import argparse
import hashlib
import json
import struct
from pathlib import Path
MAX_TOKEN_LEN = 64
MIN_RECORD_LEN = 1
MAX_RECORD_LEN = 120
def u16(data: bytes, off: int) -> int:
return struct.unpack_from("<H", data, off)[0]
def u32(data: bytes, off: int) -> int:
return struct.unpack_from("<I", data, off)[0]
def u64(data: bytes, off: int) -> int:
return struct.unpack_from("<Q", data, off)[0]
class KallsymsError(RuntimeError):
pass
def find_longest_ascending_u32(data: bytes, limit: int) -> tuple[int, int]:
"""Return (start, count) of the longest ascending u32 run below `limit`."""
best = (0, 0)
n = len(data) // 4
i = 0
while i < n:
v = u32(data, i * 4)
if v < limit:
j = i + 1
last = v
while j < n:
w = u32(data, j * 4)
if w < last or w >= limit:
break
last = w
j += 1
if j - i > best[1]:
best = (i * 4, j - i)
i = j
else:
i += 1
if best[1] < 1000:
raise KallsymsError("no kallsyms_offsets candidate found")
return best
def find_token_table(data: bytes, start_hint: int) -> int:
"""Locate kallsyms_token_table: exactly 256 consecutive NUL-terminated strings."""
search_from = max(0, start_hint - 8 * 1024 * 1024)
pos = search_from
total = len(data)
# Split the whole file on NUL and rebuild offsets; cheap enough and exact.
segments = data.split(b"\x00")
offsets: list[int] = []
p = 0
for s in segments:
offsets.append(p)
p += len(s) + 1
def acceptable(s: bytes) -> bool:
return 1 <= len(s) <= MAX_TOKEN_LEN and all(0x20 <= c < 0x7F for c in s)
i = 0
n = len(segments)
while i < n:
if offsets[i] < search_from:
i += 1
continue
if acceptable(segments[i]):
j = i
while j < n and acceptable(segments[j]):
j += 1
if j - i == 256:
return offsets[i]
i = j
else:
i += 1
raise KallsymsError("no kallsyms_token_table candidate found")
def read_tokens(data: bytes, table: int, count: int = 256) -> list[bytes]:
tokens: list[bytes] = []
p = table
for _ in range(count):
end = data.find(b"\x00", p)
if end < 0:
raise KallsymsError("truncated token table")
tokens.append(data[p:end])
p = end + 1
return tokens
def find_token_index(data: bytes, tokens: list[bytes], table: int) -> int:
"""token_index[i] is the byte offset of token i inside the token table."""
offsets: list[int] = []
p = table
for tok in tokens:
offsets.append(p - table)
p += len(tok) + 1
needle = b"".join(struct.pack("<H", o) for o in offsets)
hit = data.find(needle)
if hit < 0:
raise KallsymsError("kallsyms_token_index not found")
return hit
def find_markers(data: bytes, token_table: int) -> tuple[int, list[int]]:
"""Markers are the increasing u32 array that ends where the token table starts."""
end = token_table
values: list[int] = []
p = end - 4
while p > 0:
v = u32(data, p)
values.append(v)
if v == 0:
break
p -= 4
if len(values) > 16384:
raise KallsymsError("markers scan ran away")
values.reverse()
start = end - 4 * len(values)
for i in range(1, len(values)):
if values[i] <= values[i - 1]:
raise KallsymsError("markers are not strictly increasing")
if values[0] != 0:
raise KallsymsError("markers[0] is not zero")
return start, values
def find_names_start(data: bytes, names_end: int, markers: list[int]) -> int:
"""Brute-force the names blob start, validated against every marker checkpoint."""
tail_guess = 1200
guess = names_end - (markers[-1] + tail_guess)
window = 32768
found: list[int] = []
for start in range(guess - window, guess + window):
if start < 0:
continue
off = 0
ok = True
for i in range(1, len(markers)):
p = start + off
for _ in range(256):
ln = data[p]
if ln < MIN_RECORD_LEN or ln > MAX_RECORD_LEN:
ok = False
break
p += 1 + ln
if not ok:
break
off = p - start
if off != markers[i]:
ok = False
break
if ok:
found.append(start)
if len(found) != 1:
raise KallsymsError(f"names start is ambiguous: {[hex(s) for s in found]}")
return found[0]
def decode(tokens: list[bytes], record: bytes) -> str:
out = bytearray()
for b in record:
out += tokens[b]
return out.decode("utf-8", "replace")
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("image", type=Path)
parser.add_argument("--json", type=Path, help="write {name: address} as JSON")
parser.add_argument("--limit", type=int, default=0x3000000,
help="upper bound for a kallsyms offset value")
args = parser.parse_args()
data = args.image.read_bytes()
offsets_off, num_syms = find_longest_ascending_u32(data, args.limit)
token_table = find_token_table(data, offsets_off)
tokens = read_tokens(data, token_table)
token_index = find_token_index(data, tokens, token_table)
markers_start, markers = find_markers(data, token_table)
names_start = find_names_start(data, markers_start, markers)
base = u64(data, offsets_off + 4 * num_syms + 4)
if base >> 40 != 0xFFFFFF:
raise KallsymsError(f"implausible kallsyms_relative_base {base:#x}")
symbols: list[tuple[str, str, int]] = []
p = names_start
for i in range(num_syms):
ln = data[p]
record = data[p + 1:p + 1 + ln]
p += 1 + ln
raw = decode(tokens, record)
address = base + u32(data, offsets_off + 4 * i)
# kallsyms stores the symbol type character as the first name character.
symbols.append((raw[0], raw[1:], address))
if p > markers_start:
raise KallsymsError("names blob overran the markers array")
report = {
"image": str(args.image),
"imageSha256": hashlib.sha256(data).hexdigest(),
"imageBase": f"{base:#018x}",
"numSyms": num_syms,
"layout": {
"numSyms": f"{names_start - 8:#x}",
"names": f"{names_start:#x}",
"namesEnd": f"{markers_start:#x}",
"markers": f"{markers_start:#x}",
"tokenTable": f"{token_table:#x}",
"tokenIndex": f"{token_index:#x}",
"offsets": f"{offsets_off:#x}",
"relativeBase": f"{offsets_off + 4 * num_syms + 4:#x}",
},
}
text = json.dumps(report, indent=2)
print(text)
if args.json:
args.json.parent.mkdir(parents=True, exist_ok=True)
payload = {
"image": str(args.image),
"imageSha256": hashlib.sha256(data).hexdigest(),
"imageBase": f"{base:#018x}",
"symbols": [
{"type": t, "name": n, "address": f"{a:#018x}"}
for t, n, a in symbols
],
}
args.json.write_text(json.dumps(payload), encoding="utf-8")
print(f"wrote {len(symbols)} symbols to {args.json}")
else:
for stype, name, address in symbols[:20]:
print(f"{address:#018x} {stype} {name}")
return 0
if __name__ == "__main__":
raise SystemExit(main())