【CTF】Git 信息收集技巧总结

📅 2026/6/21 20:41:53
【CTF】Git 信息收集技巧总结
一、基础信息查看1. 查看提交历史gitlog--oneline# 简洁查看提交历史gitlog--all--oneline# 查看所有分支的提交历史gitlog--stat# 查看每次提交变更的文件统计gitlog-p# 查看完整diff内容gitlog --name-status# 查看每个提交新增/修改/删除的文件2. 查看分支gitbranch-a# 查看所有分支包括远程gitbranch-r# 查看远程分支gitbranch-v# 查看分支详细信息3. 查看远程仓库gitremote-v# 查看远程仓库地址gitls-remote origin# 查看远程仓库所有引用二、隐藏信息挖掘1. 查看 stash暂存区gitstash list# 列出所有stashgitstash show stash{0}# 查看stash内容gitstash show-pstash{0}# 查看stash完整diff2. 查看引用日志refloggitreflog# 查看所有HEAD移动记录gitreflog show--all# 查看所有分支的reflog3. 查看被删除的提交gitfsck--unreachable# 查找不可达的对象gitfsck--lost-found# 查找丢失的对象gitshowunreachable-commit# 查看不可达commit内容gitshowunreachable-blob# 查看不可达blob内容4. 查看标签gittag-l# 列出所有标签gitshowtag-name# 查看标签内容三、敏感文件搜索1. 搜索历史中的文件gitlog--all--full-history --*.pemgitlog--all--full-history --*.keygitlog--all--full-history --*.envgitlog--all--full-history --*.confgitlog--all--full-history --*.sqlgitlog--all--full-history --*.bakgitlog--all--full-history --*id_rsa*gitlog--all--full-history --*.password2. 查看特定文件的历史gitlog-p--file-path# 查看某文件的所有历史修改gitshowcommit:file-path# 查看某commit中某文件的内容3. 搜索提交消息gitlog--all--grepkey# 搜索提交消息中包含key的gitlog--all--grepsecret# 搜索包含secret的gitlog--all--greppassword# 搜索包含password的gitlog--all--grepbackup# 搜索包含backup的四、深入挖掘1. 查看.git目录ls-la.git/# 查看.git目录结构cat.git/config# 查看git配置cat.git/description# 查看仓库描述cat.git/HEAD# 查看当前HEADcat.git/packed-refs# 查看打包的引用2. 查看钩子文件ls-la.git/hooks/# 查看钩子目录cat.git/hooks/*# 查看钩子内容可能有敏感信息3. 查看对象gitcat-file-pobject-hash# 查看任意git对象内容gitcat-file-tobject-hash# 查看对象类型五、CTF实战技巧1. 完整信息收集脚本#!/bin/bashecho Git 信息收集 echoecho[] 提交历史:gitlog--oneline--allechoecho[] 分支列表:gitbranch-aechoecho[] 远程仓库:gitremote-vechoecho[] Stash列表:gitstash listechoecho[] Reflog:gitreflogechoecho[] 不可达对象:gitfsck--unreachableechoecho[] 标签:gittag-l2. 常见敏感信息关键词类型关键词私钥id_rsa,id_dsa,*.pem,*.key密码password,passwd,secret,credential配置config,env,.env,settings备份bak,backup,old,tmp数据库sql,dump,db,database3. 恢复被删除的文件# 方法1: 从commit恢复gitcheckoutcommit-hash--file-path# 方法2: 从blob恢复gitcheckoutblob-hash--file-path# 方法3: 从unreachable commit恢复gitshowcommit-hash:file-pathfile-path