Documentation
¶
Overview ¶
model/ip_info.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppConfig ¶
type AppConfig struct {
Name string `bson:"name" json:"name" example:"default" description:"应用名称"`
Directives string `bson:"directives" json:"directives" description:"Coraza指令"`
TransactionTTL time.Duration `bson:"transactionTTL" json:"transactionTTL" example:"10s" description:"事务超时时间"`
LogLevel string `bson:"logLevel" json:"logLevel" example:"info" description:"日志级别"`
LogFile string `bson:"logFile" json:"logFile" example:"/var/log/waf.log" description:"日志文件路径"`
LogFormat string `bson:"logFormat" json:"logFormat" example:"json" description:"日志格式"`
}
AppConfig 应用配置
@Description WAF应用配置
type BlockedIPRecord ¶
type BlockedIPRecord struct {
IP string `bson:"ip" json:"ip" example:"192.168.1.1" description:"被封禁的IP地址"`
Reason string `bson:"reason" json:"reason" example:"high_frequency_attack" description:"封禁原因"`
RequestUri string `bson:"request_uri" json:"requestUri" example:"/api/v1/login" description:"请求URI"`
BlockedAt time.Time `bson:"blocked_at" json:"blockedAt" description:"封禁开始时间"`
BlockedUntil time.Time `bson:"blocked_until" json:"blockedUntil" description:"封禁结束时间"`
}
BlockedIPRecord IP封禁记录 @Description 被封禁的IP记录信息
func (*BlockedIPRecord) GetCollectionName ¶
func (b *BlockedIPRecord) GetCollectionName() string
type Config ¶
type Config struct {
Name string `bson:"name" json:"name" example:"AppConfig" description:"配置名称"`
Engine EngineConfig `bson:"engine" json:"engine" description:"引擎配置"`
Haproxy HaproxyConfig `bson:"haproxy" json:"haproxy" description:"HAProxy配置"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt" description:"创建时间"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt" description:"更新时间"`
IsResponseCheck bool `bson:"isResponseCheck" json:"isResponseCheck" description:"是否检查响应"`
IsDebug bool `bson:"isDebug" json:"isDebug" description:"是否开启调试模式"`
IsK8s bool `bson:"isK8s" json:"isK8s" description:"是否在K8s环境"`
}
Config WAF系统配置
@Description WAF系统全局配置信息
func (*Config) GetCollectionName ¶
GetCollectionName 获取集合名称
@Summary 获取MongoDB集合名称 @Description 获取配置在MongoDB中的集合名称 @Return string 集合名称
type EngineConfig ¶
type EngineConfig struct {
Bind string `bson:"bind" json:"bind" example:"0.0.0.0:9000" description:"绑定地址"`
UseBuiltinRules bool `bson:"useBuiltinRules" json:"useBuiltinRules" description:"是否使用内置规则"`
ASNDBPath string `bson:"asnDBPath" json:"asnDBPath" example:"/opt/geoip/GeoLite2-ASN.mmdb" description:"ASN数据库路径"`
CityDBPath string `bson:"cityDBPath" json:"cityDBPath" example:"/opt/geoip/GeoLite2-City.mmdb" description:"城市数据库路径"`
AppConfig []AppConfig `bson:"appConfig" json:"appConfig" description:"应用配置列表"`
FlowController FlowControlConfig `bson:"flowController" json:"flowController" description:"流量控制配置"`
}
EngineConfig 引擎配置
@Description WAF引擎配置信息
type FlowControlConfig ¶
type FlowControlConfig struct {
// 高频访问限制配置
VisitLimit struct {
Enabled bool `bson:"enabled" json:"enabled" example:"true" description:"是否启用访问限制"`
Threshold int64 `bson:"threshold" json:"threshold" example:"100" description:"访问阈值,每分钟最大请求数"`
StatDuration int64 `bson:"statDuration" json:"statDuration" example:"60" description:"统计时间窗口(秒)"`
BlockDuration int64 `bson:"blockDuration" json:"blockDuration" example:"600" description:"封禁时长(秒)"`
BurstCount int64 `bson:"burstCount" json:"burstCount" example:"10" description:"允许的突发请求数"`
ParamsCapacity int64 `bson:"paramsCapacity" json:"paramsCapacity" example:"10000" description:"缓存容量,最多缓存IP数"`
} `bson:"visitLimit" json:"visitLimit" description:"访问频率限制配置"`
// 高频攻击限制配置
AttackLimit struct {
Enabled bool `bson:"enabled" json:"enabled" example:"true" description:"是否启用攻击限制"`
Threshold int64 `bson:"threshold" json:"threshold" example:"5" description:"攻击阈值,每分钟最大攻击次数"`
StatDuration int64 `bson:"statDuration" json:"statDuration" example:"60" description:"统计时间窗口(秒)"`
BlockDuration int64 `bson:"blockDuration" json:"blockDuration" example:"3600" description:"封禁时长(秒)"`
BurstCount int64 `bson:"burstCount" json:"burstCount" example:"2" description:"允许的突发攻击次数"`
ParamsCapacity int64 `bson:"paramsCapacity" json:"paramsCapacity" example:"10000" description:"缓存容量,最多缓存IP数"`
} `bson:"attackLimit" json:"attackLimit" description:"攻击频率限制配置"`
// 高频错误限制配置
ErrorLimit struct {
Enabled bool `bson:"enabled" json:"enabled" example:"true" description:"是否启用错误限制"`
Threshold int64 `bson:"threshold" json:"threshold" example:"20" description:"错误阈值,每分钟最大错误次数"`
StatDuration int64 `bson:"statDuration" json:"statDuration" example:"60" description:"统计时间窗口(秒)"`
BlockDuration int64 `bson:"blockDuration" json:"blockDuration" example:"1800" description:"封禁时长(秒)"`
BurstCount int64 `bson:"burstCount" json:"burstCount" example:"5" description:"允许的突发错误次数"`
ParamsCapacity int64 `bson:"paramsCapacity" json:"paramsCapacity" example:"10000" description:"缓存容量,最多缓存IP数"`
} `bson:"errorLimit" json:"errorLimit" description:"错误频率限制配置"`
}
FlowControlConfig 定义流控配置,用于存储在数据库中
@Description WAF流量控制配置
func GetDefaultFlowControlConfig ¶
func GetDefaultFlowControlConfig() FlowControlConfig
GetDefaultFlowControlConfig 返回默认的流控配置
@Summary 获取默认流控配置 @Description 获取系统预设的默认流量控制配置 @Return FlowControlConfig 默认流控配置
type HaproxyConfig ¶
type HaproxyConfig struct {
ConfigBaseDir string `bson:"configBaseDir" json:"configBaseDir" example:"/etc/haproxy" description:"配置基础目录"`
HaproxyBin string `bson:"haproxyBin" json:"haproxyBin" example:"/usr/sbin/haproxy" description:"HAProxy可执行文件路径"`
BackupsNumber int `bson:"backupsNumber" json:"backupsNumber" example:"5" description:"备份数量"`
SpoeAgentAddr string `bson:"spoeAgentAddr" json:"spoeAgentAddr" example:"127.0.0.1" description:"SPOE代理地址"`
SpoeAgentPort int `bson:"spoeAgentPort" json:"spoeAgentPort" example:"9000" description:"SPOE代理端口"`
Thread int `bson:"thread" json:"thread" example:"4" description:"线程数"`
}
HaproxyConfig HAProxy配置
@Description HAProxy相关配置
type IPGroup ¶
type IPGroup struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id,omitempty" example:"60d21b4367d0d8992e89e964"` // 组唯一标识符
Name string `bson:"name" json:"name" example:"内部服务器"` // 组名称
Items []string `bson:"items" json:"items" example:"['192.168.1.1', '10.0.0.1/24']"` // IP地址或CIDR列表
}
IPGroup 表示IP地址组信息 @Description IP地址组信息,包含组名和IP地址列表
func (*IPGroup) GetCollectionName ¶
type IPInfo ¶
type IPInfo struct {
City struct {
NameZH string `json:"nameZh" bson:"nameZh" example:"杭州"` // 城市中文名称
NameEN string `json:"nameEn" bson:"nameEn" example:"Hangzhou"` // 城市英文名称
} `json:"city" bson:"city"`
Subdivision struct {
NameZH string `json:"nameZh" bson:"nameZh" example:"浙江"` // 省/州中文名称
NameEN string `json:"nameEn" bson:"nameEn" example:"Zhejiang"` // 省/州英文名称
IsoCode string `json:"isoCode" bson:"isoCode" example:"ZJ"` // 省/州代码
} `json:"subdivision" bson:"subdivision"`
Country struct {
NameZH string `json:"nameZh" bson:"nameZh" example:"中国"` // 国家中文名称
NameEN string `json:"nameEn" bson:"nameEn" example:"China"` // 国家英文名称
IsoCode string `json:"isoCode" bson:"isoCode" example:"CN"` // 国家ISO代码
} `json:"country" bson:"country"`
Continent struct {
NameZH string `json:"nameZh" bson:"nameZh" example:"亚洲"` // 大洲中文名称
NameEN string `json:"nameEn" bson:"nameEn" example:"Asia"` // 大洲英文名称
} `json:"continent" bson:"continent"`
Location struct {
Longitude float64 `json:"longitude" bson:"longitude" example:"120.1663"` // 经度
Latitude float64 `json:"latitude" bson:"latitude" example:"30.2943"` // 纬度
TimeZone string `json:"timeZone" bson:"timeZone" example:"Asia/Shanghai"` // 时区
} `json:"location" bson:"location"`
ASN struct {
Number uint `json:"number" bson:"number" example:"4134"` // ASN号码
Organization string `json:"organization" bson:"organization" example:"China Telecom"` // 组织名称
} `json:"asn" bson:"asn"`
}
IPInfo 表示IP地址的地理位置信息 @Description IP地址地理位置详细信息,包含城市、区域、国家和ASN等数据
type Log ¶
type Log struct {
Message string `json:"message" bson:"message" example:"恶意扫描器检测"` // 日志消息
Payload string `json:"payload" bson:"payload" example:"Scanner/1.0"` // 攻击载荷
RuleID int `json:"ruleId" bson:"ruleId" example:"10086"` // 规则ID
Severity int `json:"severity" bson:"severity" example:"2"` // 严重级别(0-5)
Phase int `json:"phase" bson:"phase" example:"1"` // 请求处理阶段
SecMark string `json:"secMark" bson:"secMark" example:"web_scanner"` // 安全标记
Accuracy int `json:"accuracy" bson:"accuracy" example:"9"` // 规则匹配准确度(0-10)
SecLangRaw string `` // 安全规则原始定义
/* 140-byte string literal not displayed */
LogRaw string `` // 原始日志数据
/* 291-byte string literal not displayed */
}
Log 表示单个日志条目 @Description 详细的WAF规则匹配记录,包含规则触发的详细信息和原始日志
type MicroRule ¶
type MicroRule struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id,omitempty" example:"60d21b4367d0d8992e89e964"` // 规则唯一标识符
Name string `json:"name" bson:"name" example:"SQL注入防护规则"` // 规则名称
Type RuleType `json:"type" bson:"type" example:"blacklist"` // 规则类型
Status RuleStatus `json:"status" bson:"status" example:"enabled"` // 规则状态
Priority int `json:"priority" bson:"priority" example:"100"` // 优先级字段,数字越大优先级越高
// @Schema(type=object, example={"type":"composite","operator":"AND","conditions":[{"type":"simple","target":"source_ip","match_type":"in_ipgroup","match_value":"blocked_ips"},{"type":"simple","target":"path","match_type":"regex","match_value":"^/admin/.*$"}]})
Condition bson.Raw `json:"condition" bson:"condition" swaggertype:"object"`
}
MicroRule 表示WAF微规则信息 @Description WAF微规则信息,包含规则名称、类型、状态、优先级和条件
func (*MicroRule) GetCollectionName ¶
type RuleStatus ¶
type RuleStatus string
RuleStatus 规则状态
@Description 规则状态,表示规则是启用还是禁用
const ( RuleEnabled RuleStatus = "enabled" // 规则已启用 RuleDisabled RuleStatus = "disabled" // 规则已禁用 )
type WAFLog ¶
type WAFLog struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // 日志唯一标识符
RequestID string `json:"requestId" bson:"requestId" example:"a1b2c3d4e5f6"` // 请求唯一标识
RuleID int `json:"ruleId" bson:"ruleId" example:"10086"` // 触发的规则ID
SecLangRaw string `` // 安全规则原始定义
/* 140-byte string literal not displayed */
Severity int `json:"severity" bson:"severity" example:"2"` // 事件严重级别(0-5)
Phase int `json:"phase" bson:"phase" example:"1"` // 请求处理阶段
SecMark string `json:"secMark" bson:"secMark" example:"web_scanner"` // 安全标记
Accuracy int `json:"accuracy" bson:"accuracy" example:"9"` // 规则匹配准确度(0-10)
Payload string `json:"payload" bson:"payload" example:"Scanner/1.0"` // 攻击载荷
URI string `json:"uri" bson:"uri" example:"/api/v1/users"` // 请求URI路径
SrcIP string `json:"srcIp" bson:"srcIp" example:"192.168.1.1"` // 来源IP地址
SrcIPInfo *IPInfo `json:"srcIpInfo,omitempty" bson:"srcIpInfo,omitempty"` // 来源IP地理位置信息
DstIP string `json:"dstIp" bson:"dstIp" example:"10.0.0.1"` // 目标IP地址
ClientIP string `json:"clientIp" bson:"clientIp" example:"192.168.1.1"` // 来源IP地址
ServerIP string `json:"serverIp" bson:"serverIp" example:"10.0.0.1"` // 目标IP地址
SrcPort int `json:"srcPort" bson:"srcPort" example:"52134"` // 来源端口
DstPort int `json:"dstPort" bson:"dstPort" example:"443"` // 目标端口
Domain string `json:"domain" bson:"domain" example:"api.example.com"` // 目标域名
Logs []Log `json:"logs" bson:"logs"` // 关联的日志条目
Message string `json:"message" bson:"message" example:"恶意扫描器检测"` // 事件描述消息
Request string `json:"request" bson:"request" example:"GET /api/v1/users HTTP/1.1\nHost: api.example.com\nUser-Agent: Scanner/1.0"` // 原始HTTP请求
Response string `json:"response" bson:"response" example:"HTTP/1.1 403 Forbidden\nContent-Type: text/html\nContent-Length: 146"` // 原始HTTP响应
Date string `json:"date" bson:"date"`
Hour int `json:"hour" bson:"hour"`
HourGroupSix int `json:"hourGroupSix" bson:"hourGroupSix" example:"0"`
Minute int `json:"minute" bson:"minute"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt" example:"2024-03-18T08:12:33Z"` // 事件发生时间戳
}
WAFLog 表示安全事件日志 @Description Web应用防火墙安全事件完整记录,包含详细的攻击检测和防护信息
func (*WAFLog) GetCollectionName ¶
GetCollectionName 返回WAFLog对应的MongoDB集合名称 @Description 获取用于存储WAF日志的MongoDB集合名
Click to show internal directories.
Click to hide internal directories.