mirror of https://gitee.com/openkylin/genmai.git
Merge branch 'master' into alpha-dev
This commit is contained in:
commit
d34666badf
6
go.mod
6
go.mod
|
@ -4,7 +4,11 @@ go 1.17
|
|||
|
||||
require (
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
golang.org/x/crypto v0.2.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
require (
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
golang.org/x/sys v0.2.0 // indirect
|
||||
)
|
||||
|
|
31
go.sum
31
go.sum
|
@ -2,6 +2,37 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
|
|||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE=
|
||||
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
|
|
74
main.go
74
main.go
|
@ -2,12 +2,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"main/src/Parser"
|
||||
// "main/Pool"
|
||||
"main/src/genmai/ArgParser"
|
||||
"fmt"
|
||||
"flag"
|
||||
"strconv"
|
||||
"main/src/Actuator"
|
||||
"strings"
|
||||
|
||||
genmai "main/src/genmai"
|
||||
)
|
||||
type Vul struct{
|
||||
|
@ -20,38 +20,60 @@ type Vul struct{
|
|||
Update string //更新软件
|
||||
Docs string //生成报告
|
||||
PoolStatNum int //启动协程任务数
|
||||
IP string //web 制定IP
|
||||
MD string //生成MD文件
|
||||
RemoteAssessment string //远程检测
|
||||
SSHHost string //主机IP
|
||||
SSHUser string //用户名
|
||||
SSHPassword string //密码
|
||||
}
|
||||
func main(){
|
||||
///////////////////////////////
|
||||
// test "main/src/genmai"
|
||||
genmai.Test()
|
||||
// config := genmai.NewConfig()
|
||||
fmt.Println(">>")
|
||||
//fmt.Println(config["id"])
|
||||
return
|
||||
|
||||
//检测架构是否符合漏扫架构
|
||||
// result:=Actuator.OsCheck()
|
||||
// if result=="flase"{
|
||||
// fmt.Println("不支持其他架构")
|
||||
// return
|
||||
// }
|
||||
var vul Vul
|
||||
result:=Actuator.OsCheck()
|
||||
if result=="flase"{
|
||||
return
|
||||
}
|
||||
flag.IntVar(&vul.ParserNum, "POOL_NUMS", 0, "set coprogram nums")
|
||||
var System = flag.Bool("system", false, "Use only system")
|
||||
var Kernel = flag.Bool("kernel", false, "Use only kernel")
|
||||
var Web = flag.Bool("web", false, "Use only web")
|
||||
var BaseLine = flag.Bool("baseline", false, "Use only baseline")
|
||||
var All = flag.Bool("all", false, "'ALL' is check BaseLine、kernel and system")
|
||||
var Update = flag.Bool("update", false, "update entire program")
|
||||
flag.IntVar(&vul.ParserNum, "poolNums", 0, "设置协程的数量,默认数量为0,最大数量为200")
|
||||
flag.StringVar(&vul.Web, "web", "false", "使用web漏洞的验证模块,可联合其他模块使用")
|
||||
flag.StringVar(&vul.IP, "ip", "false", "设置ip,可设置ip段进行验证")
|
||||
flag.StringVar(&vul.System, "system", "false", "使用系统漏洞的验证模块,可联合其他模块使用")
|
||||
flag.StringVar(&vul.Kernel, "kernel", "false", "使用内核漏洞的验证模块,可联合其他模块使用")
|
||||
flag.StringVar(&vul.BaseLine, "baseline", "false", "使用基线检测模块,可联合其他模块使用")
|
||||
|
||||
|
||||
var RA = flag.Bool("RA", false, "使用远程检测,只能单独使用模块")
|
||||
flag.StringVar(&vul.SSHHost, "H", "false", "远程检测指定host")
|
||||
flag.StringVar(&vul.SSHUser, "user", "false", "远程检测指定用户")
|
||||
flag.StringVar(&vul.SSHPassword, "passwd", "false", "远程登录密码")
|
||||
|
||||
var All = flag.Bool("all", false, "只扫描除web模块外的所有模块的所有poc,不可联合其他参数使用")
|
||||
var Update = flag.Bool("update", false, "更新程序到最新版本,不可联合其他参数使用")
|
||||
|
||||
vul.PoolStatNum =0
|
||||
flag.Parse()
|
||||
|
||||
//初始化bool值
|
||||
vul.System = strconv.FormatBool(*System)
|
||||
vul.Kernel = strconv.FormatBool(*Kernel)
|
||||
vul.Web = strconv.FormatBool(*Web)
|
||||
vul.BaseLine = strconv.FormatBool(*BaseLine)
|
||||
sAll :=strconv.FormatBool(*All)
|
||||
vul.Update=strconv.FormatBool(*Update)
|
||||
Parser.ParameterParser(vul.System,vul.Kernel,vul.Web,vul.BaseLine,sAll,vul.PoolStatNum,vul.ParserNum,vul.Update)
|
||||
vul.RemoteAssessment=strconv.FormatBool(*RA)
|
||||
|
||||
//是否开启远程检测
|
||||
if vul.RemoteAssessment=="true"{
|
||||
checkResult:=ArgParser.RemoteArgParser(vul.SSHHost,vul.SSHUser,vul.SSHPassword)
|
||||
checkResult=strings.TrimSpace(checkResult)
|
||||
if checkResult=="true"{
|
||||
fmt.Println("不允许登录root用户进行验证")
|
||||
}else if checkResult=="false"{
|
||||
ArgParser.ParameterParser(vul.System,vul.Kernel,vul.Web,vul.BaseLine,sAll,vul.PoolStatNum,vul.ParserNum,vul.Update,vul.IP)
|
||||
}
|
||||
|
||||
}else{
|
||||
ArgParser.ParameterParser(vul.System,vul.Kernel,vul.Web,vul.BaseLine,sAll,vul.PoolStatNum,vul.ParserNum,vul.Update,vul.IP)
|
||||
}
|
||||
return
|
||||
|
||||
///////////////////////////////
|
||||
// test "main/src/genmai"
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
package Parser
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
//FileParser 读取三层yaml文件路径
|
||||
func FileParser() (string,[][]string,[][]string,[][]string,[][]string) {
|
||||
dirname := "src/Yaml"
|
||||
var RequestsSystemArray [][]string //请求信息
|
||||
var RequestsKernelArray [][]string //请求信息
|
||||
var RequestsWebArray [][]string //请求信息
|
||||
var RequestsBaseLineArray [][]string
|
||||
f, err := os.Open(dirname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
files, err := f.Readdir(-1)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, file := range files {
|
||||
dirYaml := dirname+"/"+file.Name()
|
||||
|
||||
|
||||
f2, err:=os.Open(dirYaml)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fileYaml, err := f2.Readdir(-1)
|
||||
f2.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _,Yaml:=range fileYaml{
|
||||
lastYaml := dirYaml+"/"+Yaml.Name()
|
||||
f3 ,err := os.Open(lastYaml)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
ParserYaml, err := f3.Readdir(-1)
|
||||
f3.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _,lastparserYaml := range ParserYaml{
|
||||
YamlPath:=lastYaml+"/"+lastparserYaml.Name()
|
||||
RequestsSystem, RequestsKernel, RequestsWeb ,RequestsBaseLine:=YamlParser(YamlPath)
|
||||
if len(RequestsSystem)>0{
|
||||
RequestsSystemArray = append(RequestsSystemArray, RequestsSystem)
|
||||
}
|
||||
if len(RequestsKernel)>0{
|
||||
RequestsKernelArray = append(RequestsKernelArray, RequestsKernel)
|
||||
}
|
||||
if len(RequestsWeb)>0{
|
||||
RequestsWebArray = append(RequestsWebArray, RequestsWeb)
|
||||
}
|
||||
if len(RequestsBaseLine)>0{
|
||||
RequestsWebArray = append(RequestsBaseLineArray, RequestsBaseLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "true",RequestsSystemArray,RequestsKernelArray,RequestsWebArray,RequestsBaseLineArray
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package Parser
|
||||
|
||||
import(
|
||||
"flag"
|
||||
"fmt"
|
||||
"main/src/Pool"
|
||||
)
|
||||
func ParameterParser(sSystem string,sKernel string,sWeb string,sBaseLine string,sAll string,PoolStatNum int,ParserNum int,Update string){
|
||||
if sSystem=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
}
|
||||
if sKernel=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
}
|
||||
if sWeb=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
}
|
||||
if sBaseLine=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
}
|
||||
if sAll=="true"{
|
||||
PoolStatNum=4
|
||||
}
|
||||
if Update=="true"{
|
||||
fmt.Println("Updating")
|
||||
}
|
||||
if sSystem!="true"&&sKernel!="true"&&sWeb!="true"&&sBaseLine!="true"&&sAll!="true"&&Update!="true"{
|
||||
flag.PrintDefaults()
|
||||
return
|
||||
}
|
||||
fmt.Println(PoolStatNum)
|
||||
//解析所有Yaml
|
||||
bool,RequestsSystemArray,RequestsKernelArray,RequestsWebArray,RequestsBaseLineArray:=FileParser()
|
||||
var Null [][]string
|
||||
if bool !="true"{
|
||||
fmt.Println("解析Yaml文件出错")
|
||||
return
|
||||
}
|
||||
if sSystem=="true" && sKernel!="true" && sWeb!="true" && sBaseLine!="true" && sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,Null,Null,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel=="true"&&sWeb!="true"&&sBaseLine!="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,RequestsKernelArray,Null,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel!="true"&&sWeb=="true"&&sBaseLine!="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,Null,RequestsWebArray,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel!="true"&&sWeb!="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,Null,Null,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel!="true"&&sWeb!="true"&&sBaseLine!="true"&&sAll=="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,RequestsKernelArray,RequestsWebArray,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem=="true"&&sKernel=="true"&&sWeb!="true"&&sBaseLine!="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,RequestsKernelArray,Null,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem=="true"&&sKernel!="true"&&sWeb=="true"&&sBaseLine!="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,Null,RequestsWebArray,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem=="true"&&sKernel!="true"&&sWeb!="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,Null,Null,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel=="true"&&sWeb=="true"&&sBaseLine!="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,RequestsKernelArray,RequestsWebArray,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel=="true"&&sWeb!="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,RequestsKernelArray,Null,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel!="true"&&sWeb=="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,Null,RequestsWebArray,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem=="true"&&sKernel=="true"&&sWeb=="true"&&sBaseLine!="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,RequestsKernelArray,RequestsWebArray,Null,PoolStatNum)
|
||||
}
|
||||
if sSystem=="true"&&sKernel!="true"&&sWeb=="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,Null,RequestsWebArray,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem=="true"&&sKernel=="true"&&sWeb!="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,RequestsSystemArray,RequestsKernelArray,Null,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
if sSystem!="true"&&sKernel=="true"&&sWeb=="true"&&sBaseLine=="true"&&sAll!="true"{
|
||||
Pool.CoprogramPool(ParserNum,Null,RequestsKernelArray,RequestsWebArray,RequestsBaseLineArray,PoolStatNum)
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package Parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
//Implement 解析执行类型
|
||||
type Implement struct{
|
||||
RawType string `yaml:"rawType"`
|
||||
Condition string `yaml:"condition"`
|
||||
ImMap map[string]string `yaml:"ImMap"`
|
||||
}
|
||||
|
||||
//Matchers 解析验证
|
||||
type Matchers struct{
|
||||
Type string `yaml:"type"`
|
||||
Condition string `yaml:"condition"`
|
||||
MatcherMap map[string]string `yaml:"MatcherMap"`
|
||||
}
|
||||
|
||||
//Requests 解析请求中的值
|
||||
type Requests struct{
|
||||
SiteImplement Implement `yaml:"implement"`
|
||||
ReqCondition string `yaml:"req-condition"`
|
||||
SiteMatchers Matchers `yaml:"matchers"`
|
||||
}
|
||||
|
||||
//Classification 解析Info中的信息
|
||||
type Classification struct{
|
||||
CvssMetrics string `yaml:"cvss-metrics"`
|
||||
CvssScore string `yaml:"cvss-score"`
|
||||
CveId string `yaml:"cve-id"`
|
||||
CweId string `yaml:"cwe-id"`
|
||||
CnvdId string `yaml:"cnvd-id"`
|
||||
KveId string `yaml:"kve-id "`
|
||||
}
|
||||
|
||||
// Info yaml文件的Info
|
||||
type Info struct{
|
||||
Name string `yaml:"name"`
|
||||
Severity string `yaml:"severity"`
|
||||
Description string `yaml:"description"`
|
||||
ScopeOfInfluence string `yaml:"scope-of-influence"`
|
||||
Reference string `yaml:"reference"`
|
||||
SiteClassification Classification `yaml:"classification"`
|
||||
Tags string `yaml:"tags"`
|
||||
}
|
||||
|
||||
//ResolvingYaml 解析Yaml文件
|
||||
type ResolvingYaml struct{
|
||||
Id string `yaml:"id"`
|
||||
Belong string `yaml:"belong"`
|
||||
PocHazardLevel string `yaml:"Poc-hazard-level"`
|
||||
Source string `yaml:"source"`
|
||||
SiteInfo Info `yaml:"info"`
|
||||
SiteRequests Requests `yaml:"requests"`
|
||||
}
|
||||
|
||||
|
||||
func YamlParser(path string) ([]string,[]string,[]string,[]string) {
|
||||
var RequestsSystem []string
|
||||
var RequestsKernel []string
|
||||
var RequestsWeb []string
|
||||
var RequestsBaseLine []string
|
||||
yamlPath := path
|
||||
var setting ResolvingYaml
|
||||
resolvingYaml, err := ioutil.ReadFile(yamlPath)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
yaml.Unmarshal(resolvingYaml,&setting)
|
||||
if setting.Belong=="system"{
|
||||
RequestsSystem= append(RequestsSystem, setting.Id)
|
||||
RequestsSystem = append(RequestsSystem, setting.SiteRequests.ReqCondition)
|
||||
}else if setting.Belong=="kernel"{
|
||||
RequestsKernel= append(RequestsKernel, setting.Id)
|
||||
RequestsKernel = append(RequestsKernel, setting.SiteRequests.ReqCondition)
|
||||
}else if setting.Belong=="web"{
|
||||
RequestsWeb= append(RequestsWeb, setting.Id)
|
||||
RequestsWeb = append(RequestsWeb, setting.SiteRequests.ReqCondition)
|
||||
}else if setting.Belong=="baseline"{
|
||||
RequestsBaseLine= append(RequestsBaseLine, setting.Id)
|
||||
RequestsBaseLine = append(RequestsBaseLine, setting.SiteRequests.ReqCondition)
|
||||
}else {
|
||||
fmt.Println("worth")
|
||||
}
|
||||
return RequestsSystem,RequestsKernel,RequestsWeb,RequestsBaseLine
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package ArgParser
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ArgCheck(targetString string)(LegalValue string){
|
||||
match, err := regexp.MatchString(`^[a-zA-Z][a-zA-Z0-9-]{4,15}$`, targetString)
|
||||
if err != nil {
|
||||
fmt.Println("IP 不合法请修改")
|
||||
}
|
||||
// fmt.Println(match)
|
||||
LegalValue=strconv.FormatBool(match)
|
||||
return LegalValue
|
||||
}
|
||||
|
||||
//IP校验
|
||||
func IPCheck(IP string)(matchResult string){
|
||||
match, err := regexp.MatchString(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9]
|
||||
[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`, IP)
|
||||
if err != nil {
|
||||
fmt.Println("IP 不合法请修改")
|
||||
}
|
||||
// fmt.Println(match)
|
||||
matchResult=strconv.FormatBool(match)
|
||||
return matchResult
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package ArgParser
|
||||
|
||||
import(
|
||||
"flag"
|
||||
"fmt"
|
||||
"main/src/genmai/Pool"
|
||||
"main/src/genmai/RemoteCheck"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
var RequestsWeb string
|
||||
var RequestsSystem string
|
||||
var RequestsKernel string
|
||||
var RequestsBaseLine string
|
||||
var Num int
|
||||
var RequestsIP string
|
||||
var PoolStatNums int
|
||||
func ParameterParser(sSystem string,sKernel string,sWeb string,sBaseLine string,sAll string,PoolStatNum int,ParserNum int,Update string ,IP string){
|
||||
|
||||
if sSystem!="false"{
|
||||
if sSystem=="All"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsSystem=sSystem
|
||||
}else{
|
||||
//检测函数检测安全性
|
||||
//单独检查某个项目
|
||||
LegalSystem:=ArgCheck(sSystem)
|
||||
if LegalSystem=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsSystem=sSystem
|
||||
}else{
|
||||
fmt.Println("system参数不合规")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if sKernel!="false"{
|
||||
if sKernel=="All"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsKernel=sKernel
|
||||
}else{
|
||||
//检测函数检测安全性
|
||||
//单独检查某个项目
|
||||
LegalKernel:=ArgCheck(sKernel)
|
||||
if LegalKernel=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsKernel=sKernel
|
||||
}else{
|
||||
fmt.Println("kernel参数不合规")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if sWeb!="false" && IP!="false"{
|
||||
if sWeb=="All"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsWeb=sWeb
|
||||
}else{
|
||||
//检测函数检测安全性
|
||||
//单独检查某个项目
|
||||
LegalWeb:=ArgCheck(sWeb)
|
||||
ipCheck:=IPCheck(IP)
|
||||
if ipCheck=="true"&&LegalWeb=="true"{
|
||||
RequestsIP=IP
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsWeb=sWeb
|
||||
}else{
|
||||
fmt.Println("参数不合规")
|
||||
}
|
||||
}
|
||||
}else if sWeb!="false" && IP=="false"{
|
||||
fmt.Println("请输入IP参数")
|
||||
return
|
||||
}else if sWeb=="false" && IP!="false"{
|
||||
fmt.Println("请输入web参数")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if sBaseLine!="false"{
|
||||
if sBaseLine=="All"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsBaseLine=sBaseLine
|
||||
}else{
|
||||
//检测函数检测安全性
|
||||
//单独检查某个项目
|
||||
LegalBaseline:=ArgCheck(sBaseLine)
|
||||
if LegalBaseline=="true"{
|
||||
PoolStatNum=PoolStatNum+1
|
||||
RequestsBaseLine=sBaseLine
|
||||
}else{
|
||||
fmt.Println("BaseLine参数不合规")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if sAll=="true"{
|
||||
if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false" {
|
||||
PoolStatNum=3
|
||||
RequestsKernel=sKernel
|
||||
RequestsSystem=sSystem
|
||||
// RequestsWeb=sWeb
|
||||
RequestsBaseLine=sBaseLine
|
||||
}else{
|
||||
fmt.Println("Only allow all")
|
||||
flag.PrintDefaults()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if Update=="true"{
|
||||
if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false" {
|
||||
fmt.Println("Updating")
|
||||
return
|
||||
}else{
|
||||
fmt.Println("The update process does not allow other processes")
|
||||
flag.PrintDefaults()
|
||||
return
|
||||
}
|
||||
}
|
||||
if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false"&&sAll!="true"&&Update!="true"{
|
||||
fmt.Println("error")
|
||||
flag.PrintDefaults()
|
||||
return
|
||||
}
|
||||
|
||||
//协程最大值为200
|
||||
if ParserNum<0 || ParserNum>200{
|
||||
fmt.Println("协程最大值为0-200")
|
||||
return
|
||||
}else{
|
||||
Num=ParserNum
|
||||
}
|
||||
|
||||
PoolStatNums=PoolStatNum
|
||||
Pool.CoprogramPool(Num,RequestsSystem,RequestsKernel,RequestsWeb,RequestsBaseLine,PoolStatNums,RequestsIP)
|
||||
}
|
||||
|
||||
func RemoteArgParser(SSHHost string,SSHUser string,SSHPassword string)(checkResult string){
|
||||
if SSHHost !="false" && SSHUser !="false" &&SSHPassword !="false"{
|
||||
|
||||
SSHHostCheck:=IPCheck(SSHHost)
|
||||
if SSHHostCheck !="true"{
|
||||
fmt.Println("host错误")
|
||||
}else{
|
||||
command:="id"
|
||||
result:=RemoteCheck.SSHConnect(SSHHost,SSHUser,SSHPassword,command)
|
||||
checkResult=strconv.FormatBool(strings.Contains(result, "root"))
|
||||
}
|
||||
}
|
||||
return checkResult
|
||||
}
|
|
@ -18,7 +18,6 @@ func NewPool(cap ...int) *Pool {
|
|||
var n int
|
||||
if len(cap) > 0 {
|
||||
n = cap[0]
|
||||
fmt.Println(n)
|
||||
}
|
||||
if n == 0 {
|
||||
n = runtime.NumCPU() // 默认等于CPU线程数
|
||||
|
@ -48,28 +47,35 @@ func (p *Pool) Submit(f func()) {
|
|||
p.TaskChannel <- f
|
||||
}
|
||||
|
||||
func CoprogramPool(num int,RequestsSystem [][]string,RequestsKernel [][]string,RequestsWeb [][]string,RequestsBaseLine[][]string,PoolStatNum int) {
|
||||
p := NewPool(num)
|
||||
func CoprogramPool(Num int,RequestsSystem string,RequestsKernel string,RequestsWeb string,RequestsBaseLine string,PoolStatNums int,IP string) {
|
||||
p := NewPool(Num)
|
||||
StartPool(p)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(PoolStatNum)
|
||||
wg.Add(PoolStatNums)
|
||||
//执行解析yaml文件路径
|
||||
SystemTask := func() {
|
||||
fmt.Println(0)
|
||||
fmt.Println("systemTask..")
|
||||
wg.Done()
|
||||
}
|
||||
KernelTask := func() {
|
||||
fmt.Println(1)
|
||||
fmt.Println("kernelTask..")
|
||||
//内核处理
|
||||
wg.Done()
|
||||
}
|
||||
WebTask := func() {
|
||||
fmt.Println(2)
|
||||
fmt.Println("webTask..")
|
||||
//处理web
|
||||
|
||||
wg.Done()
|
||||
}
|
||||
BaseLineTask := func() {
|
||||
fmt.Println(3)
|
||||
fmt.Println("baselineTask..")
|
||||
//基线处理
|
||||
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
|
||||
if len(RequestsSystem)>0{
|
||||
p.Submit(SystemTask)
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package RemoteCheck
|
||||
|
||||
import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"log"
|
||||
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
func SSHConnect(SSHHost string,SSHUser string, SSHPassword string,command string)(result string){
|
||||
|
||||
sshHost := SSHHost
|
||||
|
||||
sshUser := SSHUser
|
||||
|
||||
sshPassword := SSHPassword
|
||||
|
||||
sshType := "password"
|
||||
|
||||
sshPort := 22
|
||||
|
||||
//创建sshp登陆配置
|
||||
|
||||
config := &ssh.ClientConfig{
|
||||
|
||||
Timeout: 5*time.Second,//ssh 连接time out 时间一秒钟, 如果ssh验证错误 会在一秒内返回
|
||||
|
||||
User: sshUser,
|
||||
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //这个可以, 但是不够安全
|
||||
|
||||
//HostKeyCallback: hostKeyCallBackFunc(h.Host),
|
||||
|
||||
}
|
||||
|
||||
if sshType == "password" {
|
||||
|
||||
config.Auth = []ssh.AuthMethod{ssh.Password(sshPassword)}
|
||||
|
||||
}
|
||||
|
||||
//dial 获取ssh client
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", sshHost, sshPort)
|
||||
|
||||
sshClient, err := ssh.Dial("tcp", addr, config)
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Fatal("创建ssh client 失败",err)
|
||||
|
||||
|
||||
}
|
||||
|
||||
defer sshClient.Close()
|
||||
|
||||
//创建ssh-session
|
||||
|
||||
session, err := sshClient.NewSession()
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Fatal("创建ssh session 失败",err)
|
||||
|
||||
|
||||
}
|
||||
|
||||
defer session.Close()
|
||||
|
||||
//执行远程命令
|
||||
combo,err := session.CombinedOutput(command)
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Fatal("远程执行cmd 失败",err,command)
|
||||
|
||||
|
||||
}
|
||||
|
||||
log.Println("命令输出:",string(combo))
|
||||
defer session.Close()
|
||||
result=string(combo)
|
||||
return result
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"log"
|
||||
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
func main(){
|
||||
|
||||
sshHost := "127.0.0.1"
|
||||
|
||||
sshUser := "song"
|
||||
|
||||
sshPassword := "sbcj1999"
|
||||
|
||||
sshType := "password"
|
||||
|
||||
sshPort := 22
|
||||
|
||||
//创建sshp登陆配置
|
||||
|
||||
config := &ssh.ClientConfig{
|
||||
|
||||
Timeout: 5*time.Second,//ssh 连接time out 时间一秒钟, 如果ssh验证错误 会在一秒内返回
|
||||
|
||||
User: sshUser,
|
||||
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //这个可以, 但是不够安全
|
||||
|
||||
//HostKeyCallback: hostKeyCallBackFunc(h.Host),
|
||||
|
||||
}
|
||||
|
||||
if sshType == "password" {
|
||||
|
||||
config.Auth = []ssh.AuthMethod{ssh.Password(sshPassword)}
|
||||
|
||||
}
|
||||
|
||||
//dial 获取ssh client
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", sshHost, sshPort)
|
||||
|
||||
sshClient, err := ssh.Dial("tcp", addr, config)
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Fatal("创建ssh client 失败",err)
|
||||
|
||||
}
|
||||
|
||||
defer sshClient.Close()
|
||||
|
||||
//创建ssh-session
|
||||
|
||||
session, err := sshClient.NewSession()
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Fatal("创建ssh session 失败",err)
|
||||
|
||||
}
|
||||
|
||||
defer session.Close()
|
||||
|
||||
//执行远程命令
|
||||
|
||||
command:="whoami"
|
||||
combo,err := session.CombinedOutput(command)
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Fatal("远程执行cmd 失败",err)
|
||||
|
||||
}else{
|
||||
log.Println("命令输出:",string(combo))
|
||||
defer session.Close()
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue