2021-12-29 17:08:30 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2022-01-03 07:24:39 +00:00
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/xvzc/SpoofDPI/config"
|
2021-12-29 17:08:30 +00:00
|
|
|
)
|
|
|
|
|
2022-01-07 14:04:09 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
func ExtractDomain(message *[]byte) string {
|
|
|
|
i := 0
|
|
|
|
for ; i < len(*message); i++ {
|
|
|
|
if (*message)[i] == ' ' {
|
|
|
|
i++
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j := i
|
|
|
|
for ; j < len(*message); j++ {
|
2022-01-07 15:39:36 +00:00
|
|
|
if (*message)[j] == ' ' {
|
2022-01-07 13:44:03 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 15:39:36 +00:00
|
|
|
domain := string((*message)[i:j])
|
|
|
|
domain = strings.Replace(domain, "http://", "", 1)
|
|
|
|
domain = strings.Replace(domain, "https://", "", 1)
|
|
|
|
domain = strings.Split(domain, ":")[0]
|
|
|
|
domain = strings.Split(domain, "/")[0]
|
2022-01-07 13:44:03 +00:00
|
|
|
|
2022-01-07 15:39:36 +00:00
|
|
|
return strings.TrimSpace(domain)
|
2021-12-29 17:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
func ExtractMethod(message *[]byte) string {
|
|
|
|
i := 0
|
|
|
|
for ; i < len(*message); i++ {
|
|
|
|
if (*message)[i] == ' ' {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-12-29 17:08:30 +00:00
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
method := strings.TrimSpace(string((*message)[:i]))
|
|
|
|
Debug(method)
|
2021-12-29 17:08:30 +00:00
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
return strings.ToUpper(method)
|
2021-12-29 17:08:30 +00:00
|
|
|
}
|
2022-01-03 07:24:39 +00:00
|
|
|
|
|
|
|
func Debug(v ...interface{}) {
|
2022-01-07 13:44:03 +00:00
|
|
|
if config.GetConfig().Debug == false {
|
|
|
|
return
|
|
|
|
}
|
2022-01-03 07:24:39 +00:00
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
log.Println(v...)
|
2022-01-03 07:24:39 +00:00
|
|
|
}
|
2022-01-03 15:13:42 +00:00
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
func BytesToChunks(buf []byte) [][]byte {
|
|
|
|
if len(buf) < 1 {
|
|
|
|
return [][]byte{buf}
|
|
|
|
}
|
2022-01-03 15:13:42 +00:00
|
|
|
|
2022-01-07 13:44:03 +00:00
|
|
|
return [][]byte{buf[:1], buf[1:]}
|
2022-01-03 15:13:42 +00:00
|
|
|
}
|