Documentation
¶
Index ¶
- Variables
- func EveryCommit(localRepos string, opt ...Option) error
- func GitHack(remoteRepoURL string, localPath string, opts ...Option) (finalErr error)
- func NewConfig() *config
- func SetProxy(proxies ...string)
- type GitHackObject
- type Option
- func WithCheckoutCreate(b bool) Option
- func WithCheckoutForce(b bool) Option
- func WithCheckoutKeep(b bool) Option
- func WithContext(ctx context.Context) Option
- func WithDepth(depth int) Option
- func WithFetchAllTags(b bool) Option
- func WithFilterGitCommit(f func(r *object.Commit) bool) Option
- func WithFilterGitReference(f func(r *plumbing.Reference) bool) Option
- func WithForce(b bool) Option
- func WithHTTPOptions(opts ...poc.PocConfigOption) Option
- func WithHandleGitCommit(f func(r *object.Commit) error) Option
- func WithHandleGitReference(f func(r *plumbing.Reference) error) Option
- func WithNoFetchTags(b bool) Option
- func WithRecuriveSubmodule(b bool) Option
- func WithRemote(remote string) Option
- func WithThreads(threads int) Option
- func WithUseLocalGitBinary(b bool) Option
- func WithUsernamePassword(username, password string) Option
- func WithVerifyTLS(b bool) Option
Constants ¶
This section is empty.
Variables ¶
var ( DEFAULT_GIT_FILES = []string{ ".git/COMMIT_EDITMSG", ".git/description", ".git/info/exclude", ".git/FETCH_HEAD", ".git/logs/refs/remotes/origin/HEAD", ".git/ORIG_HEAD", ".git/packed-refs", ".git/logs/refs/stash", ".git/refs/remotes/origin/HEAD", ".git/objects/info/alternates", ".git/objects/info/http-alternates", ".git/refs/tags/v0.0.1", ".git/refs/tags/0.0.1", ".git/refs/tags/v1.0.0", ".git/refs/tags/1.0.0", } DEFAULT_GIT_FILES_DANGEROUS = []string{ ".git/config", ".git/hooks/applypatch-msg", ".git/hooks/commit-msg", ".git/hooks/fsmonitor-watchman", ".git/hooks/post-update", ".git/hooks/pre-applypatch", ".git/hooks/pre-commit", ".git/hooks/pre-merge-commit", ".git/hooks/pre-push", ".git/hooks/pre-rebase", ".git/hooks/pre-receive", ".git/hooks/prepare-commit-msg", ".git/hooks/update", } COMMON_BRANCH_NAMES = []string{ "daily", "dev", "feature", "feat", "fix", "hotfix", "issue", "main", "master", "ng", "quickfix", "release", "test", "testing", "wip", } EXPAND_BRANCH_NAME_PATH = []string{ ".git/logs/refs/heads", ".git/logs/refs/remotes/origin", ".git/refs/remotes/origin", ".git/refs/heads", } HEAD_REGEX = regexp.MustCompile("ref: refs/heads/([a-zA-Z0-9_-]+)") LOGs_HEAD_REGEX = regexp.MustCompile("checkout: moving from ([a-zA-Z0-9_-]+) to ([a-zA-Z0-9_-]+)") HASH_REGEX = regexp.MustCompile("[a-f0-9]{40}") PACK_REGEX = regexp.MustCompile("P pack-([a-z0-9]{40}).pack") )
var Exports = map[string]any{ "SetProxy": SetProxy, "GitHack": GitHack, "Clone": clone, "Pull": pull, "Fetch": fetch, "Checkout": checkout, "IterateCommit": EveryCommit, "auth": WithUsernamePassword, "context": WithContext, "depth": WithDepth, "recursive": WithRecuriveSubmodule, "remote": WithRemote, "force": WithForce, "verify": WithVerifyTLS, "checkoutCreate": WithCheckoutCreate, "checkoutForce": WithCheckoutForce, "checkoutKeep": WithCheckoutKeep, "noFetchTags": WithNoFetchTags, "fetchAllTags": WithFetchAllTags, "handleCommit": WithHandleGitCommit, "filterCommit": WithFilterGitCommit, "handleReference": WithHandleGitReference, "filterReference": WithFilterGitReference, "threads": WithThreads, "useLocalGitBinary": WithUseLocalGitBinary, "httpOpts": WithHTTPOptions, }
Functions ¶
func EveryCommit ¶
IterateCommit 用于指定一个本地仓库,遍历其所有的提交记录(commit),并对过滤后的每个提交记录执行指定的操作,它还可以接收零个到多个选项函数,用于配置回调函数 Example: ``` // 遍历提交记录,过滤名字中包含ci的引用记录,过滤作者名字为xxx的提交记录,打印剩余的每个提交记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterReference((ref) => {return !ref.Name().Contains("ci")}), git.filterCommit((c) => { return c.Author.Name != "xxx" }), git.handleCommit((c) => { println(c.String()) })) ```
func GitHack ¶ added in v1.2.8
GitHack 是一个用于利用 Git 源码泄露漏洞的函数 Git源码泄露漏洞是指:由于网站服务器的错误配置,可以通过 HTTP / HTTPS 直接访问到网站 .git 目录下的文件,从而导致源码泄露 Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.threads(8)) ```
func SetProxy ¶
func SetProxy(proxies ...string)
SetProxy 是一个辅助函数,用于指定其他 Git 操作(例如Clone)的代理 Example: ``` git.SetProxy("http://127.0.0.1:1080") ```
Types ¶
type GitHackObject ¶ added in v1.2.8
type GitHackObject struct {
// contains filtered or unexported fields
}
func NewGitHackObject ¶ added in v1.2.8
func NewGitHackObject(remoteRepoURL, tempDirPath string, gitConfig *config) *GitHackObject
type Option ¶
type Option func(*config) error
func WithCheckoutCreate ¶
fetchAllTags 是一个选项函数,用于指定检出(checkout)操作时是否创建新分支 Example: ``` git.Checkout("C:/Users/xxx/Desktop/yaklang", "feat/new-branch", git.checkoutCreate(true)) ```
func WithCheckoutForce ¶
fetchAllTags 是一个选项函数,用于指定检出(checkout)操作时是否强制 Example: ``` git.Checkout("C:/Users/xxx/Desktop/yaklang", "old-branch", git.checkoutForce(true)) ```
func WithCheckoutKeep ¶
checkoutKeep 是一个选项函数,用于指定检出(checkout)操作时,本地更改(索引或工作树更改)是否被保留,如果保留,就可以将它们提交到目标分支,默认为false Example: ``` git.Checkout("C:/Users/xxx/Desktop/yaklang", "old-branch", git.checkoutKeep(true)) ```
func WithContext ¶
context 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的上下文 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.context(context.New())) ```
func WithDepth ¶
depth 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的最大深度,默认为1 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.Depth(1)) ```
func WithFetchAllTags ¶
fetchAllTags 是一个选项函数,用于指定获取(fetch)操作时是否拉取所有标签 Example: ``` git.Fetch("C:/Users/xxx/Desktop/yaklang", git.fetchAllTags(true)) // 拉取所有标签 ```
func WithFilterGitCommit ¶
filterCommit 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为提交记录结构体(commit),每次遍历到提交记录时,就会调用这个回调函数,这个函数还有一个返回值,通过这个返回值来决定是否过滤掉这个提交记录 Example: ``` // 遍历提交记录,过滤作者名字为xxx的提交记录,打印剩余的每个提交记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterCommit((c) => { return c.Author.Name != "xxx" }), git.handleCommit((c) => { println(c.String()) })) ```
func WithFilterGitReference ¶
filterReference 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为引用记录结构体(reference),每次遍历到引用时,就会调用这个回调函数,这个函数还有一个返回值,通过这个返回值来决定是否过滤掉这个引用 Example: ``` // 遍历提交记录,过滤名字中包含ci的引用记录,打印剩余的每个引用记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterReference((ref) => {return !ref.Name().Contains("ci")}), git.handleReference((ref) => { println(ref.String()) })) ```
func WithForce ¶
force 是一个选项函数,用于指定其他 Git 操作(例如Pull)时是否强制执行,默认为false Example: ``` git.Pull("C:/Users/xxx/Desktop/yaklang", git.verify(false), git.force(true)) ```
func WithHTTPOptions ¶ added in v1.2.8
func WithHTTPOptions(opts ...poc.PocConfigOption) Option
httpOpts 是一个GitHack选项函数,用于指定GitHack的HTTP选项,其接收零个到多个poc的请求选项函数 Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.httpOpts(poc.timeout(10), poc.https(true))) ```
func WithHandleGitCommit ¶
handleCommit 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为提交记录结构体(commit),每次遍历到一个过滤后的提交记录时,就会调用这个回调函数 Example: ``` // 遍历提交记录,打印每个提交记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.handleCommit((c) => { println(c.String()) })) ```
func WithHandleGitReference ¶
handleReference 是一个选项函数,它接收一个回调函数,这个函数有一个参数,其为引用记录结构体(reference),每次遍历到过滤后的引用时,就会调用这个回调函数 Example: ``` // 遍历提交记录,过滤名字中包含ci的引用记录,打印剩余的每个引用记录 git.IterateCommit("D:/coding/golang/src/yaklang", git.filterReference((ref) => {return !ref.Name().Contains("ci")}), git.handleReference((ref) => { println(ref.String()) })) ```
func WithNoFetchTags ¶
noFetchTags 是一个选项函数,用于指定获取(fetch)操作时是否不拉取标签 Example: ``` git.Fetch("C:/Users/xxx/Desktop/yaklang", git.noFetchTags(true)) // 不拉取标签 ```
func WithRecuriveSubmodule ¶
recursive 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的是否递归克隆子模块,默认为false Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.recursive(true)) ```
func WithRemote ¶
remote 是一个选项函数,用于指定其他 Git 操作(例如Pull)时的远程仓库名称,默认为origin Example: ``` git.Pull("C:/Users/xxx/Desktop/yaklang", git.verify(false), git.remote("origin")) ```
func WithThreads ¶ added in v1.2.8
threads 是一个GitHack选项函数,用于指定并发数,默认为8 Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.threads(8)) ```
func WithUseLocalGitBinary ¶ added in v1.2.8
useLocalGitBinary 是一个GitHack选项函数,用于指定是否使用本地环境变量的git二进制文件来执行`git fsck`命令,这个命令用于尽可能恢复完整的git仓库,默认为true Example: ``` git.GitHack("http://127.0.0.1:8787/git/website", "C:/Users/xxx/Desktop/githack-test", git.useLocalGitBinary(true)) ```
func WithUsernamePassword ¶
auth 是一个选项函数,用于指定其他 Git 操作(例如Clone)时的认证用户名和密码 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.auth("admin", "admin")) ```
func WithVerifyTLS ¶
verify 是一个选项函数,用于指定其他 Git 操作(例如Clone)时是否验证TLS证书 Example: ``` git.Clone("https://github.com/yaklang/yaklang", "C:/Users/xxx/Desktop/yaklang", git.recursive(true), git.verify(false)) ```