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 files19
creeeeger/cve-2024-56426Revision 3d6d94a21066

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

external/tools/extract_ldfw.py

Python · 2,369 bytes
#!/usr/bin/env python3
"""Extract individual Exynos 9830 LDFW records from ldfw.img."""

import argparse
import re
import struct
from pathlib import Path

LDFW_MAGIC = 0x10ADAB1E
LDFW_NAME_OFFSET = 0x30
LDFW_NAME_SIZE = 0x10
LDFW_ALIGNMENT = 0x1000


def sanitize_name(raw_name: bytes, offset: int) -> str:
    decoded = raw_name.split(b"\0", 1)[0].decode("ascii", errors="strict")
    cleaned = re.sub(r"[^A-Za-z0-9_.-]", "_", decoded)
    if not cleaned:
        cleaned = f"ldfw_{offset:08x}"
    if not cleaned.endswith(".ldfw"):
        cleaned += ".ldfw"
    return cleaned


def extract_ldfws(image_path: Path, output_dir: Path) -> list[Path]:
    data = image_path.read_bytes()
    output_dir.mkdir(parents=True, exist_ok=True)
    outputs: list[Path] = []
    offset = 0

    while offset + LDFW_NAME_OFFSET + LDFW_NAME_SIZE <= len(data):
        magic = struct.unpack_from("<I", data, offset)[0]
        if magic == 0:
            break
        if data[offset:offset + 9] == b"SignerVer":
            break
        if magic != LDFW_MAGIC:
            raise ValueError(f"invalid LDFW magic 0x{magic:08X} at offset 0x{offset:X}")

        size = struct.unpack_from("<I", data, offset + 4)[0]
        if size <= 0 or size % LDFW_ALIGNMENT:
            raise ValueError(f"invalid LDFW size 0x{size:X} at offset 0x{offset:X}")
        end = offset + size
        if end > len(data):
            raise ValueError(f"LDFW at 0x{offset:X} ends past the image at 0x{end:X}")

        name = sanitize_name(
            data[offset + LDFW_NAME_OFFSET:offset + LDFW_NAME_OFFSET + LDFW_NAME_SIZE],
            offset,
        )
        output_path = output_dir / name
        output_path.write_bytes(data[offset:end])
        outputs.append(output_path)
        print(f"extracted {name}: 0x{offset:X}-0x{end:X} ({size} bytes)")
        offset = end

    if not outputs:
        raise ValueError(f"no LDFW records found in {image_path}")
    return outputs


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("image", type=Path, help="Path to ldfw.img")
    parser.add_argument("-o", "--output-dir", type=Path, required=True)
    args = parser.parse_args()

    if not args.image.is_file():
        raise FileNotFoundError(args.image)
    extract_ldfws(args.image, args.output_dir)


if __name__ == "__main__":
    main()