diff --git a/main b/main index 049dec6..224a3eb 100755 Binary files a/main and b/main differ diff --git a/main.go b/main.go index e98e342..ddc9ee8 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,11 @@ package main import ( - "main/src/Parser" - // "main/Pool" + "main/src/genmai/ArgParser" "fmt" "flag" "strconv" - "main/src/Actuator" + // "main/src/Actuator" genmai "main/src/genmai" ) type Vul struct{ @@ -22,36 +21,36 @@ type Vul struct{ PoolStatNum int //启动协程任务数 } func main(){ - /////////////////////////////// - // test "main/src/genmai" - genmai.Test() - // config := genmai.NewConfig() - fmt.Println(">>") - //fmt.Println(config["id"]) - return + // /////////////////////////////// + // // 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") + flag.StringVar(&vul.Web, "web", "false", "Use web") + flag.StringVar(&vul.System, "system", "false", "Use web") + flag.StringVar(&vul.Kernel, "kernel", "false", "Use web") + flag.StringVar(&vul.BaseLine, "baseline", "false", "Use web") var All = flag.Bool("all", false, "'ALL' is check BaseLine、kernel and system") var Update = flag.Bool("update", false, "update entire program") 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) + ArgParser.ParameterParser(vul.System,vul.Kernel,vul.Web,vul.BaseLine,sAll,vul.PoolStatNum,vul.ParserNum,vul.Update) + return /////////////////////////////// // test "main/src/genmai" diff --git a/src/Parser/FileParser.go b/src/Parser/FileParser.go deleted file mode 100644 index fc9c168..0000000 --- a/src/Parser/FileParser.go +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/src/Parser/ParameterParser.go b/src/Parser/ParameterParser.go deleted file mode 100644 index b6cf8a6..0000000 --- a/src/Parser/ParameterParser.go +++ /dev/null @@ -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) - } -} diff --git a/src/Parser/YamlParser.go b/src/Parser/YamlParser.go deleted file mode 100644 index 081ab84..0000000 --- a/src/Parser/YamlParser.go +++ /dev/null @@ -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 -} - diff --git a/src/genmai/ArgParser/ParameterParser.go b/src/genmai/ArgParser/ParameterParser.go new file mode 100644 index 0000000..1eecca1 --- /dev/null +++ b/src/genmai/ArgParser/ParameterParser.go @@ -0,0 +1,82 @@ +package ArgParser + +import( + "flag" + "fmt" + "main/src/genmai/Pool" + ) +var RequestsWeb string +var RequestsSystem string +var RequestsKernel string +var RequestsBaseLine string +var Num int +var PoolStatNums int +func ParameterParser(sSystem string,sKernel string,sWeb string,sBaseLine string,sAll string,PoolStatNum int,ParserNum int,Update string){ + if sSystem!="false"{ + if sSystem=="All"{ + PoolStatNum=PoolStatNum+1 + RequestsSystem=sSystem + }else{ + //检测函数检测安全性 + //单独检查某个项目 + } + } + + if sKernel=="false"{ + if sKernel=="All"{ + PoolStatNum=PoolStatNum+1 + RequestsKernel=sKernel + }else{ + //检测函数检测安全性 + //单独检查某个项目 + } + + } + + if sWeb!="false"{ + PoolStatNum=PoolStatNum+1 + RequestsWeb=sWeb + } + + if sBaseLine=="false"{ + if sBaseLine=="All"{ + PoolStatNum=PoolStatNum+1 + RequestsBaseLine=sBaseLine + }else{ + //检测函数检测安全性 + //单独检查某个项目 + } + } + if sAll=="true"{ + if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false" { + PoolStatNum=4 + 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 + } + PoolStatNums=PoolStatNum + Num=ParserNum + Pool.CoprogramPool(Num,RequestsSystem,RequestsKernel,RequestsWeb,RequestsBaseLine,PoolStatNums) +} diff --git a/src/Pool/CoprogramPool.go b/src/genmai/Pool/CoprogramPool.go similarity index 83% rename from src/Pool/CoprogramPool.go rename to src/genmai/Pool/CoprogramPool.go index 9ac8e8b..38ba0b6 100644 --- a/src/Pool/CoprogramPool.go +++ b/src/genmai/Pool/CoprogramPool.go @@ -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) { + p := NewPool(Num) StartPool(p) var wg sync.WaitGroup - wg.Add(PoolStatNum) + wg.Add(PoolStatNums) //执行解析yaml文件路径 SystemTask := func() { - fmt.Println(0) + wg.Done() } KernelTask := func() { - fmt.Println(1) + + //内核处理 wg.Done() } WebTask := func() { - fmt.Println(2) + fmt.Println(1) + //处理web + wg.Done() } BaseLineTask := func() { - fmt.Println(3) + + //基线处理 + wg.Done() } + + if len(RequestsSystem)>0{ p.Submit(SystemTask) }