2025-02-26 18:58:43 +08:00
|
|
|
|
package attackevent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"dt_automate/conn"
|
|
|
|
|
"dt_automate/tool"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"log"
|
|
|
|
|
"net/url"
|
2025-02-27 00:12:26 +08:00
|
|
|
|
"strconv"
|
2025-02-26 18:58:43 +08:00
|
|
|
|
"time"
|
2025-02-27 00:12:26 +08:00
|
|
|
|
|
|
|
|
|
"github.com/Esword618/unioffice/schema/soo/sml"
|
|
|
|
|
"github.com/Esword618/unioffice/spreadsheet"
|
2025-02-26 18:58:43 +08:00
|
|
|
|
)
|
|
|
|
|
|
2025-02-27 00:12:26 +08:00
|
|
|
|
var cookieStr string
|
|
|
|
|
|
|
|
|
|
// 传入cookie
|
|
|
|
|
func Fw_event(cookieStr string) {
|
|
|
|
|
ss := spreadsheet.New()
|
|
|
|
|
sheet := ss.AddSheet()
|
|
|
|
|
// sheet.SetFrozen(true, false)
|
|
|
|
|
v := sheet.InitialView()
|
|
|
|
|
v.SetState(sml.ST_PaneStateFrozen)
|
|
|
|
|
v.SetXSplit(0) //冻结列
|
|
|
|
|
v.SetYSplit(1) //冻结行
|
|
|
|
|
// v.SetTopLeft("B2")
|
|
|
|
|
// // 获取第一个工作表
|
|
|
|
|
// sheet, err := ss.GetSheet("Sheet2")
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// log.Println(err)
|
|
|
|
|
// }
|
|
|
|
|
sheet.Cell("A1").SetString("序号")
|
|
|
|
|
sheet.Cell("B1").SetString("攻击时间")
|
|
|
|
|
sheet.Cell("C1").SetString("源安全域")
|
|
|
|
|
sheet.Cell("D1").SetString("目的安全域")
|
|
|
|
|
sheet.Cell("E1").SetString("源IP")
|
|
|
|
|
sheet.Cell("F1").SetString("目的IP")
|
|
|
|
|
sheet.Cell("G1").SetString("目的端口")
|
|
|
|
|
sheet.Cell("H1").SetString("攻击类型")
|
|
|
|
|
sheet.Cell("I1").SetString("应用协议")
|
|
|
|
|
sheet.Cell("J1").SetString("域名(host)")
|
2025-02-26 18:58:43 +08:00
|
|
|
|
|
|
|
|
|
//当前时间
|
|
|
|
|
EndTime := time.Unix(tool.Timestamp("second"), 0).Format("2006-01-02T15:04:05")
|
|
|
|
|
//今天0点
|
|
|
|
|
StartTime := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Now().Location()).Format("2006-01-02T15:04:05")
|
|
|
|
|
// 构建 x-www-form-urlencoded 格式的请求体
|
|
|
|
|
values := url.Values{}
|
|
|
|
|
values.Add("xml", "<rpc message-id='101' xmlns='urn:ietf:params:xml:ns:netconf:base:1.0' xmlns:web='urn:ietf:params:xml:ns:netconf:base:1.0'><get-bulk><filter type='subtree'><top xmlns='http://www.unis.cn/netconf/data:1.0' xmlns:web='http://www.unis.cn/netconf/base:1.0' xmlns:data='http://www.unis.cn/netconf/data:1.0'><NTOP><LogPaging><Log><LogType>1</LogType><UserID/><ID/><TimeFilter><StartTime>"+StartTime+"</StartTime><EndTime>"+EndTime+"</EndTime></TimeFilter><PageNo>1</PageNo><CountPerPage>200</CountPerPage><TotalCounts/><InputJSON>{"SrcZoneName":"Untrust","DestZoneName":"Trust"}</InputJSON><OutputJSON/></Log></LogPaging></NTOP></top></filter></get-bulk></rpc>")
|
|
|
|
|
values.Add("req_menu", "M_Monitor/M_AtkLog/M_ThreatLog")
|
|
|
|
|
header := map[string]string{
|
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
|
|
|
"referer": "https://11.2.68.146/wnm/frame/index.php",
|
|
|
|
|
"cookie": cookieStr,
|
|
|
|
|
}
|
2025-02-27 10:48:32 +08:00
|
|
|
|
body := conn.DT_POST("https://11.2.68.146/wnm/get.j", header, bytes.NewBufferString(values.Encode()))
|
|
|
|
|
var bodys Person
|
|
|
|
|
json.Unmarshal(body, &bodys)
|
|
|
|
|
|
|
|
|
|
for v, k := range bodys.LogPaging {
|
|
|
|
|
// fmt.Printf("序号:%d,攻击时间:[%s],安全域:%s-%s##攻击源IP:%s#目的源IP:%s:%s,攻击类型:%s,应用协议:%s,请求域名:%s\n", v, a["Time"], a["SrcZoneName"], a["DestZoneName"], a["SrcIPAddr"], a["DestIPAddr"], strconv.FormatFloat(a["DestPort"].(float64), 'f', 0, 64), a["ThreatName"], a["Application"], a["HttpHost"])
|
2025-02-27 00:12:26 +08:00
|
|
|
|
sheet.Cell("A" + strconv.Itoa(v+1)).SetString(strconv.Itoa(v)) // 第一列 (A1)
|
2025-02-27 10:48:32 +08:00
|
|
|
|
sheet.Cell("B" + strconv.Itoa(v+1)).SetString(k.Time)
|
|
|
|
|
sheet.Cell("C" + strconv.Itoa(v+1)).SetString(k.SrcZoneName)
|
2025-02-27 00:12:26 +08:00
|
|
|
|
sheet.Cell("D" + strconv.Itoa(v+1)).SetString(a["DestZoneName"].(string))
|
|
|
|
|
sheet.Cell("E" + strconv.Itoa(v+1)).SetString(a["SrcIPAddr"].(string))
|
|
|
|
|
sheet.Cell("F" + strconv.Itoa(v+1)).SetString(a["DestIPAddr"].(string))
|
|
|
|
|
sheet.Cell("G" + strconv.Itoa(v+1)).SetString(strconv.FormatFloat(a["DestPort"].(float64), 'f', 0, 64))
|
|
|
|
|
sheet.Cell("H" + strconv.Itoa(v+1)).SetString(a["ThreatName"].(string))
|
|
|
|
|
sheet.Cell("I" + strconv.Itoa(v+1)).SetString(a["Application"].(string))
|
|
|
|
|
sheet.Cell("J" + strconv.Itoa(v+1)).SetString(a["HttpHost"].(string))
|
|
|
|
|
}
|
|
|
|
|
// 保存修改后的 Excel 文件
|
|
|
|
|
if err := ss.Validate(); err != nil {
|
|
|
|
|
log.Fatalf("验证文件时出错: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if err := ss.SaveToFile("防火墙安全事件.xlsx"); err != nil {
|
|
|
|
|
log.Fatalf("保存文件时出错: %s", err)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-27 10:48:32 +08:00
|
|
|
|
|
|
|
|
|
type Person struct {
|
|
|
|
|
NTOP string `json:"ntop"`
|
|
|
|
|
LogPaging []LogPaging `json:"logpaging"`
|
|
|
|
|
}
|
|
|
|
|
type LogPaging struct {
|
|
|
|
|
Time string `json:"time"`
|
|
|
|
|
SrcZoneName string `json"srczonename"`
|
|
|
|
|
}
|