mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
add request module
This commit is contained in:
parent
1581f9c4d1
commit
81938445a1
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/xvzc/SpoofDPI/config"
|
||||
"github.com/xvzc/SpoofDPI/request"
|
||||
"github.com/xvzc/SpoofDPI/util"
|
||||
)
|
||||
|
||||
@ -30,40 +31,35 @@ func Start() {
|
||||
go func() {
|
||||
defer clientConn.Close()
|
||||
|
||||
message, err := ReadBytes(clientConn)
|
||||
b, err := ReadBytes(clientConn)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
util.Debug("Client sent data: ", len(message))
|
||||
util.Debug("Client sent data: ", len(b))
|
||||
|
||||
util.Debug("")
|
||||
util.Debug("Request : ")
|
||||
util.Debug("\n" + string(message))
|
||||
r := request.New(&b)
|
||||
|
||||
method := util.ExtractMethod(&message)
|
||||
|
||||
if !util.IsValidMethod(method) {
|
||||
util.Debug("Not a valid method: " + method)
|
||||
if !r.IsValidMethod() {
|
||||
log.Println("Unsupported method: ", r.Method)
|
||||
return
|
||||
}
|
||||
|
||||
domain := util.ExtractDomain(&message)
|
||||
|
||||
ip, err := util.DnsLookupOverHttps(config.GetConfig().DNS, domain) // Dns lookup over https
|
||||
// Dns lookup over https
|
||||
ip, err := util.DnsLookupOverHttps(config.GetConfig().DNS, r.Domain)
|
||||
if err != nil {
|
||||
log.Println("Error looking up dns: "+domain, err)
|
||||
log.Println("Error looking up dns: "+r.Domain, err)
|
||||
return
|
||||
}
|
||||
|
||||
util.Debug("ip: " + ip)
|
||||
|
||||
if util.ExtractMethod(&message) == "CONNECT" {
|
||||
if r.Method == "CONNECT" {
|
||||
util.Debug("HTTPS Requested")
|
||||
HandleHttps(clientConn, ip)
|
||||
} else {
|
||||
util.Debug("HTTP Requested.")
|
||||
HandleHttp(clientConn, ip, message)
|
||||
HandleHttp(clientConn, ip, b)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
107
request/http.go
Normal file
107
request/http.go
Normal file
@ -0,0 +1,107 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
Raw *[]byte
|
||||
Method string
|
||||
Domain string
|
||||
}
|
||||
|
||||
func (r *Request) IsValidMethod() bool {
|
||||
if _, exists := getValidMethods()[r.Method]; exists {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func New(raw *[]byte) Request {
|
||||
return Request{
|
||||
Raw: raw,
|
||||
Method: extractMethod(raw),
|
||||
Domain: extractDomain(raw),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Request) ToChunks() {
|
||||
|
||||
}
|
||||
|
||||
func extractDomain(request *[]byte) string {
|
||||
i := 0
|
||||
for ; i < len(*request); i++ {
|
||||
if (*request)[i] == ' ' {
|
||||
i++
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
j := i
|
||||
for ; j < len(*request); j++ {
|
||||
if (*request)[j] == ' ' {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
domain := string((*request)[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]))
|
||||
|
||||
return strings.ToUpper(method)
|
||||
}
|
||||
|
||||
func getValidMethods() map[string]struct{} {
|
||||
return 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": {},
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user