Commit c38228a3 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Add attack classes endpoint and service implementation

- Introduce a new GET endpoint for listing attack classes in the WAF router.
- Implement AttackClassesList method in WafController to handle requests and return attack class data based on the specified language.
- Enhance the WAF service with ListAttackClasses method to retrieve attack classes and support localization for descriptions.
- Define AttackClasses struct to standardize the response format for attack class data.
parent f77ce263
......@@ -35,5 +35,6 @@ func SetWafRouter(e *gin.Engine, clusterClientManager *utils.ClusterClientManage
v2.DELETE("blackwhitelist/:id", wafController.DeleteBlackWhiteList)
v2.GET("blackwhitelists", wafController.GetBlackWhiteLists)
v2.GET("services", wafController.ListWafs)
v2.GET("attack/classes", wafController.AttackClassesList)
}
......@@ -552,3 +552,22 @@ func (c *WafController) ListListenerHistory(ctx *gin.Context) {
}
utils.AssembleResponse(ctx, respData, nil)
}
func (c *WafController) AttackClassesList(ctx *gin.Context) {
ctx1, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
language := ctx.Request.Header.Get("Accept-Language")
if language == "" {
language = "zh"
}
classes := c.service.ListAttackClasses(ctx1, language)
respData := utils.ListRespData{
Items: classes,
TotalItems: len(classes),
ItemsPerPage: 10,
}
utils.AssembleResponse(ctx, respData, nil)
}
......@@ -27,4 +27,5 @@ type Service interface {
DeleteBlackWhiteList(ctx context.Context, ID uint32) error
GetBlackWhiteLists(ctx context.Context, query *MatchExprQueryOption, limit int, offset int) ([]MatcherExpr, int, error)
ListListenerHistory(ctx context.Context, query *WafListenerHistoryOption, limit, offset int) ([]model.WafListenerHistory, int, error)
ListAttackClasses(ctx context.Context, lang string) []AttackClasses
}
......@@ -460,3 +460,10 @@ func (n *WafListenerHistoryOption) WithFuzzyRegionCode(regionCode string) *WafLi
n.WhereLikeCondition["region_code"] = regionCode
return n
}
type AttackClasses struct {
Id int `json:"id"`
En string `json:"en,omitempty"`
Describe string `json:"describe"`
AttackType string `json:"type"`
}
......@@ -27,6 +27,29 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)
var DefAttackClass = []AttackClasses{{1, "Remote Command Execution", "远程代码执行", "RCE_OS"},
{2, "SQL Injection", "SQL注入", "SQLI"},
{3, "Cross-Site Scripting", "跨站脚本攻击", "XSS"},
{4, "Access of Internal Components", "内部组件访问", "AOIC"},
{5, "Directory Traversal", "路径穿越", "DT"},
{6, "Data Leakage", "数据泄露", "DL"},
{7, "Source Code Disclosure", "源码泄露", "SCD"},
{8, "Php remote code execution", "PHP远程代码执行", "RCE_PHP"},
{9, "Java remote code execution", "JAVA远程代码执行", "RCE_JAVA"},
{10, "Local file include", "本地文件包含", "LFI"},
{11, "Remote file include", "远程文件包含", "RFI"},
{12, "Url Redirect", "URL重定向(CVE)", "UR"},
{13, "DOS", "DOS攻击", "DOS"},
{14, "Unauthorized File Upload", "未授权文件上传", "UFL"},
{15, "General Rule", "一般文件规则", "GR"},
{16, "Site Scanning/Probing", "网站扫描/探测", "SS"},
{17, "Server-side request forgery", "跨站请求伪造", "SSRF"},
{18, "Famous application vulnerable", "针对知名应用的针对性规则", "FAPPV"},
{19, "Other", "其它", "Other"},
{20, "blacklist", "黑名单", "black"},
{21, "whitelist", "白名单", "white"},
{22, "strong whitelist", "强白名单", "force-white"}}
type wafService struct {
clusterClientManager *utils.ClusterClientManager
db *gorm.DB
......@@ -1327,3 +1350,25 @@ func (s *wafService) addListenerHistory(ctx context.Context, name, listenerName,
}
return nil
}
func (s *wafService) ListAttackClasses(ctx context.Context, lang string) []AttackClasses {
var attackClass []AttackClasses
isEn := true
if lang == "zh" {
isEn = false
}
for i := 0; i < len(DefAttackClass); i++ {
value := AttackClasses{
Id: DefAttackClass[i].Id,
Describe: DefAttackClass[i].Describe,
AttackType: DefAttackClass[i].AttackType,
}
if isEn {
value.Describe = DefAttackClass[i].En
}
attackClass = append(attackClass, value)
}
return attackClass
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment