types.go 13.4 KB
Newer Older
qiuqunfeng's avatar
qiuqunfeng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
package service

import "encoding/json"

type Intelligence struct {
	Source     string      `json:"source"`
	Confidence int         `json:"confidence"`
	Expired    bool        `json:"expired"`
	IntelTags  []TagsClass `json:"intel_tags"`
	FindTime   string      `json:"find_time"`
	IntelTypes []string    `json:"intel_types"`
	UpdateTime string      `json:"update_time"`
}

type OpenSource struct {
	Source     string      `json:"source"`
	Confidence int         `json:"confidence"`
	Expired    bool        `json:"expired"`
	IntelTags  []TagsClass `json:"intel_tags"`
	FindTime   string      `json:"find_time"`
	IntelTypes []string    `json:"intel_types"`
	UpdateTime string      `json:"update_time"`
}

type Location struct {
	Country     string `json:"country"`
	Province    string `json:"province"`
	City        string `json:"city"`
	Longitude   string `json:"lng"`
	Latitude    string `json:"lat"`
	CountryCode string `json:"country_code"`
}

type Basic struct {
	Carrier  string   `json:"carrier"`
	Location Location `json:"location"`
}

type ASN struct {
	Rank   int    `json:"rank"`
	Info   string `json:"info"`
	Number int    `json:"number"`
}

type Port struct {
	Port    int    `json:"port"`
	Module  string `json:"module"`
	Product string `json:"product"`
	Version string `json:"version"`
	Detail  string `json:"detail"`
}

type RDNS struct {
	RDNS    string `json:"rdns"`
	GetTime string `json:"get_time"`
}

type Intelligences struct {
	ThreatbookLab []Intelligence `json:"threatbook_lab"`
	XReward       []interface{}  `json:"x_reward"`
	OpenSource    []OpenSource   `json:"open_source"`
}

type Sample struct {
	Hash          string `json:"sha256"`
	ScanTime      string `json:"scan_time"`
	Ratio         string `json:"ratio"`
	MalwareType   string `json:"malware_type"`
	MalwareFamily string `json:"malware_family"`
}

type TagsClass struct {
	TagsType string   `json:"tags_type"` //标签类别,如"industry(行业)"、"gangs(团伙)"、"virus_family(家族)"等
	Tags     []string `json:"tags"`      //具体的攻击团伙或安全事件标签,例如:APT、海莲花等。
}

type CAS struct {
	Protocol           string      `json:"protocol"`
	Port               int16       `json:"port"`
	Period             int         `json:"period"`
	DigitalCertificate Certificate `json:"digital_certificate"`
}

type Certificate struct {
	Subject      string `json:"subject"`
	Issuer       string `json:"issuer"`
	Fingerprint  string `json:"fingerprint"`
	Purpose      string `json:"purpose"`
	Verify       string `json:"verify"`
	Status       string `json:"status"`
	Revoked      bool   `json:"revoked"`
	Begin        string `json:"begin"`
	End          string `json:"end"`
	StatusDesc   string `json:"status_desc"`
	SerialNumber string `json:"serial_number"`
	RevokedTime  string `json:"revoked_time"`
}

type IpInfo struct {
	Samples       []Sample      `json:"samples"`
	TagsClasses   []TagsClass   `json:"tags_classes"`
	Judgments     []string      `json:"judgments"`
	Intelligences Intelligences `json:"intelligences"`
	Scene         string        `json:"scene"`
	Basic         Basic         `json:"basic"`
	ASN           ASN           `json:"asn"`
	Ports         []Port        `json:"ports"`
	CAS           []CAS         `json:"cas"`
	UpdateTime    string        `json:"update_time"`
	RDNSList      []RDNS        `json:"rdns_list"`
	SumCurDomains string        `json:"sum_cur_domains"`
}

type RespData struct {
	Data         map[string]json.RawMessage `json:"data"`
	ResponseCode int                        `json:"response_code"`
	VerboseMsg   string                     `json:"verbose_msg"`
}

type Reputation struct {
	IsMalicious bool `json:"is_malicious"`
}

type ASNPrivate struct {
	Rank   int    `json:"rank"`
	Info   string `json:"info"`
	Number string `json:"number"`
}

type LocationPrivate struct {
	Country     string  `json:"country"`
	Province    string  `json:"province"`
	City        string  `json:"city"`
	Longitude   float64 `json:"lng"`
	Latitude    float64 `json:"lat"`
	CountryCode string  `json:"country_code"`
}

