Exploit database

GH-d040af49f7627d91b0e314e6400f7010

creeeeger/cve-2024-56426

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-56426

2 sources

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

Repository files13
creeeeger/cve-2024-56426Revision 3d6d94a21066

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

exploit/split.py

Python · 4,665 bytes
#!/usr/bin/env python3
import argparse
import json
import logging
import os
import sys

from soc_data import BOOTLOADER_SPLITS, SBOOT_SOC

logger = logging.getLogger("sboot_splitter")
SPLIT_MANIFEST_NAME = "split_manifest.json"
TAIL_FILENAME = "__tail__.bin"


def split_sboot(sboot_path: str, out_dir: str) -> None:
    """Extract the fixed Exynos9830 SBoot ranges and preserve its tail."""

    ranges: list[tuple[str, str, int, int]] = []
    for part_name, params in BOOTLOADER_SPLITS.items():
        start = params["start"]
        end = params["end"]
        if end <= start:
            raise RuntimeError(f"Invalid range for {part_name}: start={start}, end={end}")

        filename = part_name
        if not os.path.splitext(filename)[1]:
            filename += ".bin"

        ranges.append((part_name, filename, start, end))

    ranges.sort(key=lambda item: item[2])

    for idx in range(len(ranges) - 1):
        cur_name, _, cur_start, cur_end = ranges[idx]
        next_name, _, next_start, _ = ranges[idx + 1]
        if cur_end > next_start:
            raise RuntimeError(
                f"Overlapping ranges: {cur_name} (0x{cur_start:X}-0x{cur_end:X}) "
                f"and {next_name} (from 0x{next_start:X})"
            )

    os.makedirs(out_dir, exist_ok=True)

    source_size = os.path.getsize(sboot_path)
    max_end = max(end for _, _, _, end in ranges)
    if source_size < max_end:
        raise RuntimeError(
            f"sboot.bin is too small: file has {source_size} bytes, "
            f"but split ranges extend to 0x{max_end:X} ({max_end} bytes)."
        )

    manifest_parts: list[dict] = []

    with open(sboot_path, "rb") as sboot:
        for part_name, filename, start, end in ranges:
            size = end - start
            sboot.seek(start)
            chunk = sboot.read(size)
            if len(chunk) != size:
                raise RuntimeError(
                    f"Could not fully read {part_name}: expected {size} bytes, got {len(chunk)} bytes"
                )

            out_path = os.path.join(out_dir, filename)
            with open(out_path, "wb") as out:
                out.write(chunk)

            manifest_parts.append(
                {
                    "name": part_name,
                    "filename": filename,
                    "start": start,
                    "end": end,
                    "size": size,
                }
            )

            logger.info(
                "Written: %s (0x%X - 0x%X) => %d bytes",
                out_path, start, end, size
            )

        tail_file: str | None = None
        if source_size > max_end:
            tail_size = source_size - max_end
            sboot.seek(max_end)
            tail_data = sboot.read(tail_size)
            if len(tail_data) != tail_size:
                raise RuntimeError(
                    f"Could not fully read tail area: expected {tail_size} bytes, "
                    f"got {len(tail_data)} bytes"
                )

            tail_path = os.path.join(out_dir, TAIL_FILENAME)
            with open(tail_path, "wb") as out:
                out.write(tail_data)

            tail_file = TAIL_FILENAME
            logger.info(
                "Written: %s (0x%X - 0x%X) => %d bytes",
                tail_path, max_end, source_size, tail_size
            )

    manifest = {
        "version": 1,
        "soc": SBOOT_SOC,
        "source_size": source_size,
        "covered_end": max_end,
        "tail_file": tail_file,
        "parts": manifest_parts,
    }
    manifest_path = os.path.join(out_dir, SPLIT_MANIFEST_NAME)
    with open(manifest_path, "w", encoding="utf-8") as manifest_file:
        json.dump(manifest, manifest_file, indent=2)
        manifest_file.write("\n")
    logger.info("Written: %s", manifest_path)


def main() -> None:
    logging.basicConfig(
        level=logging.INFO,
        format="%(levelname)s: %(message)s",
    )

    parser = argparse.ArgumentParser(
        description="Extract the Exynos9830 images from sboot.bin."
    )
    parser.add_argument(
        "sboot",
        help="Path to sboot.bin",
    )
    parser.add_argument(
        "-o",
        "--out",
        help="Output directory",
        default="sboot_splits",
    )

    args = parser.parse_args()

    if not os.path.isfile(args.sboot):
        logger.error("File not found: %s", args.sboot)
        sys.exit(1)

    try:
        logger.info("SoC: %s", SBOOT_SOC.rstrip("\0"))
        split_sboot(args.sboot, args.out)
        logger.info("Done.")
    except Exception as e:
        logger.error("Error: %s", e)
        sys.exit(1)


if __name__ == "__main__":
    main()