diff --git a/src/genmai/Doctor.go b/src/genmai/Doctor.go index 5bff921..dab8181 100644 --- a/src/genmai/Doctor.go +++ b/src/genmai/Doctor.go @@ -789,10 +789,7 @@ func func (dtr *doctor)GenmaiFastScan() (map[string]interface{},map[string]interface{}){ Port,_:=strconv.Atoi(dtr.Port) - resultMap,resultMapNotIn,errCode:=FastScan.GetdpkgInfo(dtr.Username,dtr.Passwd_nor,dtr.Host,Port) - if errCode != 0{ - A_DEBUG_ERROR("Connection error,ssh RunShell error") - } + resultMap,resultMapNotIn:=FastScan.GetdpkgInfo(dtr.Username,dtr.Passwd_nor,dtr.Host,Port) return resultMap,resultMapNotIn } diff --git a/src/genmai/RemoteCheck/RemoteScan.go b/src/genmai/RemoteCheck/RemoteScan.go index ef65b9b..cbe84f6 100644 --- a/src/genmai/RemoteCheck/RemoteScan.go +++ b/src/genmai/RemoteCheck/RemoteScan.go @@ -433,16 +433,13 @@ func RemoteVersionComparison(host string,port int,user string,passwd string,Remo } for i:=0;i>Genmai Web>>") - rp := genmai.DoctorIns().GenmaiWeb() - if len(rp.RCExploredVulns)==0{ - fmt.Println("Web info: No vulnerability") - if jout !="null"{ - createfile_fun(rp,jout) - } - }else if jout !="null"{ - createfile_fun(rp,jout) - } - } - - var ipCheck string - // ipList := make([]string,0) - - if args.Web=="All" || args.Web=="all"{ - ipCheck,_=genmai.SecCheckIP(args.IP) - if ipCheck=="true"{ - //Request["web"] = args.Web - //Num=Num+1 - fun(args.OutPutJson) - }else{ - fmt.Println("IP参数不合规") - } - }else{ - //检测函数检测安全性 - //单独检查某个项目 - LegalWeb:=genmai.SecCheckArgs(args.Web) - ipCheck,_=genmai.SecCheckIP(args.IP) - if ipCheck=="true"&&LegalWeb=="true"{ - //Request["web"] = args.Web - //Num=Num+1 - fun(args.OutPutJson) - }else{ - fmt.Println("参数不合规") - } - } -} func genmaiBaseLine(args Args) { createfile_fun := func (rp *genmai.ReportBaseLine, fileName string){ @@ -910,8 +839,8 @@ genmaiWKPWD(WKPWD string ,PWDList []string) { } } // for i:= ... - _=genmai.PythonParser(PWD) - fmt.Println("弱密码已生成") + re,_:=genmai.PythonParser(PWD) + fmt.Println("弱密码已生成",re) return } @@ -953,12 +882,14 @@ genmaiNmapScan(Nmap string, NmapScanList []string) { if NmapScanList[0]!="false"{ if NmapScanList[1]=="all"{ Map[1]=" -H "+NmapScanList[0]+" -p "+"0-65000" - _=genmai.PythonParser(Map) + re,_:=genmai.PythonParser(Map) + fmt.Println(re) }else{ Map[1]=" -H "+NmapScanList[0]+" -p "+NmapScanList[1] - _=genmai.PythonParser(Map) + re,_:=genmai.PythonParser(Map) + fmt.Println(re) } fmt.Println("Nmap模块结束...") }else{ @@ -980,7 +911,8 @@ genmaiFofaApi(Fofa string,fofaCom string) { if fofaCom!="null"{ Map[1]=" -c "+fofaCom - _=genmai.PythonParser(Map) + re,_:=genmai.PythonParser(Map) + fmt.Println(re) }else{ fmt.Println("Fofa模块,参数使用错误,请添加fofaCom参数") log.Println("Fofa模块,参数使用错误,请添加fofaCom参数") diff --git a/src/tools/FastScan/FastScan.go b/src/tools/FastScan/FastScan.go index 55bf0a8..d2f5827 100644 --- a/src/tools/FastScan/FastScan.go +++ b/src/tools/FastScan/FastScan.go @@ -3,24 +3,27 @@ package FastScan import ( - // _ "github.com/go-sql-driver/mysql" - // _ "github.com/mattn/go-sqlite3" - "github.com/knqyf263/go-deb-version" - "github.com/pkg/sftp" - "golang.org/x/crypto/ssh" - // "database/sql" - "fmt" - "log" - "net" - // "sync" - "strings" - "bytes" - "os/exec" - "strconv" - "regexp" - "time" - // "reflect" - // "runtime" + // _ "github.com/go-sql-driver/mysql" + // _ "github.com/mattn/go-sqlite3" + version "github.com/knqyf263/go-deb-version" + "github.com/pkg/sftp" + "golang.org/x/crypto/ssh" + + // "database/sql" + "fmt" + "log" + "net" + + // "sync" + "bytes" + "os/exec" + "os/user" + "regexp" + "strconv" + "strings" + "time" + // "reflect" + // "runtime" ) type ClientConfig struct { @@ -529,6 +532,44 @@ func GetdpkgInfo(user string, passwd string, host string, port int) (map[string] return resultMap,resultMapNotIn } +func IsoScanSet(username string, passwd string, host string, port int, dpkgInfo []string,product string,framwork string ) (map[string]interface{},map[string]interface{}, int){ + var resultMap map[string]interface{} + var resultMapNotIn map[string]interface{} + errCode:= 0 + if host == "false"{ + resultMap,resultMapNotIn = MakeFastScan(dpkgInfo,product,framwork) + currentUser,_:=user.Current() + UserName:=currentUser.Username + resultMap["UserName"] = UserName + resultMap["HostName"] = Exec("hostname") + resultMap["OpName"] = Exec("cat /etc/os-release | awk 'NR==1{print $1}'") + resultMap["OpVersion"] = Exec("cat /etc/os-release | awk 'NR==14{print $1}'") + resultMap["Arch"] = framwork + resultMap["KernelRelease"] = Exec("uname -r") + + fmt.Println("检测方式为本地检测.....") + }else{ + defer func() { + if err := recover(); err != nil { + errCode=1004 + log.Println("recover:", errCode) + } + }() + cliConf := new(ClientConfig) + // fmt.Println(host, port, user, passwd) + _ =cliConf.createClient(host, port, username, passwd) + resultMap,resultMapNotIn = MakeFastScan(dpkgInfo,product,framwork) + resultMap["UserName"] = username + resultMap["HostName"] = cliConf.RunShell("hostname") + resultMap["OpName"] = cliConf.RunShell("cat /etc/os-release | awk 'NR==1{print $1}'") + resultMap["OpVersion"] = cliConf.RunShell("cat /etc/os-release | awk 'NR==14{print $1}'") + resultMap["Arch"] = framwork + resultMap["KernelRelease"] = cliConf.RunShell("uname -r") + fmt.Println("检测方式为服务器远程检测.....") + } + return resultMap,resultMapNotIn,errCode +} + func (cliConf *ClientConfig) createClient(host string, port int, username, password string)error { var ( diff --git a/src/tools/FastScan/Utils.go b/src/tools/FastScan/Utils.go index e303e32..191449a 100644 --- a/src/tools/FastScan/Utils.go +++ b/src/tools/FastScan/Utils.go @@ -1,14 +1,15 @@ package FastScan -import( - "gopkg.in/yaml.v2" - "io/ioutil" - "runtime" - "os/exec" - "strings" +import ( "bytes" - "log" "fmt" + "io/ioutil" + "log" + "os/exec" + "runtime" + "strings" + + "gopkg.in/yaml.v2" ) type Config struct { @@ -29,6 +30,7 @@ type Packages struct{ PackageInfo map[string]string `yaml:"PackageInfo"` } + // 获取当前系统架构 func GetCurrentFw()(string,string){ system:=runtime.GOOS @@ -73,6 +75,22 @@ func GetdOpUInfo()string{ } return outStr } +func Exec(command string)string{ + cmd := exec.Command("bash","-c",command) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout // 标准输出 + cmd.Stderr = &stderr // 标准错误 + err := cmd.Run() + outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes()) + if len(errStr)!=0{ + log.Println(errStr) + } + outStr = strings.TrimSpace(outStr) + if err != nil { + log.Println("cmd.Run() failed with %s\n", errStr) + } + return outStr +} // 获取源码包信息 func getSourceCode(packageName string)string{ str:="dpkg -s "+packageName+" |grep Source |awk '{print $2}'" @@ -124,4 +142,157 @@ func FastScanFalseAlarmConfigYamlParse(dpkgName string)bool{ } return false +} +// 判定系统版本 +func JudgedOpVersion(info string)string{ + + if strings.Contains(info, "SP1") { + return "V10SP1" + } else if strings.Contains(info, "V4"){ + return "V4" + }else if !strings.Contains(info, "SP1") && strings.Contains(info, "V10"){ + return "V10" + }else if !strings.Contains(info, "国防"){ + return "V10SP1" + }else { + return "NOT" + } +} +var A_DEBUG_LEVEL int = 0 +var A_DEBUG_NEED_HEAD bool = true +var A_DEVELOPMENT_MODE bool = false +//////////////////////////////////////////////////////////////// +// ALOG +const ( + A_DEBUG_LEVEL_INFO int = 0 + A_DEBUG_LEVEL_NOTE int = 1 + A_DEBUG_LEVEL_WARNING int = 2 + A_DEBUG_LEVEL_ERROR int = 3 + + A_DEBUG_LEVEL_STR_INFO string = "[+] [INF] " + A_DEBUG_LEVEL_STR_NOTE string = "[*] [NOT] " + A_DEBUG_LEVEL_STR_WARNING string = "[!] [WAR] " + A_DEBUG_LEVEL_STR_ERROR string = "[-] [ERR] " + A_DEBUG_LEVEL_STR_DEV string = "[#] [DEV] " + A_DEBUG_LEVEL_STR_VULNERABLE string = "[x] [VUL] " + A_DEBUG_LEVEL_STR_FIXED string = "[√] [FIX] " + A_DEBUG_LEVEL_STR_RISK string = "[x] [RIS] " + A_DEBUG_LEVEL_STR_SAFE string = "[√] [SAF] " + + A_DEBUG_LEVEL_COLOUR_INFO string = "W" + A_DEBUG_LEVEL_COLOUR_NOTE string = "B" + A_DEBUG_LEVEL_COLOUR_WARNING string = "Y" + A_DEBUG_LEVEL_COLOUR_ERROR string = "R" + A_DEBUG_LEVEL_COLOUR_DEV string = "W" + A_DEBUG_LEVEL_COLOUR_VULNERABLE string = "R" + A_DEBUG_LEVEL_COLOUR_FIXED string = "G" + A_DEBUG_LEVEL_COLOUR_RISK string = "B" + A_DEBUG_LEVEL_COLOUR_SAFE string = "G" +) + + +func +A_DEBUG(colour string,head string, args ...interface{}) { + if (true == A_DEBUG_NEED_HEAD) { + switch colour { + case "R-Y": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 31, head, 0x1B) + case "G-QQB": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 32, head, 0x1B) + case "Y-QB": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 33, head, 0x1B) + case "B": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 34, head, 0x1B) + case "Y": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 33, head, 0x1B) + case "R": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 31, head, 0x1B) + case "W": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 30, head, 0x1B) + case "G": + fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 32, head, 0x1B) + } + + } + switch colour { + case "R-Y": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 33) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + case "G": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 32) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + case "Y-QB": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 36) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + case "B": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 34) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + case "Y": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 33) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + case "R": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 31) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + case "W": + fmt.Printf("%c[%d;%d;%dm", 0x1B, 0, 0, 30) + fmt.Print(args...) + fmt.Printf("%c[0m\n", 0x1B) + } +} + +func +A_DEBUG_INFO(args ...interface{}) { + if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_INFO) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_INFO,A_DEBUG_LEVEL_STR_INFO , args...) + } +} +func +A_DEBUG_NOTE(args ...interface{}) { + if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_NOTE) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_NOTE,A_DEBUG_LEVEL_STR_NOTE , args...) + } +} +func +A_DEBUG_WARNING(args ...interface{}) { + if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_WARNING) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_WARNING,A_DEBUG_LEVEL_STR_WARNING , args...) + } +} +func +A_DEBUG_ERROR(args ...interface{}) { + if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_ERROR) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_ERROR,A_DEBUG_LEVEL_STR_ERROR , args...) + } +} + +func +A_DEBUG_DEV(args ...interface{}) { + if (A_DEVELOPMENT_MODE == true) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_DEV,A_DEBUG_LEVEL_STR_DEV , args...) + } +} + +func +A_DEBUG_VULNERABLE(args ...interface{}) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_VULNERABLE,A_DEBUG_LEVEL_STR_VULNERABLE , args...) +} + +func +A_DEBUG_FIXED(args ...interface{}) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_FIXED,A_DEBUG_LEVEL_STR_FIXED , args...) +} + +func +A_DEBUG_RISK(args ...interface{}) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_RISK,A_DEBUG_LEVEL_STR_RISK , args...) +} +func +A_DEBUG_SAFE(args ...interface{}) { + A_DEBUG(A_DEBUG_LEVEL_COLOUR_SAFE,A_DEBUG_LEVEL_STR_SAFE , args...) } \ No newline at end of file diff --git a/src/tools/Kybuilder/Kybuilder.go b/src/tools/Kybuilder/Kybuilder.go index 31313dd..17fedb5 100644 --- a/src/tools/Kybuilder/Kybuilder.go +++ b/src/tools/Kybuilder/Kybuilder.go @@ -1,11 +1,12 @@ package Kybuilder -import( + +import ( + "bytes" + "fmt" + "log" "main/genmai" + "os/exec" "strings" - "log" - "fmt" - "bytes" - "os/exec" ) /////////////////////////////// @@ -31,10 +32,10 @@ GenmaiIsoScan(arg string)string{ log.Fatalf("genmaiIsoScan worth %s\n", errStr) } Map[1]=" -kybuilder "+ outStr - re=genmai.PythonParser(Map) + re,_=genmai.PythonParser(Map) }else{ Map[1]=" -kybuilder "+ arg - re=genmai.PythonParser(Map) + re,_=genmai.PythonParser(Map) } return re }