mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-31 07:04:39 +00:00
fix unexpectedly formated http request
This commit is contained in:
parent
5b5a081681
commit
7563f2b895
@ -58,7 +58,7 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
|||||||
ret := make([]byte, 0)
|
ret := make([]byte, 0)
|
||||||
buf := make([]byte, BUF_SIZE)
|
buf := make([]byte, BUF_SIZE)
|
||||||
|
|
||||||
conn.conn.SetReadDeadline(time.Now().Add(3 * time.Second))
|
conn.conn.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||||
|
|
||||||
for {
|
for {
|
||||||
n, err := conn.Read(buf)
|
n, err := conn.Read(buf)
|
||||||
|
@ -53,8 +53,11 @@ func ParseUrl(raw []byte) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpPacket(raw []byte) HttpPacket {
|
func NewHttpPacket(raw []byte) (HttpPacket, error){
|
||||||
method, domain, port, path, version := parse(raw)
|
method, domain, port, path, version, err := parse(raw)
|
||||||
|
if err != nil {
|
||||||
|
return HttpPacket{}, err
|
||||||
|
}
|
||||||
|
|
||||||
return HttpPacket{
|
return HttpPacket{
|
||||||
raw: raw,
|
raw: raw,
|
||||||
@ -63,7 +66,7 @@ func NewHttpPacket(raw []byte) HttpPacket {
|
|||||||
port: port,
|
port: port,
|
||||||
path: path,
|
path: path,
|
||||||
version: version,
|
version: version,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HttpPacket) Raw() []byte {
|
func (p *HttpPacket) Raw() []byte {
|
||||||
@ -125,10 +128,10 @@ func (p *HttpPacket) Tidy() {
|
|||||||
p.raw = []byte(result)
|
p.raw = []byte(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(raw []byte) (string, string, string, string, string) {
|
func parse(raw []byte) (string, string, string, string, string, error) {
|
||||||
var firstLine string
|
var firstLine string
|
||||||
for i := 0; i < len(raw); i++ {
|
for i := 0; i < len(raw); i++ {
|
||||||
if (raw)[i] == '\n' {
|
if (raw)[i] == '\r' {
|
||||||
firstLine = string((raw)[:i])
|
firstLine = string((raw)[:i])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -136,15 +139,15 @@ func parse(raw []byte) (string, string, string, string, string) {
|
|||||||
|
|
||||||
tokens := strings.Split(firstLine, " ")
|
tokens := strings.Split(firstLine, " ")
|
||||||
|
|
||||||
method := strings.TrimSpace(tokens[0])
|
method := tokens[0]
|
||||||
url := strings.TrimSpace(tokens[1])
|
url := tokens[1]
|
||||||
version := strings.TrimSpace(tokens[2])
|
version := tokens[2]
|
||||||
|
|
||||||
url = strings.Replace(url, "http://", "", 1)
|
url = strings.Replace(url, "http://", "", 1)
|
||||||
url = strings.Replace(url, "https://", "", 1)
|
url = strings.Replace(url, "https://", "", 1)
|
||||||
|
|
||||||
var domain string
|
domain := ""
|
||||||
var port string
|
port := ""
|
||||||
for i := 0; i < len(url); i++ {
|
for i := 0; i < len(url); i++ {
|
||||||
if url[i] == ':' {
|
if url[i] == ':' {
|
||||||
domain = url[:i]
|
domain = url[:i]
|
||||||
@ -166,5 +169,5 @@ func parse(raw []byte) (string, string, string, string, string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return method, domain, port, path, version
|
return method, domain, port, path, version, nil
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,15 @@ func (p *Proxy) Start() {
|
|||||||
}
|
}
|
||||||
// log.Debug("[PROXY] Client sent a request")
|
// log.Debug("[PROXY] Client sent a request")
|
||||||
|
|
||||||
pkt := packet.NewHttpPacket(b)
|
pkt, err := packet.NewHttpPacket(b)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Error while parsing request")
|
||||||
|
log.Println(b)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !pkt.IsValidMethod() {
|
if !pkt.IsValidMethod() {
|
||||||
log.Println("Unsupported method: ", pkt.Method())
|
log.Debug("Unsupported method: ", pkt.Method())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user