Skip to content

Commit

Permalink
firt commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yhy0 committed Dec 20, 2022
0 parents commit 0f93190
Show file tree
Hide file tree
Showing 38 changed files with 3,884 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 🎉 Build Binary
on:
create:
tags:
- v*
workflow_dispatch:
jobs:

build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- name: Set up Go 1.19
uses: actions/setup-go@v2
with:
go-version: 1.19
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: go mod download

- name: Build On Linux
run: |
go build -ldflags "-s -w" -o Yi-Linux-x64 cmd/main.go
chmod +x Yi-Linux-x64
if: matrix.os == 'ubuntu-latest'
- name: Build On Darwin
run: |
go build -ldflags "-s -w" -o Yi-Darwin-x64 cmd/main.go
chmod +x Yi-Darwin-x64
if: matrix.os == 'macos-latest'
- name: Build On Windows
run: |
go build -ldflags "-s -w" -o Yi-Windows-x64.exe cmd/main.go
if: matrix.os == 'windows-latest'
env:
GOOS: windows
GOENABLE: 1
- name: Release
uses: softprops/action-gh-release@master
with:
files: Yi-*
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Binaries for programs and plugins
*.db
.idea
logs
.DS_Store
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
1.txt
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DIR=data
$(shell mkdir -p ${DIR})

# Go build flags
LDFLAGS=-ldflags "-s -w"

default:
go build ${LDFLAGS} -o ${DIR}/Yi cmd/main.go

# Compile Server - Windows x64
windows:
export GOOS=windows;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/Yi.exe cmd/main.go

# Compile Server - Linux x64
linux:
export GOOS=linux;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/Yi-linux cmd/main.go

# Compile Server - Darwin x64
darwin:
export GOOS=darwin;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/Yi-darwin cmd/main.go

# clean
clean:
rm -rf ${DIR}
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#
以有算无

> [lgtm](https://lgtm.com/) 要关闭了,就搞了一个自己的监控工具。也方便自己编写好规则后,自动化批量扫描, 高效捡洞。
每天检查 github 项目是否更新,自动获取/生成数据库查询,自动运行 CodeQL 规则查询,高效捡洞.

默认 web 页面开放在8888端口, 用户名,密码如果没有指定,用户名默认为 yhy, 密码为随机的,会输出到控制台

注:因为使用了 go-sqlite3,每个平台需要单独编译

```go
./Yi -token githubToken -pwd 密码 -f 1.txt -user 用户名 -path /Users/yhy/CodeQL/codeql
```

考虑到监控的项目有点多,所以需要 github token,防止访问被限制.

**-path** 必须要指定,指 codeql 各种语言规则库的顶级目录

![image-20221213212521373](images/image-20221213212521373.png)

其它参数

```go
-p 代理
-t 运行时监控一个项目
-f 运行后要监控的项目, 每行一个github项目地址 url
-port web 访问端口,默认 8888 端口
-thread 扫描协程数,默认 5

-t -f 指定一个即可,或者都不使用,通过 Web 界面的新增按钮,慢慢添加
```

运行后,会自动在当前目录下生成相关文件夹(下载、生成的数据库,clone的仓库)和 ql 规则配置文件。


注: 运行该程序的机器上要安装好 **Codeql**(加入环境变量)、**Git****Docker****Go**

**Java****Maven****Gradle**(如果要监控 Java 项目的话,不然会导致数据库生成失败)

如果你需要其他语言,修改代码后,最好也安装好语言对应的编译工具。 emmmm 有没有各种语言都安装好的 docker

还有就是最好使用 `root` 执行, 监控项目中使用 `makefile` 时,可能会有一些工具,机器上没有,导致数据库失败,比如:

```go
[2022-12-14 16:34:26] [build-stdout] INFO: yq was not found, installing it
[2022-12-14 16:34:30] [build-stderr] make: go: 权限不够
[2022-12-14 16:34:30] [build-stderr] make: go: 权限不够
```

# 安全隐患
`codeql` 生成数据库时,会执行项目下的类似`makefile`的构建流程,这里存在安全隐患。

所以一定要对 **可信** **可信** **可信** 的项目进行监控,**别被弹了 shell**

**造成的一切损失与本项目及其作者无关**

**造成的一切损失与本项目及其作者无关**

**造成的一切损失与本项目及其作者无关**

# 功能

![image-20221213143603327](images/image-20221213143603327.png)

![image-20221215162315622](images/image-20221215162315622.png)

- [x] 每天监控项目是否是否更新,更新则获取/生成数据库,进行 Codeql 扫描
- [x] 监控配置文件更新,新增 ql 规则从数据库中获取进行扫描
- [x] 黑名单,有的规则会误报,看的时候将该扫描结果拉黑,以后再次扫描时该结果就不会在界面显示


# TODO

- [ ] 现在只是适配 Go,Java 语言,后期尽量适配主流语言,也可以修改项目中存在"Go","Java"的地方自己添加其他语言
- [ ] codeql 创建数据库时 指定 --[no-]db-cluster 会自动创建所有语言的数据库, 如果不指定--language ,需要指定 github token 来 自动分析 --github-auth-stdin
- [ ] 生成数据库可以下载
- [ ] Docker 封装好各种语言及其编译工具
- [ ] 读取本地 codeql 数据库,方便一些闭源或者私有项目

# 已知问题

- [ ] http 请求时,时不时的出现 `EOF`

# 📄 免责声明

本工具仅面向合法授权的企业安全建设行为,在使用本工具进行检测时,您应确保该行为符合当地的法律法规,并且已经取得了足够的授权。

如您在使用本工具的过程中存在任何非法行为或造成的一切损失,您需**自行承担相应后果, 本项目及其作者将不承担任何法律及连带责任**

在使用本工具前,请您务必审慎阅读、充分理解各条款内容,限制、免责条款或者其他涉及您重大权益的条款可能会以加粗、加下划线等形式提示您重点注意。 除非您已充分阅读、完全理解并接受本协议所有条款,否则,请您不要使用本工具。您的使用行为或者您以其他任何明示或者默示方式表示接受本协议的,即视为您已阅读并同意本协议的约束。
20 changes: 20 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"Yi/pkg/runner"
"Yi/pkg/web"
)

/**
@author: yhy
@since: 2022/10/13
@desc: //TODO
**/

func main() {
runner.ParseArguments()
go runner.Cyclic()
go runner.Run()

web.Init()
}
63 changes: 63 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Yi

go 1.19

require (
github.com/corpix/uarand v0.2.0
github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.6.0
github.com/gin-gonic/gin v1.8.1
github.com/json-iterator/go v1.1.12
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.14.0
github.com/x-cray/logrus-prefixed-formatter v0.5.2
gorm.io/datatypes v1.1.0
gorm.io/driver/sqlite v1.4.3
gorm.io/gorm v1.24.2
)

require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.22.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.4.4 // indirect
)
Loading

0 comments on commit 0f93190

Please sign in to comment.