flawopen.com/Teardowns/CVE-2024-32002

CVE-2024-32002: Git Submodule Symlink RCE

Critical 9.8 CWE-78 / CWE-59 Git < 2.45.1
Languages: en pt-br es fr de ru zh-cn ja hi ko id
ELI5 — Das täuschende Büroschild

Stellen Sie sich einen Boten vor, der ein Paket in 'Raum 101' abliefern soll. Ein Angreifer klebt ein Schild an die Tür: 'Raum 101 befindet sich jetzt im Tresorraum der Geschäftsleitung'. Statt die Legitimität des Schildes zu prüfen, folgt der Bote blind dem Pfeil und legt das Paket im Tresor ab. Bei Git war der Bote der Submodul-Kloner, das täuschende Schild ein Symlink und der Tresorraum das versteckte Verzeichnis .git/hooks/, in dem Skripte automatisch ausgeführt werden.

Target: Git core CLI
Vector: git clone --recursive <url>
Impact: Remote Code Execution (RCE)
Platform: macOS & Windows (Case-Insensitive Filesystems)

Das fatale Git-Quellcode-Diff

In builtin/submodule--helper.c und dir.c initialisierte Git das Submodul, ohne zu prüfen, ob ein übergeordnetes Verzeichnis im Pfad ein Symlink ist, der aus dem Verzeichnisbaum herausführt.

builtin/submodule--helper.c (Vulnerable)Vulnerable
// Git clone created submodule directory blindly
static int clone_submodule(const struct module_clone_data *clone_data)
{
    struct strbuf sb = STRBUF_INIT;

    // BUG: clone_data->path could traverse an existing symlink
    strbuf_addf(&sb, "%s", clone_data->path);
    safe_create_leading_directories(sb.buf);
    return do_clone(clone_data);
}
builtin/submodule--helper.c (Fixed)Patched
// Fixed: Refuse to clone into or through symlinked path components
static int clone_submodule(const struct module_clone_data *clone_data)
{
    struct strbuf sb = STRBUF_INIT;

    // FIX: Validate that no parent component is a symlink
    if (path_has_symlinks(clone_data->path))
        die(_("fatal: submodule path '%s' contains a symlink"),
            clone_data->path);

    strbuf_addf(&sb, "%s", clone_data->path);
    return do_clone(clone_data);
}

Der 3-Stufen-Exploit-Ablauf

Wichtige Lektionen für Softwareentwickler

Explore more vulnerability mechanisms & language matrices: Command Injection Matrix →