update packet module

This commit is contained in:
xvzc 2022-01-09 00:09:01 +09:00
parent 5e1222054c
commit c376d62ea4
7 changed files with 13 additions and 96 deletions

1
io/io.go Normal file
View File

@ -0,0 +1 @@
package main

View File

@ -4,16 +4,16 @@ import (
"strings" "strings"
) )
type Http struct { type HttpPacket struct {
Raw *[]byte Raw *[]byte
Method string Method string
Domain string Domain string
Version string Version string
} }
func NewHttp(raw *[]byte) Http { func NewHttpPacket(raw *[]byte) HttpPacket {
method, domain, version := parse(raw) method, domain, version := parse(raw)
return Http{ return HttpPacket{
Raw: raw, Raw: raw,
Method: method, Method: method,
Domain: domain, Domain: domain,
@ -21,7 +21,7 @@ func NewHttp(raw *[]byte) Http {
} }
} }
func (r *Http) IsValidMethod() bool { func (r *HttpPacket) IsValidMethod() bool {
if _, exists := getValidMethods()[r.Method]; exists { if _, exists := getValidMethods()[r.Method]; exists {
return true return true
} }
@ -29,7 +29,7 @@ func (r *Http) IsValidMethod() bool {
return false return false
} }
func (r *Http) IsConnectMethod() bool { func (r *HttpPacket) IsConnectMethod() bool {
return r.Method == "CONNECT" return r.Method == "CONNECT"
} }

View File

@ -1,16 +1,16 @@
package packet package packet
type Https struct { type HttpsPacket struct {
Raw *[]byte Raw *[]byte
} }
func NewHttps(raw *[]byte) Https { func NewHttpsPacket(raw *[]byte) HttpsPacket {
return Https{ return HttpsPacket{
Raw: raw, Raw: raw,
} }
} }
func (r Https) SplitInChunks() [][]byte { func (r HttpsPacket) SplitInChunks() [][]byte {
if len(*r.Raw) < 1 { if len(*r.Raw) < 1 {
return [][]byte{*r.Raw} return [][]byte{*r.Raw}
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/xvzc/SpoofDPI/util" "github.com/xvzc/SpoofDPI/util"
) )
func HandleHttp(clientConn net.Conn, ip string, p *packet.Http) { func HandleHttp(clientConn net.Conn, ip string, p *packet.HttpPacket) {
remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server
if err != nil { if err != nil {
util.Debug(err) util.Debug(err)

View File

@ -8,7 +8,7 @@ import (
"github.com/xvzc/SpoofDPI/util" "github.com/xvzc/SpoofDPI/util"
) )
func HandleHttps(clientConn net.Conn, ip string, r *packet.Http) { func HandleHttps(clientConn net.Conn, ip string, r *packet.HttpPacket) {
// Create a connection to the requested server // Create a connection to the requested server
remoteConn, err := net.Dial("tcp", ip+":443") remoteConn, err := net.Dial("tcp", ip+":443")
if err != nil { if err != nil {

View File

@ -38,7 +38,7 @@ func Start() {
util.Debug("Client sent data: ", len(b)) util.Debug("Client sent data: ", len(b))
r := packet.NewHttp(&b) r := packet.NewHttpPacket(&b)
util.Debug("Request: \n" + string(*r.Raw)) util.Debug("Request: \n" + string(*r.Raw))
if !r.IsValidMethod() { if !r.IsValidMethod() {

View File

@ -2,94 +2,10 @@ package util
import ( import (
"log" "log"
"strings"
"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 {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
i++
break
}
}
j := i
for ; j < len(*message); j++ {
if (*message)[j] == ' ' {
break
}
}
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]
return strings.TrimSpace(domain)
}
func ExtractMethod(message *[]byte) string {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
break
}
}
method := strings.TrimSpace(string((*message)[:i]))
Debug(method)
return strings.ToUpper(method)
}
func Debug(v ...interface{}) { func Debug(v ...interface{}) {
if config.GetConfig().Debug == false { if config.GetConfig().Debug == false {
return return