
一、基础信息查看
1. 查看提交历史
bash
git log --oneline # 简洁查看提交历史
git log --all --oneline # 查看所有分支的提交历史
git log --stat # 查看每次提交变更的文件统计
git log -p # 查看完整diff内容
git log --name-status # 查看每个提交新增/修改/删除的文件
2. 查看分支
bash
git branch -a # 查看所有分支(包括远程)
git branch -r # 查看远程分支
git branch -v # 查看分支详细信息
3. 查看远程仓库
bash
git remote -v # 查看远程仓库地址
git ls-remote origin # 查看远程仓库所有引用
二、隐藏信息挖掘
1. 查看 stash(暂存区)
bash
git stash list # 列出所有stash
git stash show stash@{0} # 查看stash内容
git stash show -p stash@{0} # 查看stash完整diff
2. 查看引用日志(reflog)
bash
git reflog # 查看所有HEAD移动记录
git reflog show --all # 查看所有分支的reflog
3. 查看被删除的提交
bash
git fsck --unreachable # 查找不可达的对象
git fsck --lost-found # 查找丢失的对象
git show <unreachable-commit> # 查看不可达commit内容
git show <unreachable-blob> # 查看不可达blob内容
4. 查看标签
bash
git tag -l # 列出所有标签
git show <tag-name> # 查看标签内容
三、敏感文件搜索
1. 搜索历史中的文件
bash
git log --all --full-history -- "*.pem"
git log --all --full-history -- "*.key"
git log --all --full-history -- "*.env"
git log --all --full-history -- "*.conf"
git log --all --full-history -- "*.sql"
git log --all --full-history -- "*.bak"
git log --all --full-history -- "*id_rsa*"
git log --all --full-history -- "*.password"
2. 查看特定文件的历史
bash
git log -p -- <file-path> # 查看某文件的所有历史修改
git show <commit>:<file-path> # 查看某commit中某文件的内容
3. 搜索提交消息
bash
git log --all --grep="key" # 搜索提交消息中包含key的
git log --all --grep="secret" # 搜索包含secret的
git log --all --grep="password" # 搜索包含password的
git log --all --grep="backup" # 搜索包含backup的
四、深入挖掘
1. 查看.git目录
bash
ls -la .git/ # 查看.git目录结构
cat .git/config # 查看git配置
cat .git/description # 查看仓库描述
cat .git/HEAD # 查看当前HEAD
cat .git/packed-refs # 查看打包的引用
2. 查看钩子文件
bash
ls -la .git/hooks/ # 查看钩子目录
cat .git/hooks/* # 查看钩子内容(可能有敏感信息)
3. 查看对象
bash
git cat-file -p <object-hash> # 查看任意git对象内容
git cat-file -t <object-hash> # 查看对象类型
五、CTF实战技巧
1. 完整信息收集脚本
bash
#!/bin/bash
echo "=== Git 信息收集 ==="
echo ""
echo "[+] 提交历史:"
git log --oneline --all
echo ""
echo "[+] 分支列表:"
git branch -a
echo ""
echo "[+] 远程仓库:"
git remote -v
echo ""
echo "[+] Stash列表:"
git stash list
echo ""
echo "[+] Reflog:"
git reflog
echo ""
echo "[+] 不可达对象:"
git fsck --unreachable
echo ""
echo "[+] 标签:"
git tag -l
2. 常见敏感信息关键词
| 类型 | 关键词 |
|---|---|
| 私钥 | id_rsa, id_dsa, *.pem, *.key |
| 密码 | password, passwd, secret, credential |
| 配置 | config, env, .env, settings |
| 备份 | bak, backup, old, tmp |
| 数据库 | sql, dump, db, database |
3. 恢复被删除的文件
bash
# 方法1: 从commit恢复
git checkout <commit-hash> -- <file-path>
# 方法2: 从blob恢复
git checkout <blob-hash> -- <file-path>
# 方法3: 从unreachable commit恢复
git show <commit-hash>:<file-path> > <file-path>