add method validation

This commit is contained in:
xvzc 2022-01-07 23:04:09 +09:00
parent 2fd2503dd5
commit 72d5770d18
3 changed files with 81 additions and 32 deletions

View File

@ -37,6 +37,11 @@ func Start() {
util.Debug("Client sent data: ", len(message)) util.Debug("Client sent data: ", len(message))
method := util.ExtractMethod(&message)
if !util.IsValidMethod(method) {
return
}
domain := util.ExtractDomain(&message) domain := util.ExtractDomain(&message)
ip, err := util.DnsLookupOverHttps(config.GetConfig().DNS, domain) // Dns lookup over https ip, err := util.DnsLookupOverHttps(config.GetConfig().DNS, domain) // Dns lookup over https

View File

@ -7,6 +7,50 @@ import (
"github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/config"
) )
var validMethod = map[string]struct{}{
"DELETE": {},
"GET": {},
"HEAD": {},
"POST": {},
"PUT": {},
"CONNECT": {},
"OPTIONS": {},
"TRACE": {},
"COPY": {},
"LOCK": {},
"MKCOL": {},
"MOVE": {},
"PROPFIND": {},
"PROPPATCH": {},
"SEARCH": {},
"UNLOCK": {},
"BIND": {},
"REBIND": {},
"UNBIND": {},
"ACL": {},
"REPORT": {},
"MKACTIVITY": {},
"CHECKOUT": {},
"MERGE": {},
"M-SEARCH": {},
"NOTIFY": {},
"SUBSCRIBE": {},
"UNSUBSCRIBE": {},
"PATCH": {},
"PURGE": {},
"MKCALENDAR": {},
"LINK": {},
"UNLINK": {},
}
func IsValidMethod(name string) bool {
if _, exists := validMethod[name]; exists {
return true
}
return false
}
func ExtractDomain(message *[]byte) string { func ExtractDomain(message *[]byte) string {
i := 0 i := 0
for ; i < len(*message); i++ { for ; i < len(*message); i++ {
@ -32,7 +76,7 @@ func ExtractDomain(message *[]byte) string {
domain := strings.Split(string((*message)[i:j]), ":")[0] domain := strings.Split(string((*message)[i:j]), ":")[0]
return strings.TrimSpace(domain) return strings.ToUpper(strings.TrimSpace(domain))
} }
func ExtractMethod(message *[]byte) string { func ExtractMethod(message *[]byte) string {