渗透测试 | 如何通过git clone CVE-2024-32002 实现RCE

2024-06-07 340 0

Git中的一个新RCE在最近的安全提要上引起了我的注意,标记为CVE-2024-32002。通过一个简单的 git clone​ 命令触发RCE的想法让我着迷。考虑到Git的无处不在和 clone​ 命令的广泛使用,我立刻就被吸引住了。像克隆存储库这样的常规操作真的能为远程代码执行打开大门吗?

在这篇文章中,我将带你走过我逆转Git RCE的旅程,从最初的发现到制作一个工作漏洞。

我在网上搜索,看看是否有任何公共POC为这个CVE,但空手而归。不过,我很快找到了官方的建议:

带有子模块的存储库可以通过利用Git中的一个bug来制作,从而可以欺骗它将文件写入 .git/​ 目录而不是子模块的工作树。这允许编写一个钩子,当克隆操作仍在运行时执行,使用户没有机会检查正在执行的代码…

如果在Git中禁用了符号链接支持(例如通过 git config --global core.symlinks false​ ),则所描述的攻击将无法工作。

与往常一样,最好避免从不受信任的来源克隆存储库。

解释是有道理的,但它留给我的问题比答案多。Git到底是如何处理子模块的?符号链接在此漏洞中扮演什么角色?为了真正掌握游戏中的机制,我知道我必须更深入。没有比剖析源代码更好的方法来理解漏洞了。但是在一头扎进源代码之前,我需要巩固我对底层概念的理解。

git介绍

git是一个版本控制系统,可以跟踪代码随时间的变化。它通过将复杂的项目划分为更小的、可管理的块(称为存储库)来管理它们。为了进一步简化这一过程,Git使用了子模块-本质上是嵌套在其他存储库中的存储库。把它想象成一个初始阶段,但是是代码。

每个子模块都位于主存储库中的指定目录中。Git跟踪子模块的路径,确保更改被准确记录。然而,有一个陷阱:在不区分大小写的文件系统(如Windows和macOS上的默认文件系统)上, A/modules/x​ 和 a/modules/x​ 被视为相同的路径。这个看似次要的细节为我们的CVE奠定了基础。

符号链接

符号链接是文件系统对象,充当指向其他文件或目录的指针。在Git上下文中,它们可以用来引用仓库的其他部分。虽然方便,但符号链接也可以用于恶意目的。

漏洞修复方法解读

漏洞修复意见:submodules: submodule paths must not contain symlinks · git/git@9706576 (github.com)

检查builtin/submodule--helper.c​

@@ -1641,12 +1641,35 @@ static char *clone_submodule_sm_gitdir(const char *name)
	return sm_gitdir;
}

static int dir_contains_only_dotgit(const char *path)
{
	DIR *dir = opendir(path);
	struct dirent *e;
	int ret = 1;

	if (!dir)
		return 0;

	e = readdir_skip_dot_and_dotdot(dir);
	if (!e)
		ret = 0;
	else if (strcmp(DEFAULT_GIT_DIR_ENVIRONMENT, e->d_name) ||
		 (e = readdir_skip_dot_and_dotdot(dir))) {
		error("unexpected item '%s' in '%s'", e->d_name, path);
		ret = 0;
	}

	closedir(dir);
	return ret;
}

static int clone_submodule(const struct module_clone_data *clone_data,
			   struct string_list *reference)
{
	char *p;
	char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
	char *sm_alternate = NULL, *error_strategy = NULL;
	struct stat st;
	struct child_process cp = CHILD_PROCESS_INIT;
	const char *clone_data_path = clone_data->path;
	char *to_free = NULL;
@@ -1660,6 +1683,10 @@ static int clone_submodule(const struct module_clone_data *clone_data,
		      "git dir"), sm_gitdir);

	if (!file_exists(sm_gitdir)) {
		if (clone_data->require_init && !stat(clone_data_path, &st) &&
		    !is_empty_dir(clone_data_path))
			die(_("directory not empty: '%s'"), clone_data_path);

		if (safe_create_leading_directories_const(sm_gitdir) < 0)
			die(_("could not create directory '%s'"), sm_gitdir);

@@ -1704,6 +1731,14 @@ static int clone_submodule(const struct module_clone_data *clone_data,
		if(run_command(&cp))
			die(_("clone of '%s' into submodule path '%s' failed"),
			    clone_data->url, clone_data_path);

		if (clone_data->require_init && !stat(clone_data_path, &st) &&
		    !dir_contains_only_dotgit(clone_data_path)) {
			char *dot_git = xstrfmt("%s/.git", clone_data_path);
			unlink(dot_git);
			free(dot_git);
			die(_("directory not empty: '%s'"), clone_data_path);
		}
	} else {
		char *path;
  • 新函数 dir_contains_on

4A评测 - 免责申明

本站提供的一切软件、教程和内容信息仅限用于学习和研究目的。

不得将上述内容用于商业或者非法用途,否则一切后果请用户自负。

本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。

如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。敬请谅解!

程序来源网络,不确保不包含木马病毒等危险内容,请在确保安全的情况下或使用虚拟机使用。

侵权违规投诉邮箱:4ablog168#gmail.com(#换成@)

相关文章

苹果试图保护你的隐私,OpenAI可能做不到
Shuffle:一款完全自动化的安全栈增强平台
如何使用CODASM编码Payload并降低熵值
SessionExec:一款针对会话安全的安全命令测试工具
Arkime:一款大规模数据包捕获和索引数据库系统
从蓝队流量角度分析Shiro-550反序列化漏洞

发布评论