2025-02-19 18:30:19 +08:00
|
|
|
|
package conn
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crypto/tls"
|
2025-02-27 18:37:03 +08:00
|
|
|
|
"encoding/json"
|
2025-02-19 18:30:19 +08:00
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// headers := map[string]string{
|
|
|
|
|
// "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
|
|
|
// }
|
2025-02-27 18:37:03 +08:00
|
|
|
|
func DT_POST(urls string, headers map[string]string, bytess io.Reader) Person {
|
2025-02-19 18:30:19 +08:00
|
|
|
|
url, err := url.Parse(urls)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
// 创建一个 POST 请求
|
|
|
|
|
r, err := http.NewRequest(http.MethodPost, url.String(), bytess)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// // 设置请求头
|
|
|
|
|
// req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
// 使用 map 动态设置请求头 // 设置请求头 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
|
|
|
|
for key, value := range headers {
|
|
|
|
|
r.Header.Set(key, value) // 使用 Set 方法设置请求头
|
|
|
|
|
}
|
|
|
|
|
// 创建一个 HTTP 客户端,跳过证书验证
|
|
|
|
|
tr := &http.Transport{
|
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
|
|
|
}
|
|
|
|
|
// 发送请求
|
|
|
|
|
client := &http.Client{Transport: tr}
|
|
|
|
|
resp, err := client.Do(r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
// 检查响应状态码
|
|
|
|
|
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
|
|
|
|
|
log.Printf("server returned: %s", resp.Status)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 读取响应体内容
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
2025-02-27 18:37:03 +08:00
|
|
|
|
log.Println(string(body))
|
2025-02-27 10:48:32 +08:00
|
|
|
|
// var gcresp map[string]interface{}
|
|
|
|
|
// if err := ScanJson(resp, gcresp); err != nil {
|
|
|
|
|
// log.Println(err)
|
|
|
|
|
// }
|
2025-02-27 18:37:03 +08:00
|
|
|
|
var bodys Person
|
|
|
|
|
json.NewDecoder(resp.Body).Decode(&bodys)
|
|
|
|
|
return bodys
|
2025-02-19 18:30:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// req 请求体 url 请求地址 headers请求头
|
|
|
|
|
func DT_GET(req map[string]interface{}, urls string) map[string]interface{} {
|
|
|
|
|
url, err := url.Parse(urls)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
body, err := ToJsonBuff(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println()
|
|
|
|
|
}
|
|
|
|
|
log.Println("hson请求体:", body)
|
|
|
|
|
r, err := http.NewRequest(http.MethodGet, url.String(), body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println()
|
|
|
|
|
}
|
|
|
|
|
// 使用 map 动态设置请求头
|
|
|
|
|
headers := map[string]string{
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
|
|
|
|
|
"Accept-Language": "en-US",
|
|
|
|
|
"cookie": "__ac_nonce=0638733a400869171be51",
|
|
|
|
|
}
|
|
|
|
|
for key, value := range headers {
|
|
|
|
|
r.Header.Set(key, value) // 使用 Set 方法设置请求头
|
|
|
|
|
}
|
|
|
|
|
resp, err := http.DefaultClient.Do(r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
|
log.Printf("响应失败,状态码为 %s", resp.Status)
|
|
|
|
|
}
|
|
|
|
|
var gcresp map[string]interface{}
|
|
|
|
|
if err := ScanJson(resp, gcresp); err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
return gcresp
|
|
|
|
|
}
|
2025-02-27 18:37:03 +08:00
|
|
|
|
|
|
|
|
|
type Person struct {
|
|
|
|
|
NTOP string `json:"ntop"`
|
|
|
|
|
LogPaging []LogPaging `json:"logpaging"`
|
|
|
|
|
}
|
|
|
|
|
type LogPaging struct {
|
|
|
|
|
LogType string `json:"logtype"` //日志ID
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
UserID string `json:"userid"`
|
|
|
|
|
PageNo string `json:"pageno"` //页数
|
|
|
|
|
CountPerPage string `json:"countperpage"` //每页计数
|
|
|
|
|
TotalCounts string `json:"totalcounts"` //总条数
|
|
|
|
|
InputJSON InputJSON `json:"inputjson"` //输入参数
|
|
|
|
|
OutputJSON OutputJSON `json:"outputjson"` //输出参数
|
|
|
|
|
TimeFilter TimeFilter `json:"timefilter"` //本次查询时间区间
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type InputJSON struct {
|
|
|
|
|
SrcZoneName string `json:"srczonename"` //源安全域
|
|
|
|
|
DestZoneName string `json:"destzonename"` //目的安全域
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OutputJSON struct {
|
|
|
|
|
SrcPort string `json:"srcport"` //源端口
|
|
|
|
|
DestPort string `json:"destport"` //目的端口
|
|
|
|
|
Action string `json:"Action"`
|
|
|
|
|
AttackCount string `json:"attackcount"` //攻击计数
|
|
|
|
|
SrcVrfIndex string `json:"srcvrfindex"`
|
|
|
|
|
ThreatID string `json:"threatid"`
|
|
|
|
|
Severity string `json:"severity"`
|
|
|
|
|
HddInfo string `json:"hddinfo"`
|
|
|
|
|
Application string `json:"application"` //应用协议
|
|
|
|
|
ThreatName string `json:"threatname"` //威胁名称
|
|
|
|
|
SrcRegion string `json:"srcregion"` //源区域
|
|
|
|
|
DestRegion string `json:"destregion"` //目的区域
|
|
|
|
|
ThreatType string `json:"threattype"` //威胁类型 {入侵防御}
|
|
|
|
|
Time string `json:"time"` //时间
|
|
|
|
|
ContextName string `json:"contextname"` //上下文名称
|
|
|
|
|
Policy string `json:"policy"` //策略
|
|
|
|
|
Protocol string `json:"protocol"` //传输协议
|
|
|
|
|
SrcIPAddr string `json:"srcipaddr"` //源IP
|
|
|
|
|
User string `json:"user"` //用户
|
|
|
|
|
DestIPAddr string `json:"destipaddr"` //目的IP
|
|
|
|
|
SrcZoneName string `json:"srczonename"` //源安全域
|
|
|
|
|
DestZoneName string `json:"destzonename"` //目的安全域
|
|
|
|
|
CVE string `json:"cve"` //漏洞披露
|
|
|
|
|
MSB string `json:"msb"`
|
|
|
|
|
BID string `json:"bid"`
|
|
|
|
|
RealIP string `json:"realip"`
|
|
|
|
|
CapturePktName string `json:"capturepktname"`
|
|
|
|
|
HttpHost string `json:"httphost"` //host头
|
|
|
|
|
HttpFirstLine string `json:"httpfirstline"` //请求路径
|
|
|
|
|
Payload string `json:"payload"` //请求数据
|
|
|
|
|
MethodName string `json:"methodname"` //方法名称
|
|
|
|
|
MethodNameCN string `json:"methodnamecn"` //方法名称中国(攻击类别)
|
|
|
|
|
MethodSubName string `json:"methodsubname"` //方法子名称
|
|
|
|
|
MethodSubNameCN string `json:"methodsubnamecn"` //方法子名称中国(具体攻击形式)
|
|
|
|
|
LoginUserName string `json:"loginusername"`
|
|
|
|
|
LoginPassword string `json:"loginpassword"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TimeFilter struct {
|
|
|
|
|
StartTime string `json:"starttime"`
|
|
|
|
|
EndTime string `json:"endtime"`
|
|
|
|
|
}
|