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
初心者向け解説 —— オフィスを欺く案内板の罠

社内便の配達員が「101号室」に荷物を届ける場面を想像してください。攻撃者がドアに『101号室は役員金庫室へ移転しました』という張り紙を貼りました。配達員は疑うことなく矢印に従い、金庫室の中に荷物を運び込みました。Gitにおける配達員はサブモジュールのクローン処理、張り紙はシンボリックリンク、そして金庫室はスクリプトが自動実行される隠しフォルダ .git/hooks/ でした。

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

Gitソースコードの決定的なパッチ差分

builtin/submodule--helper.c および dir.c において、Gitはサブモジュールのパス上にワークツリー外を指すシンボリックリンクが含まれているかを検証していませんでした。

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);
}

3段階のエクスプロイトフロー

開発者が学ぶべき教訓

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