自己做网站的过程,网站开发工程师累不累,网页制作工具哪个好,注册有限公司需要多少钱1、背景
利用gitleaks扫描git仓库或者文件
GitHub上有比较详细的教程#xff0c;但是由于每个人的安装环境不同#xff0c;坑很多#xff0c;网上能查到的有效信息也比较少。这里就以我坑很多的环境为例#xff0c;捋一下步骤。
GitHub - gitleaks/gitleaks: Protect an…1、背景
利用gitleaks扫描git仓库或者文件
GitHub上有比较详细的教程但是由于每个人的安装环境不同坑很多网上能查到的有效信息也比较少。这里就以我坑很多的环境为例捋一下步骤。
GitHub - gitleaks/gitleaks: Protect and discover secrets using Gitleaks
2、步骤
# MacOS
brew install gitleaks# Docker (DockerHub)
docker pull zricethezav/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source/path [OPTIONS]# Docker (ghcr.io)
docker pull ghcr.io/gitleaks/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path ghcr.io/gitleaks/gitleaks:latest [COMMAND] --source/path [OPTIONS]# From Source (make sure go is installed)
git clone https://github.com/gitleaks/gitleaks.git
cd gitleaks
make build
1安装brew
没有用docker因为本来linux环境里之前就装好brew了。这个装起来也挺烦的但是考虑到我用过其他很多扫描工具install的时候也常用brew所以就装了。一举多得。
首先手动克隆 Homebrew 的代码库
bash复制代码git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git ~/.linuxbrew/Homebrew
然后创建一些必要的目录并将 Homebrew 添加到你的 PATH 中
bash复制代码mkdir ~/.linuxbrew
mkdir ~/.linuxbrew/bin
ln -s ~/.linuxbrew/Homebrew/bin/brew ~/.linuxbrew/bin
echo export PATH$HOME/.linuxbrew/bin:$PATH ~/.bashrc
source ~/.bashrc
brew update
brew --version # 确认是否安装好了可能会有的报错
①Updating Homebrew... Error: Failed to download https://formulae.brew.sh/api/cask.jws.json!
这可能与网络连接或访问权限有关。
# 切换 Homebrew 主仓库到清华大学镜像
git -C $(brew --repo) remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git# 切换 Homebrew 核心库到清华大学镜像
git -C $(brew --repo)/Library/Taps/homebrew/homebrew-core remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git# 切换 Homebrew Cask 库到清华大学镜像
git -C $(brew --repo)/Library/Taps/homebrew/homebrew-cask remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git# 重新更新 Homebrew
brew update②fatal: cannot change to /home/iot/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core: No such file or directory
这个错误表明 Homebrew 的核心库 (homebrew-core) 还没有被正确克隆或安装。通常情况下Homebrew 会在第一次安装时自动下载和配置这些库但由于你的安装过程遇到了一些问题所以这个目录可能还没有被创建。
可以手动克隆 homebrew-core 仓库到正确的位置克隆完成后重新设置远程镜像地址
mkdir -p $(brew --repo)/Library/Taps/homebrew/
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git $(brew --repo)/Library/Taps/homebrew/homebrew-coregit -C $(brew --repo)/Library/Taps/homebrew/homebrew-core remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git更新
brew update
brew install gitleaks(2)brew install gitleaks
可能会有的报错
①Error: gitleaks: Failed to download resource glibc--bootstrap-binutils Download failed: https://github.com/Homebrew/glibc-bootstrap/releases/download/1.0.0/bootstrap-binutils-2.38.tar.gz或者Error: gitleaks: Failed to download resource glibc--bootstrap-gcc Download failed: https://github.com/Homebrew/glibc-bootstrap/releases/download/1.0.0/bootstrap-gcc-9.5.0.tar.gz。还是网络权限问题如果镜像多次连接不上有网络问题报错比如尝试直接从源代码编译安装
brew install gitleaks --build-from-source3git clone https://github.com/gitleaks/gitleaks.git
如果还是装不上尝试手动官网教程的第四条
这里因为又要连github网络不通畅就多试几次我大概试了8次左右吧。 4make build
打开进入安装好的gitleaks目录输入指令make build
可能会有的报错
①go fmt ./... go: github.com/BobuSumisu/aho-corasickv1.0.3: Get https://proxy.golang.org/github.com/%21bobu%21sumisu/aho-corasick/v/v1.0.3.mod: dial tcp 142.250.217.113:443: connect: connection refused make: *** [Makefile:13: format] Error 1
这个错误表明 go fmt 过程中尝试从 proxy.golang.org 下载依赖包时因网络问题例如连接被拒绝而失败。通常这是由于网络限制、代理设置或防火墙问题导致无法访问外部资源。
1. 设置 Go Modules 代理
可以尝试设置 Go 的代理为国内的代理服务这通常可以解决网络访问问题。你可以通过以下命令设置 Go Modules 的代理
export GOPROXYhttps://goproxy.cn,direct再次 make build
②build github.com/zricethezav/gitleaks/v8: cannot load embed: malformed module path embed: missing dot in first path element make: *** [Makefile:13: format] Error 1
这个错误提示 embed 包无法加载原因是 Go 的版本过低因为 embed 包是在 Go 1.16 中引入的。如果你正在使用较低版本的 Go这个包会导致构建失败。
解决方案升级GO版本
首先确认你当前使用的 Go 版本是否为 1.16 及以上。
go version如果 Go 版本低于 1.16可以使用以下命令更新 Go
sudo apt update
sudo apt install golang-go如果已经装了brew也可以尝试
brew update
brew upgrade go③更新的时候返回golang-go is already the newest version 在这种情况下你可以手动下载并安装最新版本的 Go。需要先卸载旧版本再下载新的
sudo apt remove golang-go
sudo apt remove --auto-remove golang-go
wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz# 将 Go 的二进制文件路径添加到系统环境变量 PATH 中
export PATH$PATH:/usr/local/go/bin④如果用brew upgrade go要确保之前在brew已经装过了go否则可能报错Error: go not installed
执行
brew install go
成功的话会显示Summary…… ⑤如果安装完成go version还是没有更新可能是环境变脸没有配置
编辑你的 .bashrc 或 .zshrc 文件添加以下内容
export PATH$PATH:/home/linuxbrew/.linuxbrew/bin保存更改
source ~/.bashrc # 或 source ~/.zshrc取决于你使用的 shell⑥go fmt ./... go: updates to go.mod needed; to update it: go mod tidy make: *** [Makefile:13: format] Error 1
go.mod 需要更新。
在 gitleaks 项目根目录下运行以下命令
go mod tidy# 之后再运行make build
⑥出现 gitleaks: command not found 错误可能是因为 gitleaks 可执行文件没有添加到系统的 PATH 中。
编辑 ~/.bashrc 或 ~/.zshrc 文件
nano ~/.bashrc # 或者 nano ~/.zshrc 在文件末尾添加以下行将 gitleaks 目录添加到 PATH 中 export PATH$PATH:/path/to/gitleaks # 这里改成自己的安装路径 保存并重新加载 shell 配置
source ~/.bashrc # 或者 source ~/.zshrc 5开始扫描
具体的指令官方也给出了 Usage:gitleaks [command]Available Commands:completion generate the autocompletion script for the specified shelldetect detect secrets in codehelp Help about any commandprotect protect secrets in codeversion display gitleaks versionFlags:-b, --baseline-path string path to baseline with issues that can be ignored-c, --config string config file pathorder of precedence:1. --config/-c2. env var GITLEAKS_CONFIG3. (--source/-s)/.gitleaks.tomlIf none of the three options are used, then gitleaks will use the default config--exit-code int exit code when leaks have been encountered (default 1)-h, --help help for gitleaks-l, --log-level string log level (trace, debug, info, warn, error, fatal) (default info)--max-target-megabytes int files larger than this will be skipped--no-color turn off color for verbose output--no-banner suppress banner--redact redact secrets from logs and stdout-f, --report-format string output format (json, csv, junit, sarif) (default json)-r, --report-path string report file-s, --source string path to source (default .)-v, --verbose show verbose output from scanUse gitleaks [command] --help for more information about a command. 我这里以扫描一个本地文件为例 如果要在终端里面展示扫描结果--no-git后面加上 --verbose
如果要把结果保存到本地加上--report-path