type BasicPrivate struct {
	Carrier  string          `json:"carrier"`
	Location LocationPrivate `json:"location"`
}

type TagsClassPrivate map[string][]string

type IPInfoPrivate struct {
	Judgments   []string         `json:"judgments"`
	Basic       BasicPrivate     `json:"basic"`
	ASN         ASNPrivate       `json:"asn"`
	Scene       string           `json:"scene"`
	IsMalicious bool             `json:"is_malicious"`
	TagsClasses TagsClassPrivate `json:"tags_classes"`
}

type IPInfoPrivateRespData struct {
	IOC          string          `json:"ioc"`
	Intelligence []IPInfoPrivate `json:"intelligence"`
}

type IPInfoPrivateResp struct {
	Data         []IPInfoPrivateRespData `json:"data"`
	ResponseCode int                     `json:"response_code"`
	VerboseMsg   string                  `json:"verbose_msg"`
}

qiuqunfeng's avatar
qiuqunfeng committed
166
type WafService struct {
167
	GatewayName string   `json:"gateway_name"`
168
	Name        string   `json:"name"`
169 170 171 172
	Mode        string   `json:"mode"`
	RuleNum     int      `json:"rule_num"`
	AttackNum   int      `json:"attack_num"`
	Listeners   []string `json:"listeners"`
qiuqunfeng's avatar
qiuqunfeng committed
173 174
} // WAF configuration details

qiuqunfeng's avatar
qiuqunfeng committed
175
type GatewateInfo struct {
176 177 178 179 180 181 182 183 184 185
	GatewayName   string `json:"gateway_name"`
	Namespace     string `json:"namespace"`
	RegionCode    string `json:"region_code"`
	ApiGatewayCrn string `json:"gateway_crn"`
	// Hosts         []string `json:"hosts"`
}

type GetWafGatewayInfoReq struct {
	GatewateInfo
	Cookie string `json:"cookie"`
qiuqunfeng's avatar
qiuqunfeng committed
186 187
}

qiuqunfeng's avatar
qiuqunfeng committed
188
type CreateWafReq struct {
qiuqunfeng's avatar
qiuqunfeng committed
189
	GatewateInfo
190 191 192 193
	Port         uint32   `json:"port"`
	Host         []string `json:"host"`
	Mode         WafMode  `json:"mode"`
	ListenerName string   `json:"listener_name"`
194
	ServiceID    uint32   `json:"service_id"`
qiuqunfeng's avatar
qiuqunfeng committed
195 196 197 198 199
}

type DeleteWafReq struct {
	GatewateInfo
	Ports []int `json:"ports"`
qiuqunfeng's avatar
qiuqunfeng committed
200 201 202
}

type RuleRequest struct {
qiuqunfeng's avatar
qiuqunfeng committed
203
	GatewateInfo
qiuqunfeng's avatar
qiuqunfeng committed
204 205 206
	CategoryID []string `json:"category_id"`
	Status     int      `json:"status"`
}
qiuqunfeng's avatar
commit  
qiuqunfeng committed
207

qiuqunfeng's avatar
qiuqunfeng committed
208 209 210 211 212 213 214 215
type WafMode string

const (
	WafModeProtect     WafMode = "protect"
	WafModeAlert       WafMode = "alert"
	WafModePassthrough WafMode = "passthrough"
)

qiuqunfeng's avatar
commit  
qiuqunfeng committed
216
type UpdateModeReq struct {
qiuqunfeng's avatar
qiuqunfeng committed
217 218 219 220 221 222 223 224
	Mode        WafMode `json:"mode"`
	GatewayName string  `json:"gateway_name"`
	Namespace   string  `json:"namespace"`
	RegionCode  string  `json:"region_code"`
}

type EnableListenerWafReq struct {
	GatewateInfo
225 226 227 228 229
	Enable       bool     `json:"enable"`
	Hosts        []string `json:"hosts"`
	Port         int      `json:"port"`
	Mode         WafMode  `json:"mode"`
	ListenerName string   `json:"listener_name"`
qiuqunfeng's avatar
qiuqunfeng committed
230 231 232 233
}

type EnableGatewayWafReq struct {
	GatewateInfo
234 235
	Enable bool   `json:"enable"`
	Cookie string `json:"cookie"`
qiuqunfeng's avatar
commit  
qiuqunfeng committed
236
}
qiuqunfeng's avatar
commit  
qiuqunfeng committed
237

