mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-31 07:04:39 +00:00
update refactor http request
This commit is contained in:
parent
b615f4aabc
commit
539d256146
@ -4,10 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/xvzc/SpoofDPI/request"
|
||||||
"github.com/xvzc/SpoofDPI/util"
|
"github.com/xvzc/SpoofDPI/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleHttp(clientConn net.Conn, ip string, message []byte) {
|
func HandleHttp(clientConn net.Conn, ip string, r *request.HttpRequest) {
|
||||||
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)
|
||||||
@ -20,7 +21,7 @@ func HandleHttp(clientConn net.Conn, ip string, message []byte) {
|
|||||||
go Serve(remoteConn, clientConn, "HTTP")
|
go Serve(remoteConn, clientConn, "HTTP")
|
||||||
|
|
||||||
util.Debug("[HTTP] Sending request to the server")
|
util.Debug("[HTTP] Sending request to the server")
|
||||||
fmt.Fprintf(remoteConn, string(message))
|
fmt.Fprintf(remoteConn, string(*r.Raw))
|
||||||
|
|
||||||
Serve(clientConn, remoteConn, "HTTP")
|
Serve(clientConn, remoteConn, "HTTP")
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ func Start() {
|
|||||||
util.Debug("Client sent data: ", len(b))
|
util.Debug("Client sent data: ", len(b))
|
||||||
|
|
||||||
r := request.NewHttpRequest(&b)
|
r := request.NewHttpRequest(&b)
|
||||||
|
util.Debug("Request: \n" + string(*r.Raw))
|
||||||
|
|
||||||
if !r.IsValidMethod() {
|
if !r.IsValidMethod() {
|
||||||
log.Println("Unsupported method: ", r.Method)
|
log.Println("Unsupported method: ", r.Method)
|
||||||
@ -59,7 +60,7 @@ func Start() {
|
|||||||
HandleHttps(clientConn, ip)
|
HandleHttps(clientConn, ip)
|
||||||
} else {
|
} else {
|
||||||
util.Debug("HTTP Requested.")
|
util.Debug("HTTP Requested.")
|
||||||
HandleHttp(clientConn, ip, b)
|
HandleHttp(clientConn, ip, &r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HttpRequest struct {
|
type HttpRequest struct {
|
||||||
Raw *[]byte
|
Raw *[]byte
|
||||||
Method string
|
Method string
|
||||||
Domain string
|
Domain string
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpRequest(raw *[]byte) HttpRequest {
|
func NewHttpRequest(raw *[]byte) HttpRequest {
|
||||||
|
method, domain, version := parse(raw)
|
||||||
return HttpRequest{
|
return HttpRequest{
|
||||||
Raw: raw,
|
Raw: raw,
|
||||||
Method: extractMethod(raw),
|
Method: method,
|
||||||
Domain: extractDomain(raw),
|
Domain: domain,
|
||||||
|
Version: version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,42 +33,26 @@ func (r *HttpRequest) ToChunks() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractDomain(request *[]byte) string {
|
func parse(raw *[]byte) (string, string, string) {
|
||||||
i := 0
|
var firstLine string
|
||||||
for ; i < len(*request); i++ {
|
for i := 0; i < len(*raw); i++ {
|
||||||
if (*request)[i] == ' ' {
|
if (*raw)[i] == '\n' {
|
||||||
i++
|
firstLine = string((*raw)[:i])
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
j := i
|
tokens := strings.Split(firstLine, " ")
|
||||||
for ; j < len(*request); j++ {
|
|
||||||
if (*request)[j] == ' ' {
|
method := strings.TrimSpace(tokens[0])
|
||||||
break
|
domain := strings.TrimSpace(tokens[1])
|
||||||
}
|
version := strings.TrimSpace(tokens[2])
|
||||||
}
|
|
||||||
|
|
||||||
domain := string((*request)[i:j])
|
|
||||||
domain = strings.Replace(domain, "http://", "", 1)
|
domain = strings.Replace(domain, "http://", "", 1)
|
||||||
domain = strings.Replace(domain, "https://", "", 1)
|
domain = strings.Replace(domain, "https://", "", 1)
|
||||||
domain = strings.Split(domain, ":")[0]
|
domain = strings.Split(domain, ":")[0]
|
||||||
domain = strings.Split(domain, "/")[0]
|
domain = strings.Split(domain, "/")[0]
|
||||||
|
|
||||||
return strings.TrimSpace(domain)
|
return method, domain, version
|
||||||
}
|
|
||||||
|
|
||||||
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{} {
|
func getValidMethods() map[string]struct{} {
|
||||||
|
Loading…
Reference in New Issue
Block a user