Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 117 additions & 13 deletions module/finger/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package finger
import (
"encoding/json"
"fmt"
"html/template"
"os"
"path/filepath"
"sort"
"strconv"
"strings"

"github.com/360EntSecGroup-Skylar/excelize"
)
Expand Down Expand Up @@ -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 := `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ehole</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
.container {
max-width: 80%;
margin: 20px auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
}
table {
/* width: 1100px; */
border-collapse: collapse;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
word-break: break-all;
}
th {
background-color: #f0f0f0;
}
tr:hover {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<div class="container">
<h1>Ehole 资产</h1>
<table width="100%" cellpadding="0" cellspacing="0" style="table-layout:fixed">
<tr>
<th style="width: 30%;">URL</th>
<th style="width: 20%;">CMS</th>
<th style="width: 30%;">Title</th>
<th style="width: 10%;">Server</th>
<th style="width: 5%;">SC</th>
<th style="width: 5%;">Len</th>

</tr>
{{range .}}

<tr>
<td><a href="{{.Url}}" target="_blank">{{.Url}}</a></td>
<td>{{.Cms}}</td>
<td>{{.Title}}</td>
<td>{{.Server}}</td>
<td>{{.Statuscode}}</td>
<td>{{.Length}}</td>
</tr>

{{end}}
</table>
</div>
</body>
</html>
`

// 解析HTML模板
t := template.Must(template.New("html").Parse(tmpl))
// 将数据写入HTML文件
err = t.Execute(file, msg)
if err != nil {
fmt.Println(err)
}
}