238
type ListenerWaf struct {
239
	Hosts []string `json:"hosts"`
240 241 242
	// Port         int      `json:"port"`
	HostsAndPort string `json:"hosts_and_port"`
	Name         string `json:"name"`
243 244 245 246
}

type EnableListenerWafsReq struct {
	GatewateInfo
247 248
	Enable    bool          `json:"enable"`
	Listeners []ListenerWaf `json:"listeners"`
249 250
}

qiuqunfeng's avatar
commit  
qiuqunfeng committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
type WafRule struct {
	ID          int    `json:"id"`
	Level       int    `json:"level"`
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Expr        string `json:"expr"`
	Mode        string `json:"mode"`
}

type Catagory struct {
	EN string `json:"en"`
	Zh string `json:"zh"`
}

type Description struct {
	EN string `json:"en"`
	Zh string `json:"zh"`
}

type WafRuleCategory struct {
	CategoryID  string      `json:"category_id"`
	Status      int         `json:"status,omitempty"`
274
	Category    Catagory    `json:"category"`
qiuqunfeng's avatar
commit  
qiuqunfeng committed
275 276 277
	Description Description `json:"description"`
	Rules       []WafRule   `json:"rules"`
}
qiuqunfeng's avatar
qiuqunfeng committed
278

279 280 281 282 283 284 285
type RuleGroupResp struct {
	CategoryID  string `json:"category_id"`
	Category    string `json:"category"`
	Description string `json:"description"`
	Status      int    `json:"status"`
}

qiuqunfeng's avatar
qiuqunfeng committed
286
type GatewayListener struct {
287 288 289 290 291 292
	GatewayName string   `json:"gateway_name"`
	Namespace   string   `json:"namespace"`
	RegionCode  string   `json:"region_code"`
	Hosts       []string `json:"hosts"`
	Port        int      `json:"port"`
	Enable      bool     `json:"enable"`
qiuqunfeng's avatar
qiuqunfeng committed
293 294 295 296 297 298 299 300 301
}

type CreateListenerReq struct {
	GatewateInfo
	Port int `json:"port"`
}

type DeleteListenerReq struct {
	GatewateInfo
302 303
	Port         int    `json:"port"`
	ListenerName string `json:"listener_name"`
qiuqunfeng's avatar
qiuqunfeng committed
304
}
305 306 307 308 309 310 311 312 313 314 315 316 317

type GatewayRespListenerData struct {
	GatewayName       string   `json:"gateway_name"`
	Namespace         string   `json:"namespace"`
	ListenerName      string   `json:"listener_name"`
	ApiGatewayCrn     string   `json:"apigateway_crn"`
	CreateAccountName string   `json:"create_account_name"`
	CreateAccountID   string   `json:"create_account_id"`
	Hosts             []string `json:"hosts"`
	Port              int      `json:"port"`
}

type GatewayResponseBase struct {
318
	Code    string `json:"code"`
319 320 321 322 323 324 325 326 327 328 329 330
	Message string `json:"message"`
}

type GatewayListenerResponse struct {
	GatewayResponseBase
	Data GatewayRespListenerData `json:"data"`
}

type GatewayListenerResponseList struct {
	GatewayResponseBase
	Data []GatewayRespListenerData `json:"data"`
}
331 332

type AttackLog struct {
333 334 335 336 337 338 339
	Uuid           string `json:"uuid"`
	AttackIp       string `json:"attack_ip"`
	AttackedAddr   string `json:"attacked_addr"`
	AttackType     string `json:"attack_type"`
	AttackTime     int64  `json:"attack_time"`
	AttackedApp    string `json:"attacked_app"`
	AttackListener string `json:"attack_listener"`
340
	AttackLoad     string `json:"attack_load"`
341 342
	ClusterKey     string `json:"cluster_key"`
	Action         string `json:"action"`
343
	RuleName       string `json:"rule_name"`
344
	RequestPkg     string `json:"req_pkg"`
345 346
}

