Files
EdgeNode/internal/waf/action_get_302.go

82 lines
1.8 KiB
Go
Raw Normal View History

2021-07-18 15:51:49 +08:00
package waf
import (
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
2021-07-18 15:51:49 +08:00
"net/http"
"net/url"
"time"
)
const (
Get302Path = "/WAF/VERIFY/GET"
)
// Get302Action
// 原理: origin url --> 302 verify url --> origin url
// TODO 将来支持meta refresh验证
type Get302Action struct {
BaseAction
2021-10-18 20:08:43 +08:00
Life int32 `yaml:"life" json:"life"`
Scope string `yaml:"scope" json:"scope"`
2021-07-18 15:51:49 +08:00
}
func (this *Get302Action) Init(waf *WAF) error {
return nil
}
func (this *Get302Action) Code() string {
return ActionGet302
}
func (this *Get302Action) IsAttack() bool {
return false
}
func (this *Get302Action) WillChange() bool {
return true
}
func (this *Get302Action) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) (continueRequest bool, goNextSet bool) {
2021-07-18 15:51:49 +08:00
// 仅限于Get
if request.WAFRaw().Method != http.MethodGet {
return true, false
2021-07-18 15:51:49 +08:00
}
// 是否已经在白名单中
if SharedIPWhiteList.Contains("set:"+types.String(set.Id), this.Scope, request.WAFServerId(), request.WAFRemoteIP()) {
return true, false
2021-07-18 15:51:49 +08:00
}
var m = maps.Map{
"url": request.WAFRaw().URL.String(),
"timestamp": time.Now().Unix(),
"life": this.Life,
2021-10-18 20:08:43 +08:00
"scope": this.Scope,
"policyId": waf.Id,
"groupId": group.Id,
2021-07-18 15:51:49 +08:00
"setId": set.Id,
}
info, err := utils.SimpleEncryptMap(m)
if err != nil {
remotelogs.Error("WAF_GET_302_ACTION", "encode info failed: "+err.Error())
return true, false
2021-07-18 15:51:49 +08:00
}
http.Redirect(writer, request.WAFRaw(), Get302Path+"?info="+url.QueryEscape(info), http.StatusFound)
flusher, ok := writer.(http.Flusher)
if ok {
flusher.Flush()
}
2021-07-18 15:51:49 +08:00
2023-03-06 16:28:54 +08:00
// 迟滞访问
time.Sleep(1 * time.Second)
return false, false
2021-07-18 15:51:49 +08:00
}