mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 22:36:53 +00:00
commit
20e2065109
@ -91,7 +91,7 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
|
||||||
defer lConn.Close()
|
defer lConn.Close()
|
||||||
p.Tidy()
|
p.Tidy()
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
func (lConn *Conn) HandleHttps(p *packet.HttpPacket) {
|
||||||
defer lConn.Close()
|
defer lConn.Close()
|
||||||
|
|
||||||
ip, err := doh.Lookup(p.Domain())
|
ip, err := doh.Lookup(p.Domain())
|
||||||
|
@ -54,20 +54,12 @@ func ParseUrl(raw []byte) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpPacket(raw []byte) (HttpPacket, error){
|
func NewHttpPacket(raw []byte) (*HttpPacket, error){
|
||||||
method, domain, port, path, version, err := parse(raw)
|
pkt := &HttpPacket{raw: raw}
|
||||||
if err != nil {
|
|
||||||
return HttpPacket{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return HttpPacket{
|
pkt.parse()
|
||||||
raw: raw,
|
|
||||||
method: method,
|
return pkt, nil
|
||||||
domain: domain,
|
|
||||||
port: port,
|
|
||||||
path: path,
|
|
||||||
version: version,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HttpPacket) Raw() []byte {
|
func (p *HttpPacket) Raw() []byte {
|
||||||
@ -129,11 +121,11 @@ func (p *HttpPacket) Tidy() {
|
|||||||
p.raw = []byte(result)
|
p.raw = []byte(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(raw []byte) (string, string, string, string, string, error) {
|
func (p *HttpPacket )parse() error {
|
||||||
var firstLine string
|
var firstLine string
|
||||||
for i := 0; i < len(raw); i++ {
|
for i := 0; i < len(p.raw); i++ {
|
||||||
if (raw)[i] == '\r' {
|
if (p.raw)[i] == '\r' {
|
||||||
firstLine = string((raw)[:i])
|
firstLine = string(p.raw[:i])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,15 +133,20 @@ func parse(raw []byte) (string, string, string, string, string, error) {
|
|||||||
tokens := strings.Split(firstLine, " ")
|
tokens := strings.Split(firstLine, " ")
|
||||||
|
|
||||||
if (len(tokens) < 3) {
|
if (len(tokens) < 3) {
|
||||||
return "", "", "", "", "", errors.New("Unexpected request format")
|
return errors.New("Error parsing http request")
|
||||||
}
|
}
|
||||||
|
|
||||||
method := tokens[0]
|
p.method = tokens[0]
|
||||||
url := tokens[1]
|
url := tokens[1]
|
||||||
version := tokens[2]
|
p.version = tokens[2]
|
||||||
|
|
||||||
url = strings.Replace(url, "http://", "", 1)
|
if strings.HasPrefix(url, "http://") {
|
||||||
url = strings.Replace(url, "https://", "", 1)
|
url = strings.Replace(url, "http://", "", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(url, "https://") {
|
||||||
|
url = strings.Replace(url, "https://", "", 1)
|
||||||
|
}
|
||||||
|
|
||||||
domain := ""
|
domain := ""
|
||||||
port := ""
|
port := ""
|
||||||
@ -165,6 +162,8 @@ func parse(raw []byte) (string, string, string, string, string, error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p.domain = domain
|
||||||
|
p.port = port
|
||||||
|
|
||||||
path := "/"
|
path := "/"
|
||||||
for i := 0; i < len(url); i++ {
|
for i := 0; i < len(url); i++ {
|
||||||
@ -174,5 +173,7 @@ func parse(raw []byte) (string, string, string, string, string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return method, domain, port, path, version, nil
|
p.path = path
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user