347 348 349 350 351 352
type AttackRsp struct {
	Uuid        string `json:"uuid"`
	Intact      bool   `json:"intact"`
	ContentType string `json:"content_type"`
	RspPkg      string `json:"rspPkg"`
}
353
type AttackLogFilter struct {
354 355 356 357 358 359 360
	Offset         int    `json:"offset"`
	Limit          int    `json:"limit"`
	ServiceId      int64  `json:"service_id"`
	Cluster        string `json:"cluster"`
	AttackUrl      string `json:"attack_url"`
	AttackIp       string `json:"attack_ip"`
	AttackType     string `json:"attack_type"`
361
	AttackApp      string `json:"attack_app"` // gateway name
362 363 364 365 366
	AttackListener string `json:"attack_listener"`
	Action         string `json:"action"`
	Token          string `json:"token"`
	StartTime      int64  `json:"start_time"`
	EndTime        int64  `json:"end_time"`
367
}
368 369 370 371 372 373 374 375 376 377 378

type MatcherExpr struct {
	ID        uint32   `json:"id"`
	Name      string   `json:"name,omitempty"`
	Scope     []uint32 `json:"scope,omitempty"`
	ScopeName []string `json:"scope_name,omitempty"`
	Mode      string   `json:"mode,omitempty"`
	Expr      string   `json:"expr,omitempty"`
	Global    bool     `json:"global"`
	Status    int32    `json:"status"`
}
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417

type MatchExprQueryOption struct {
	WhereLikeCondition map[string]string
	whereEqCondition   map[string]interface{}
	whereInCondition   map[string]interface{}
}

func MatchExprQuery() *MatchExprQueryOption {
	return &MatchExprQueryOption{
		WhereLikeCondition: make(map[string]string, 3),
		whereEqCondition:   make(map[string]interface{}, 3),
		whereInCondition:   make(map[string]interface{}, 3),
	}
}

func (n *MatchExprQueryOption) WithFuzzyName(name string) *MatchExprQueryOption {
	n.WhereLikeCondition["name"] = name
	return n
}

func (n *MatchExprQueryOption) WithFuzzyExpr(expr string) *MatchExprQueryOption {
	n.WhereLikeCondition["expr"] = expr
	return n
}

func (n *MatchExprQueryOption) WithStatus(status int32) *MatchExprQueryOption {
	n.whereEqCondition["status"] = status
	return n
}

func (n *MatchExprQueryOption) WithMode(mode string) *MatchExprQueryOption {
	n.whereEqCondition["mode"] = mode
	return n
}

func (q *MatchExprQueryOption) WithInConditionCustom(column string, value interface{}) *MatchExprQueryOption {
	q.whereInCondition[column] = value
	return q
}
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471

type WafListenerHistory struct {
	Name         string `json:"name"`
	GatewayName  string `json:"gateway_name"`
	ListenerName string `json:"listener_name"`
	Namespace    string `json:"namespace"`
	RegionCode   string `json:"region_code"`
	Description  string `json:"description"`
	Status       int    `json:"status"`
	Operation    string `json:"operation"`
}
type WafListenerHistoryOption struct {
	WhereLikeCondition map[string]string
	WhereEqCondition   map[string]interface{}
	WhereInCondition   map[string]interface{}
}

func WafListenerHistoryQuery() *WafListenerHistoryOption {
	return &WafListenerHistoryOption{
		WhereLikeCondition: make(map[string]string, 3),
		WhereEqCondition:   make(map[string]interface{}, 3),
		WhereInCondition:   make(map[string]interface{}, 3),
	}
}

func (n *WafListenerHistoryOption) WithFuzzyName(name string) *WafListenerHistoryOption {
	n.WhereLikeCondition["name"] = name
	return n
}

func (n *WafListenerHistoryOption) WithFuzzyListenerName(listenerName string) *WafListenerHistoryOption {
	n.WhereLikeCondition["listener_name"] = listenerName
	return n
}

func (n *WafListenerHistoryOption) WithFuzzyGatewayName(gatewayName string) *WafListenerHistoryOption {
	n.WhereLikeCondition["gateway_name"] = gatewayName
	return n
}

func (n *WafListenerHistoryOption) WithStatus(status int32) *WafListenerHistoryOption {
	n.WhereEqCondition["status"] = status
	return n
}

func (n *WafListenerHistoryOption) WithOperation(operation string) *WafListenerHistoryOption {
	n.WhereEqCondition["operation"] = operation
	return n
}

func (n *WafListenerHistoryOption) WithFuzzyRegionCode(regionCode string) *WafListenerHistoryOption {
	n.WhereLikeCondition["region_code"] = regionCode
	return n
}
472 473 474 475 476 477 478

type AttackClasses struct {
	Id         int    `json:"id"`
	En         string `json:"en,omitempty"`
	Describe   string `json:"describe"`
	AttackType string `json:"type"`
}