Files
revsuit/internal/rule/rule.go
T
Li4n0 3559894acc feat: complete basic functions
Support http,dns and mysql connection. Support custom http, dns response. Support dns rebinding.
Support mysql load local files and jdbc deserialize exploit.
2021-04-21 18:55:16 +08:00

66 lines
1.6 KiB
Go

package rule
import (
"regexp"
"time"
log "unknwon.dev/clog/v2"
)
type Rule interface {
CreateOrUpdate() error
Delete() error
}
type BaseRule struct {
Rule `gorm:"-" json:"-"`
ID uint `gorm:"primarykey" form:"id" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `gorm:"index;unique;not null;" form:"name" json:"name"`
FlagFormat string `gorm:"unique;not null;" form:"flag_format" json:"flag_format"`
flagCatcher *regexp.Regexp `gorm:"-" json:"-"`
Rank int `gorm:"default:0" json:"rank" form:"rank"`
PushToClient bool `gorm:"default:false;not null;" form:"push_to_client" json:"push_to_client"`
Notice bool `gorm:"default:false;not null;" form:"notice" json:"notice"`
}
func compileCatcher(flagFormat string) (reg *regexp.Regexp, err error) {
if reg, err := regexp.Compile(flagFormat); err == nil {
return reg, nil
} else {
// * meaning record all connections.
if flagFormat != "*" {
return nil, err
} else {
return nil, nil
}
}
}
func (br BaseRule) Match(s string) (flag, flagGroup string) {
if br.flagCatcher == nil && br.FlagFormat != "*" {
// compile rule flags
catcher, err := compileCatcher(br.FlagFormat)
if err != nil {
log.Error("%s(rule:%s)", err.Error(), br.Name)
}
br.flagCatcher = catcher
}
if br.flagCatcher == nil {
// capture all connection.
flag = "*"
} else {
matched := br.flagCatcher.FindStringSubmatch(s)
if len(matched) == 0 {
return
}
flag = matched[0]
if len(matched) > 1 {
flagGroup = matched[1]
}
}
return
}