resovle compile problem

This commit is contained in:
xujian 2024-09-04 18:11:49 +08:00
parent 8dd899c223
commit 20f6d690c3
6 changed files with 288 additions and 149 deletions

View File

@ -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
}

View File

@ -433,16 +433,13 @@ func RemoteVersionComparison(host string,port int,user string,passwd string,Remo
}
for i:=0;i<len(RemoteArg);i++{
if RemoteArg[i] =="FastScan"{
FastScanRE,FastScanNotIn,_ := FastScan.GetdpkgInfo(user,passwd,host,port)
FastScanRE,FastScanNotIn:= FastScan.GetdpkgInfo(user,passwd,host,port)
vul["FastScanRE"] = FastScanRE
vul["FastScanNotIn"] = FastScanNotIn
}
if RemoteArg[i] == "Iso"{
kybuild:=cliConf.RunShell("cat /etc/kylin-build |awk 'NR==3{print $2}'")
re,err:=Kybuilder.GenmaiIsoScan(kybuild)
if err != nil{
return vul,err
}
re:=Kybuilder.GenmaiIsoScan(kybuild)
dpkgInfo := strings.Split(re, " ")
PROJECT_CODENAME := cliConf.RunShell("cat /etc/os-release")
PROJECT_CODENAME=FastScan.JudgedOpVersion(PROJECT_CODENAME)

View File

@ -1,31 +1,34 @@
package main
import (
"main/genmai/FrameWorkCheck"
"flag"
"log"
"time"
"strconv"
"fmt"
"encoding/json"
"os"
// "compress/gzip"
"io"
"bytes"
"os/exec"
"strings"
genmai "main/genmai"
"main/tools/SSHExplosion"
"main/tools/Kybuilder"
"main/tools/FastScan"
"main/genmai/RemoteCheck"
// gcon "main/gconsole"
"archive/tar"
"bufio"
"path/filepath"
// TODO: 进度条:暂时无法实现:获取不了解压后的文件大小
// "github.com/cheggaaa/pb/v3"
"github.com/ulikunitz/xz"
"encoding/json"
"flag"
"fmt"
"log"
"main/genmai/FrameWorkCheck"
"os"
"strconv"
"time"
// "compress/gzip"
"bytes"
"io"
genmai "main/genmai"
"main/genmai/RemoteCheck"
"main/tools/FastScan"
"main/tools/Kybuilder"
"main/tools/SSHExplosion"
"os/exec"
"strings"
// gcon "main/gconsole"
"archive/tar"
"bufio"
"path/filepath"
// TODO: 进度条:暂时无法实现:获取不了解压后的文件大小
// "github.com/cheggaaa/pb/v3"
"github.com/ulikunitz/xz"
)
type Args struct{
ParserNum int //协程数
@ -337,7 +340,7 @@ func main(){
}
// Use the root password to perform higher authority detection
genmai.DoctorIns().SetDoctorVal(args.RootPasswd,RAV.User,RAV.Password,Time,RAV.Host,RAV.Port)
genmai.DoctorIns().SetDoctorVal(args.RootPasswd,"",RAV.User,RAV.Password,Time,RAV.Host,RAV.Port,false)
// 程序执行
emmit(args, RAV, WKV, FC)
@ -356,6 +359,7 @@ func main(){
ScanResultKernel,
ScanResultSystem,
ScanResultBaseline,
nil,
FastScanResult,
FastScanNotInResult,
IsoResult,
@ -367,6 +371,7 @@ func main(){
ScanResultKernel,
ScanResultSystem,
ScanResultBaseline,
nil,
FastScanResult,
FastScanNotInResult,
IsoResult,
@ -434,9 +439,7 @@ func emmit(args Args, RAV RAVUL, WKV WKPWDVUL, FC FofaCommand) {
} // if ("flase ...
// Web
if args.Web!="false" && args.IP!="false"{
genmaiWeb(args)
}else if args.Web!="false" && args.IP=="false"{
if args.Web!="false" && args.IP=="false"{
fmt.Println("请输入IP参数")
return
}else if args.Web=="false" && args.IP!="false"{
@ -681,80 +684,6 @@ genmaiKernel(args Args) {
}
}
func
genmaiWeb(args Args) {
createfile_fun := func (rp *genmai.ReportWeb,
fileName string ) {
path:="../data/Report/"+"web_"+fileName+".json"
Bool ,err:=genmai.PathExists(path)
if err != nil {
fmt.Println(err)
return
}
if Bool==true {
err := os.Remove(path)
if err != nil {
log.Println("File overwritten successfully")
} else {
log.Println("File overwrite failed")
}
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Println("open file failed,err:",err)
return
}
defer file.Close()
jsonVul, err := json.MarshalIndent(rp, "", " ")
if err != nil {
fmt.Println("json err ", err)
}
file.Write([]byte(jsonVul)) //写入字节切片数据
} // createfile_fun
fun := func (jout string) {
genmai.DoctorIns().Reset()
genmai.DoctorIns().LoadExplorersListConfig("../data/WebPocs/WebPocs.yaml")
genmai.A_DEBUG_INFO(">>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参数")

View File

@ -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 (

View File

@ -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...)
}

View File

@ -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
}