github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/utils.go (about)

     1  package checkpoints
     2  
     3  // AllCheckpoints all check points list
     4  var AllCheckpoints = []*CheckpointDefinition{
     5  	{
     6  		Name:        "通用请求Header长度限制",
     7  		Prefix:      "requestGeneralHeaderLength",
     8  		Description: "通用Header比如Cache-Control、Accept之类的长度限制,防止缓冲区溢出攻击",
     9  		HasParams:   false,
    10  		Instance:    new(RequestGeneralHeaderLengthCheckpoint),
    11  		Priority:    100,
    12  	},
    13  	{
    14  		Name:        "客户端地址(IP)",
    15  		Prefix:      "remoteAddr",
    16  		Description: "试图通过分析X-Forwarded-For等Header获取的客户端地址,比如192.168.1.100",
    17  		HasParams:   false,
    18  		Instance:    new(RequestRemoteAddrCheckpoint),
    19  		Priority:    100,
    20  	},
    21  	{
    22  		Name:        "客户端源地址(IP)",
    23  		Prefix:      "rawRemoteAddr",
    24  		Description: "直接连接的客户端地址,比如192.168.1.100",
    25  		HasParams:   false,
    26  		Instance:    new(RequestRawRemoteAddrCheckpoint),
    27  		Priority:    100,
    28  	},
    29  	{
    30  		Name:        "客户端端口",
    31  		Prefix:      "remotePort",
    32  		Description: "直接连接的客户端地址端口",
    33  		HasParams:   false,
    34  		Instance:    new(RequestRemotePortCheckpoint),
    35  		Priority:    100,
    36  	},
    37  	{
    38  		Name:        "客户端用户名",
    39  		Prefix:      "remoteUser",
    40  		Description: "通过BasicAuth登录的客户端用户名",
    41  		HasParams:   false,
    42  		Instance:    new(RequestRemoteUserCheckpoint),
    43  		Priority:    100,
    44  	},
    45  	{
    46  		Name:        "请求URI",
    47  		Prefix:      "requestURI",
    48  		Description: "包含URL参数的请求URI,类似于 /hello/world?lang=go",
    49  		HasParams:   false,
    50  		Instance:    new(RequestURICheckpoint),
    51  		Priority:    100,
    52  	},
    53  	{
    54  		Name:        "请求路径",
    55  		Prefix:      "requestPath",
    56  		Description: "不包含URL参数的请求路径,类似于 /hello/world",
    57  		HasParams:   false,
    58  		Instance:    new(RequestPathCheckpoint),
    59  		Priority:    100,
    60  	},
    61  	{
    62  		Name:        "请求URL",
    63  		Prefix:      "requestURL",
    64  		Description: "完整的请求URL,包含协议、域名、请求路径、参数等,类似于 https://example.com/hello?name=lily",
    65  		HasParams:   false,
    66  		Instance:    new(RequestURLCheckpoint),
    67  		Priority:    100,
    68  	},
    69  	{
    70  		Name:        "请求内容长度",
    71  		Prefix:      "requestLength",
    72  		Description: "请求Header中的Content-Length",
    73  		HasParams:   false,
    74  		Instance:    new(RequestLengthCheckpoint),
    75  		Priority:    100,
    76  	},
    77  	{
    78  		Name:        "请求体内容",
    79  		Prefix:      "requestBody",
    80  		Description: "通常在POST或者PUT等操作时会附带请求体,最大限制32M",
    81  		HasParams:   false,
    82  		Instance:    new(RequestBodyCheckpoint),
    83  		Priority:    5,
    84  	},
    85  	{
    86  		Name:        "请求URI和请求体组合",
    87  		Prefix:      "requestAll",
    88  		Description: "${requestURI}和${requestBody}组合",
    89  		HasParams:   false,
    90  		Instance:    new(RequestAllCheckpoint),
    91  		Priority:    5,
    92  	},
    93  	{
    94  		Name:        "请求表单参数",
    95  		Prefix:      "requestForm",
    96  		Description: "获取POST或者其他方法发送的表单参数,最大请求体限制32M",
    97  		HasParams:   true,
    98  		Instance:    new(RequestFormArgCheckpoint),
    99  		Priority:    5,
   100  	},
   101  	{
   102  		Name:        "上传文件",
   103  		Prefix:      "requestUpload",
   104  		Description: "获取POST上传的文件信息,最大请求体限制32M",
   105  		HasParams:   true,
   106  		Instance:    new(RequestUploadCheckpoint),
   107  		Priority:    20,
   108  	},
   109  	{
   110  		Name:        "请求JSON参数",
   111  		Prefix:      "requestJSON",
   112  		Description: "获取POST或者其他方法发送的JSON,最大请求体限制32M,使用点(.)符号表示多级数据",
   113  		HasParams:   true,
   114  		Instance:    new(RequestJSONArgCheckpoint),
   115  		Priority:    5,
   116  	},
   117  	{
   118  		Name:        "请求方法",
   119  		Prefix:      "requestMethod",
   120  		Description: "比如GET、POST",
   121  		HasParams:   false,
   122  		Instance:    new(RequestMethodCheckpoint),
   123  		Priority:    100,
   124  	},
   125  	{
   126  		Name:        "请求协议",
   127  		Prefix:      "scheme",
   128  		Description: "比如http或https",
   129  		HasParams:   false,
   130  		Instance:    new(RequestSchemeCheckpoint),
   131  		Priority:    100,
   132  	},
   133  	{
   134  		Name:        "HTTP协议版本",
   135  		Prefix:      "proto",
   136  		Description: "比如HTTP/1.1",
   137  		HasParams:   false,
   138  		Instance:    new(RequestProtoCheckpoint),
   139  		Priority:    100,
   140  	},
   141  	{
   142  		Name:        "主机名",
   143  		Prefix:      "host",
   144  		Description: "比如teaos.cn",
   145  		HasParams:   false,
   146  		Instance:    new(RequestHostCheckpoint),
   147  		Priority:    100,
   148  	},
   149  	{
   150  		Name:        "CNAME",
   151  		Prefix:      "cname",
   152  		Description: "当前网站服务CNAME,比如38b48e4f.goedge.cn",
   153  		HasParams:   false,
   154  		Instance:    new(RequestCNAMECheckpoint),
   155  		Priority:    100,
   156  	},
   157  	{
   158  		Name:        "是否为CNAME",
   159  		Prefix:      "isCNAME",
   160  		Description: "是否为CNAME,值为1(是)或0(否)",
   161  		HasParams:   false,
   162  		Instance:    new(RequestIsCNAMECheckpoint),
   163  		Priority:    100,
   164  	},
   165  	{
   166  		Name:        "请求来源",
   167  		Prefix:      "refererOrigin",
   168  		Description: "请求报头中的Referer或Origin值",
   169  		HasParams:   false,
   170  		Instance:    new(RequestRefererOriginCheckpoint),
   171  		Priority:    100,
   172  	},
   173  	{
   174  		Name:        "请求来源Referer",
   175  		Prefix:      "referer",
   176  		Description: "请求Header中的Referer值",
   177  		HasParams:   false,
   178  		Instance:    new(RequestRefererCheckpoint),
   179  		Priority:    100,
   180  	},
   181  	{
   182  		Name:        "客户端信息",
   183  		Prefix:      "userAgent",
   184  		Description: "比如Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103",
   185  		HasParams:   false,
   186  		Instance:    new(RequestUserAgentCheckpoint),
   187  		Priority:    100,
   188  	},
   189  	{
   190  		Name:        "内容类型",
   191  		Prefix:      "contentType",
   192  		Description: "请求Header的Content-Type",
   193  		HasParams:   false,
   194  		Instance:    new(RequestContentTypeCheckpoint),
   195  		Priority:    100,
   196  	},
   197  	{
   198  		Name:        "所有cookie组合字符串",
   199  		Prefix:      "cookies",
   200  		Description: "比如sid=IxZVPFhE&city=beijing&uid=18237",
   201  		HasParams:   false,
   202  		Instance:    new(RequestCookiesCheckpoint),
   203  		Priority:    100,
   204  	},
   205  	{
   206  		Name:        "单个cookie值",
   207  		Prefix:      "cookie",
   208  		Description: "单个cookie值",
   209  		HasParams:   true,
   210  		Instance:    new(RequestCookieCheckpoint),
   211  		Priority:    100,
   212  	},
   213  	{
   214  		Name:        "所有URL参数组合",
   215  		Prefix:      "args",
   216  		Description: "比如name=lu&age=20",
   217  		HasParams:   false,
   218  		Instance:    new(RequestArgsCheckpoint),
   219  		Priority:    100,
   220  	},
   221  	{
   222  		Name:        "单个URL参数值",
   223  		Prefix:      "arg",
   224  		Description: "单个URL参数值",
   225  		HasParams:   true,
   226  		Instance:    new(RequestArgCheckpoint),
   227  		Priority:    100,
   228  	},
   229  	{
   230  		Name:        "所有Header信息",
   231  		Prefix:      "headers",
   232  		Description: "使用\\n隔开的Header信息字符串",
   233  		HasParams:   false,
   234  		Instance:    new(RequestHeadersCheckpoint),
   235  		Priority:    100,
   236  	},
   237  	{
   238  		Name:        "所有请求报头名称",
   239  		Prefix:      "headerNames",
   240  		Description: "使用换行符(\\n)隔开的报头名称字符串,每行一个名称",
   241  		HasParams:   false,
   242  		Instance:    new(RequestHeaderNamesCheckpoint),
   243  		Priority:    100,
   244  	},
   245  	{
   246  		Name:        "单个Header值",
   247  		Prefix:      "header",
   248  		Description: "单个Header值",
   249  		HasParams:   true,
   250  		Instance:    new(RequestHeaderCheckpoint),
   251  		Priority:    100,
   252  	},
   253  	{
   254  		Name:        "国家/地区名称",
   255  		Prefix:      "geoCountryName",
   256  		Description: "国家/地区名称",
   257  		HasParams:   false,
   258  		Instance:    new(RequestGeoCountryNameCheckpoint),
   259  		Priority:    90,
   260  	},
   261  	{
   262  		Name:        "省份名称",
   263  		Prefix:      "geoProvinceName",
   264  		Description: "中国省份名称",
   265  		HasParams:   false,
   266  		Instance:    new(RequestGeoProvinceNameCheckpoint),
   267  		Priority:    90,
   268  	},
   269  	{
   270  		Name:        "城市名称",
   271  		Prefix:      "geoCityName",
   272  		Description: "中国城市名称",
   273  		HasParams:   false,
   274  		Instance:    new(RequestGeoCityNameCheckpoint),
   275  		Priority:    90,
   276  	},
   277  	{
   278  		Name:        "ISP名称",
   279  		Prefix:      "ispName",
   280  		Description: "ISP名称",
   281  		HasParams:   false,
   282  		Instance:    new(RequestISPNameCheckpoint),
   283  		Priority:    90,
   284  	},
   285  	{
   286  		Name:        "CC统计(旧)",
   287  		Prefix:      "cc",
   288  		Description: "统计某段时间段内的请求信息",
   289  		HasParams:   true,
   290  		Instance:    new(CCCheckpoint),
   291  		Priority:    10,
   292  	},
   293  	{
   294  		Name:        "CC统计(新)",
   295  		Prefix:      "cc2",
   296  		Description: "统计某段时间段内的请求信息",
   297  		HasParams:   true,
   298  		Instance:    new(CC2Checkpoint),
   299  		Priority:    10,
   300  	},
   301  	{
   302  		Name:        "防盗链",
   303  		Prefix:      "refererBlock",
   304  		Description: "阻止一些域名访问引用本站资源",
   305  		HasParams:   true,
   306  		Instance:    new(RequestRefererBlockCheckpoint),
   307  		Priority:    20,
   308  	},
   309  	{
   310  		Name:        "通用响应Header长度限制",
   311  		Prefix:      "responseGeneralHeaderLength",
   312  		Description: "通用Header比如Cache-Control、Accept之类的长度限制,防止缓冲区溢出攻击",
   313  		HasParams:   false,
   314  		Instance:    new(ResponseGeneralHeaderLengthCheckpoint),
   315  		Priority:    100,
   316  	},
   317  	{
   318  		Name:        "响应状态码",
   319  		Prefix:      "status",
   320  		Description: "响应状态码,比如200、404、500",
   321  		HasParams:   false,
   322  		Instance:    new(ResponseStatusCheckpoint),
   323  		Priority:    100,
   324  	},
   325  	{
   326  		Name:        "响应Header",
   327  		Prefix:      "responseHeader",
   328  		Description: "响应Header值",
   329  		HasParams:   true,
   330  		Instance:    new(ResponseHeaderCheckpoint),
   331  		Priority:    100,
   332  	},
   333  	{
   334  		Name:        "响应内容",
   335  		Prefix:      "responseBody",
   336  		Description: "响应内容字符串",
   337  		HasParams:   false,
   338  		Instance:    new(ResponseBodyCheckpoint),
   339  		Priority:    5,
   340  	},
   341  	{
   342  		Name:        "响应内容长度",
   343  		Prefix:      "bytesSent",
   344  		Description: "响应内容长度,通过响应的Header Content-Length获取",
   345  		HasParams:   false,
   346  		Instance:    new(ResponseBytesSentCheckpoint),
   347  		Priority:    100,
   348  	},
   349  }
   350  
   351  // FindCheckpoint find a check point
   352  func FindCheckpoint(prefix string) CheckpointInterface {
   353  	for _, def := range AllCheckpoints {
   354  		if def.Prefix == prefix {
   355  			def.Instance.SetPriority(def.Priority)
   356  			return def.Instance
   357  		}
   358  	}
   359  	return nil
   360  }
   361  
   362  // FindCheckpointDefinition find a check point definition
   363  func FindCheckpointDefinition(prefix string) *CheckpointDefinition {
   364  	for _, def := range AllCheckpoints {
   365  		if def.Prefix == prefix {
   366  			return def
   367  		}
   368  	}
   369  	return nil
   370  }