mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
update packet module
This commit is contained in:
parent
5e1222054c
commit
c376d62ea4
@ -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"
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
84
util/util.go
84
util/util.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user