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"
)
type Http struct {
type HttpPacket struct {
Raw *[]byte
Method string
Domain string
Version string
}
func NewHttp(raw *[]byte) Http {
func NewHttpPacket(raw *[]byte) HttpPacket {
method, domain, version := parse(raw)
return Http{
return HttpPacket{
Raw: raw,
Method: method,
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 {
return true
}
@ -29,7 +29,7 @@ func (r *Http) IsValidMethod() bool {
return false
}
func (r *Http) IsConnectMethod() bool {
func (r *HttpPacket) IsConnectMethod() bool {
return r.Method == "CONNECT"
}

View File

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

View File

@ -8,7 +8,7 @@ import (
"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
if err != nil {
util.Debug(err)

View File

@ -8,7 +8,7 @@ import (
"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
remoteConn, err := net.Dial("tcp", ip+":443")
if err != nil {

View File

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

View File

@ -2,94 +2,10 @@ package util
import (
"log"
"strings"
"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{}) {
if config.GetConfig().Debug == false {
return