Git

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

要从 URL 导出 .git 文件夹,请使用 https://github.com/arthaud/git-dumper

使用 https://www.gitkraken.com/ 检查内容

如果在 web 应用中发现 .git 目录,可以使用 wget -r http://web.com/.git. 下载所有内容。然后,你可以使用 git diff 查看所做的更改。

工具: Git-Money, DVCS-PillageGitTools 可用于检索 git 目录的内容。

该工具 https://github.com/cve-search/git-vuln-finder 可用于在提交信息中搜索 CVE 和安全漏洞提示。

该工具 https://github.com/michenriksen/gitrob 在组织及其员工的仓库中搜索敏感数据。

Repo security scanner 是一个基于命令行的工具,目标明确:帮助你发现开发者在推送敏感数据时意外暴露的 GitHub secrets。和其他工具一样,它可以帮助你查找密码、私钥、用户名、令牌等。

这里有一篇关于 github dorks 的研究: https://securitytrails.com/blog/github-dorks

更快的 /.git dumping & dirlisting bypass (2024–2026)

  • holly-hacker/git-dumper 是对经典 GitTools dumper 的 2024 年重写,支持并行抓取(>10x 加速)。示例: python3 git-dumper.py https://victim/.git/ out && cd out && git checkout -- .
  • Ebryx/GitDump 通过对 .git/index, packed-refs 等的对象名进行暴力破解,以在目录遍历被禁用时恢复仓库: python3 git-dump.py https://victim/.git/ dump && cd dump && git checkout -- .

快速转储后初步检查

cd dumpdir
# reconstruct working tree
git checkout -- .
# show branch/commit map
git log --graph --oneline --decorate --all
# list suspicious config/remotes/hooks
git config -l
ls .git/hooks

Secret/credential hunting (current tooling)

  • TruffleHog v3+: 使用 entropy+regex 并自动遍历 Git 历史。 trufflehog git file://$PWD --only-verified --json > secrets.json
  • Gitleaks (v8+): 快速的 regex 规则集,可扫描解包的 tree 或完整历史。 gitleaks detect -v --source . --report-format json --report-path gitleaks.json

Server-side Git integration RCE via hooksPath override

现代 Web 应用在集成 Git 仓库时有时会 使用用户可控的标识符重写 .git/config。如果这些标识符被拼接到 hooksPath 中,你可以将 Git hooks 重定向到攻击者控制的目录,并在服务器运行本地 Git 时执行任意代码(例如,git commit)。关键步骤:

  • Path traversal in hooksPath: 如果一个 repo 名称/依赖名称被复制到 hooksPath,注入 ../../.. 来跳出预期的 hooks 目录并指向一个可写的位置。 这实际上是在 Git config 中的 path traversal
  • Force the target directory to exist: 当应用执行服务器端克隆时,滥用克隆目标控制(例如 ref/branch/path 参数)使其克隆到 ../../git_hooks 或类似的遍历路径,从而为你创建中间文件夹。
  • Ship executable hooks: 在 Git 元数据中设置可执行位,这样每次 clone 都会以模式 100755 写入 hook:
git update-index --chmod=+x pre-commit

将你的 payload (reverse shell, file dropper, etc.) 添加到该仓库的 pre-commit/post-commit 中。

  • Find a native Git code path: 像 JGit 这样的库会忽略 hooks。寻找部署流程/标志中会回退到 system Git 的情况(例如强制使用 deploy-with-attached-repo 参数),这样 hooks 才会真正运行。
  • Race the config rewrite: 如果应用在运行 Git 之前清理 .git/config,在触发 Git 操作的同时刷写写入你恶意 hooksPath 的端点以赢得一个 race condition 并使你的 hook 被执行。

References

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks