diff --git a/module/finger/output.go b/module/finger/output.go index b1c75a4..82907d1 100644 --- a/module/finger/output.go +++ b/module/finger/output.go @@ -3,9 +3,11 @@ package finger import ( "encoding/json" "fmt" + "html/template" "os" + "path/filepath" + "sort" "strconv" - "strings" "github.com/360EntSecGroup-Skylar/excelize" ) @@ -48,19 +50,121 @@ func outxlsx(filename string, msg []Outrestul) { } func outfile(filename string, allresult []Outrestul) { - file := strings.Split(filename, ".") - if len(file) == 2 { - if file[1] == "json" { - buf, err := json.MarshalIndent(allresult, "", " ") - if err != nil { - fmt.Println(err.Error()) - return - } - outjson(filename, buf) - } - if file[1] == "xlsx" { - outxlsx(filename, allresult) + //获取后缀名 .json .xlsx .html + fileExt := filepath.Ext(filename) + if fileExt == ".json" { + buf, err := json.MarshalIndent(allresult, "", " ") + if err != nil { + fmt.Println(err.Error()) + return } + outjson(filename, buf) + } + if fileExt == ".xlsx" { + outxlsx(filename, allresult) + } + if fileExt == ".html" { + outhtml(filename, allresult) + } +} + +// 排序规则,将重点资产放到前面,方便在html中查看 +type SortByCms []Outrestul + +func (a SortByCms) Len() int { return len(a) } +func (a SortByCms) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a SortByCms) Less(i, j int) bool { return a[i].Cms != "" && a[j].Cms == "" } + +func outhtml(filename string, msg []Outrestul) { + // 创建HTML文件 + file, err := os.Create(filename) + if err != nil { + fmt.Println(err) } + defer file.Close() + sort.Sort(SortByCms(msg)) + tmpl := ` + + +
+ + +| URL | +CMS | +Title | +Server | +SC | +Len | + +
|---|---|---|---|---|---|
| {{.Url}} | +{{.Cms}} | +{{.Title}} | +{{.Server}} | +{{.Statuscode}} | +{{.Length}} | +