mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
fix recursive redirect issue
This commit is contained in:
parent
1e16a454ca
commit
0f5eae5dae
@ -72,6 +72,10 @@ func (conn *Conn) ReadBytes() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
||||||
|
p.Tidy()
|
||||||
|
|
||||||
|
log.Debug("[HTTP] request: \n\n" + string(p.Raw()))
|
||||||
|
|
||||||
ip, err := doh.Lookup(p.Domain())
|
ip, err := doh.Lookup(p.Domain())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTP] Error looking up for domain: ", err)
|
log.Debug("[HTTP] Error looking up for domain: ", err)
|
||||||
@ -99,6 +103,8 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
|
||||||
|
log.Debug("[HTTPS] request: \n\n" + string(p.Raw()))
|
||||||
|
|
||||||
ip, err := doh.Lookup(p.Domain())
|
ip, err := doh.Lookup(p.Domain())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("[HTTPS] Error looking up for domain: ", p.Domain(), " ", err)
|
log.Debug("[HTTPS] Error looking up for domain: ", p.Domain(), " ", err)
|
||||||
|
@ -44,16 +44,18 @@ type HttpPacket struct {
|
|||||||
raw []byte
|
raw []byte
|
||||||
method string
|
method string
|
||||||
domain string
|
domain string
|
||||||
|
path string
|
||||||
version string
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpPacket(raw []byte) HttpPacket {
|
func NewHttpPacket(raw []byte) HttpPacket {
|
||||||
method, domain, version := parse(raw)
|
method, domain, path, version := parse(raw)
|
||||||
|
|
||||||
return HttpPacket{
|
return HttpPacket{
|
||||||
raw: raw,
|
raw: raw,
|
||||||
method: method,
|
method: method,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
|
path: path,
|
||||||
version: version,
|
version: version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,9 +66,11 @@ func (p *HttpPacket) Raw() []byte {
|
|||||||
func (p *HttpPacket) Method() string {
|
func (p *HttpPacket) Method() string {
|
||||||
return p.method
|
return p.method
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HttpPacket) Domain() string {
|
func (p *HttpPacket) Domain() string {
|
||||||
return p.domain
|
return p.domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HttpPacket) Version() string {
|
func (p *HttpPacket) Version() string {
|
||||||
return p.version
|
return p.version
|
||||||
}
|
}
|
||||||
@ -83,10 +87,13 @@ func (p *HttpPacket) IsConnectMethod() bool {
|
|||||||
return p.Method() == "CONNECT"
|
return p.Method() == "CONNECT"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HttpPacket) RemoveProxyHeader() {
|
func (p *HttpPacket) Tidy() {
|
||||||
s := string(p.raw)
|
s := string(p.raw)
|
||||||
|
|
||||||
lines := strings.Split(s, "\n")
|
lines := strings.Split(s, "\n")
|
||||||
|
|
||||||
|
lines[0] = p.method + " " + p.path + " " + p.version
|
||||||
|
|
||||||
for i := 0; i < len(lines); i++ {
|
for i := 0; i < len(lines); i++ {
|
||||||
if strings.HasPrefix(lines[i], "Proxy-Connection") {
|
if strings.HasPrefix(lines[i], "Proxy-Connection") {
|
||||||
lines[i] = ""
|
lines[i] = ""
|
||||||
@ -105,24 +112,44 @@ func (p *HttpPacket) RemoveProxyHeader() {
|
|||||||
p.raw = []byte(result)
|
p.raw = []byte(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(raw []byte) (string, string, string) {
|
func parse(raw []byte) (string, string, string, string) {
|
||||||
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] == '\n' {
|
||||||
firstLine = string((raw)[:i])
|
firstLine = string((raw)[:i])
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens := strings.Split(firstLine, " ")
|
tokens := strings.Split(firstLine, " ")
|
||||||
|
|
||||||
method := strings.TrimSpace(tokens[0])
|
method := strings.TrimSpace(tokens[0])
|
||||||
domain := strings.TrimSpace(tokens[1])
|
url := strings.TrimSpace(tokens[1])
|
||||||
version := strings.TrimSpace(tokens[2])
|
version := strings.TrimSpace(tokens[2])
|
||||||
|
|
||||||
domain = strings.Replace(domain, "http://", "", 1)
|
url = strings.Replace(url, "http://", "", 1)
|
||||||
domain = strings.Replace(domain, "https://", "", 1)
|
url = strings.Replace(url, "https://", "", 1)
|
||||||
domain = strings.Split(domain, ":")[0]
|
|
||||||
domain = strings.Split(domain, "/")[0]
|
|
||||||
|
|
||||||
return method, domain, version
|
domain := url
|
||||||
|
for i := 0; i < len(url); i++ {
|
||||||
|
if url[i] == ':' {
|
||||||
|
domain = url[:i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if url[i] == '/' {
|
||||||
|
domain = url[:i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path := "/"
|
||||||
|
for i := 0; i < len(url); i++ {
|
||||||
|
if url[i] == '/' {
|
||||||
|
path = url[i:]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return method, domain, path, version
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,6 @@ func (p *Proxy) Start() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt.RemoveProxyHeader()
|
|
||||||
|
|
||||||
log.Debug("New request: \n\n" + string(pkt.Raw()))
|
|
||||||
|
|
||||||
if pkt.IsConnectMethod() {
|
if pkt.IsConnectMethod() {
|
||||||
log.Debug("[HTTPS] Start")
|
log.Debug("[HTTPS] Start")
|
||||||
go conn.HandleHttps(pkt)
|
go conn.HandleHttps(pkt)
|
||||||
|
Loading…
Reference in New Issue
Block a user