I have a simple http/https proxy and trying to handle this headers. When i get Get
header try to make tcp socket to that website. But this one has other data and different Host
and Referer
. How should I handle this header?
GET http://webcode.me/format.css HTTP/1.1
Host: webcode.meun, 23 Jan 2022 10:39:25 GMT��∟↔Y_=�>∟>ߞ����B�
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Referer: http://webcode.me/rom client: 282
And this is my code
func handleSocket(client_to_proxy net.Conn) {
buffer := make([]byte, 8*1024)
length, e := client_to_proxy.Read(buffer)
if e != nil {
fmt.Println("ERR1 ", e)
return
}
var host []string
headers := strings.Split(message, "\r\n")
for _, header := range headers {
if strings.HasPrefix(header, "Host") {
host = strings.Split(strings.Replace(header, " ", "", 1), ":")
break
}
}
splited := strings.Split(message, " ")
if splited[0] == "CONNECT" {
proxy_to_server, e := net.Dial("tcp", splited[1])
if e != nil {
fmt.Println("ERROR3 ", e)
return
}
fmt.Println("CONNECTed TO: " splited[1])
_, e = client_to_proxy.Write([]byte("HTTP/1.1 200 Connection Established\r\n"))
if e != nil {
fmt.Println("ERROR4 ", e)
return
}
read443(client_to_proxy, proxy_to_server)
} else if splited[0] == "GET" {
proxy_to_server, e := net.Dial("tcp", host[1] ":80")
if e != nil {
fmt.Println("ERROR5 ", e)
return
}
_, e = proxy_to_server.Write([]byte(message))
if e != nil {
fmt.Println("ERROR6 ", e)
return
}
write80(client_to_proxy, proxy_to_server)
}
}
CodePudding user response:
Mistake 1)I used AES/ECB to encrypt data and data length must be multiple of key length. So i was adding some byte to fix it and didn't remove it after decryption.
Mistake 2) I used URL after GET and now use URL after host. Then send all received headers to host.
I still have problem in connecting some host using https but hope they will be fixed soon.