第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

構(gòu)建 https 代理失敗,出現(xiàn)錯(cuò)誤 SSL_ERROR_BAD_MAC_READ

構(gòu)建 https 代理失敗,出現(xiàn)錯(cuò)誤 SSL_ERROR_BAD_MAC_READ

Go
回首憶惘然 2023-03-07 13:40:49
我正在嘗試使用 Golang 創(chuàng)建一個(gè) HTTP/HTTPS 代理,就像這個(gè)鏈接一樣。這是我的所有代碼:首先從瀏覽器獲取命令。如果它是 CONNECT 意味著 HTTPS 并制作簡(jiǎn)單的 TCP 套接字并讓瀏覽器繼續(xù)它。然后將每個(gè)連接通過管道連接在一起。package mainimport (    "bufio"    "fmt"    "net"    "strings")func main() {    fmt.Println("Start server...")    ln, _ := net.Listen("tcp", ":8000")    conn, _ := ln.Accept()    handleSocket(conn)}func handleSocket(client_to_proxy net.Conn) {    message, e := bufio.NewReader(client_to_proxy).ReadString('\n')    message = strings.ReplaceAll(message, "\r\n", "")    if e != nil {        fmt.Println("ERROR1 ", e)        return    }    splited := strings.Split(message, " ")    host := strings.Split(splited[1], ":")    if splited[0] == "CONNECT" {        proxy_to_server, e := net.Dial("tcp", splited[1])        if e != nil {            fmt.Println("ERROR2 ", e)            return        }        lenn, e := client_to_proxy.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))        if e != nil {            fmt.Println("ERROR8 ", e)            return        }        fmt.Println(lenn)        readAll(client_to_proxy, proxy_to_server)    } else if splited[0] == "GET" {        remote_conn, e := net.Dial("tcp", strings.Replace(splited[1][:len(splited[1])-1], "http://", "", 2)+":80")        if e != nil {            fmt.Println("ERROR7 ", e)            return        }        _, e = remote_conn.Write([]byte("GET / " + splited[2] + "\r\n" + "Host: " + host[0] + "\r\n\r\n"))        if e != nil {            fmt.Println("ERROR6 ", e)            return        }        writeAll(client_to_proxy, remote_conn)    }}func writeAll(client_to_proxy net.Conn, proxy_to_server net.Conn) {    buffer := make([]byte, 32*1024)    for {        readLeng, err := proxy_to_server.Read(buffer)        if err != nil {            fmt.Println("ERROR9 ", err)            return        }        if readLeng > 0 {            _, err := client_to_proxy.Write(buffer)            if err != nil {                fmt.Println("ERR4 ", err)                return            }        }    }}
查看完整描述

2 回答

?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

這是后來者的最終解決方案。適用于 http/https:


package main


import (

    "fmt"

    "net"

    "strings"

)


func main() {

    fmt.Println("Start server...")


    ln, _ := net.Listen("tcp", ":8000")


    for {

        conn, _ := ln.Accept()

        handleSocket(conn)

    }

}


func handleSocket(client_to_proxy net.Conn) {

    buffer := make([]byte, 32*1024)

    _, e := client_to_proxy.Read(buffer)

    if e != nil {

        fmt.Println("ERROR1 ", e)

        return

    }

    message := string(buffer)

    a := strings.Count(message, "\r\n")

    fmt.Println(message)

    fmt.Println(a)

    if e != nil {

        fmt.Println("ERROR1 ", e)

        return

    }


    splited := strings.Split(message, " ")

    //host := strings.Split(splited[1], ":")

    if splited[0] == "CONNECT" {

        //message = strings.Replace(message, "CONNECT", "GET", 1)

        proxy_to_server, e := net.Dial("tcp", splited[1])

        if e != nil {

            fmt.Println("ERROR2 ", e)

            return

        }

        //_, e = proxy_to_server.Write([]byte(message))

        //if e != nil {

        //  fmt.Println("ERROR2 ", e)

        //  return

        //}

        lenn, e := client_to_proxy.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))

        if e != nil {

            fmt.Println("ERROR8 ", e)

            return

        }

        fmt.Println(lenn)


        read443(client_to_proxy, proxy_to_server)

    } else if splited[0] == "GET" {

        host1 := strings.Replace(splited[1], "http://", "", 1)

        host2 := host1[:len(host1)-1]

        var final_host string

        if strings.LastIndexAny(host2, "/") > 0 {

            final_host = host2[:strings.LastIndexAny(host2, "/")]

        } else {

            final_host = host2

        }

        proxy_to_server, e := net.Dial("tcp", final_host+":80")

        if e != nil {

            fmt.Println("ERROR7 ", e)

            return

        }

        _, e = proxy_to_server.Write([]byte(message))

        if e != nil {

            fmt.Println("ERROR6 ", e)

            return

        }


        write80(client_to_proxy, proxy_to_server)

    }

}


func write80(client_to_proxy net.Conn, proxy_to_server net.Conn) {

    buffer := make([]byte, 64*1024)


    readLeng, err := proxy_to_server.Read(buffer)

    if err != nil {

        fmt.Println("ERROR9 ", err)

        return

    }

    fmt.Println("WRIIIIIIIIIIIIIIIIIIIIIIT from server:")

    fmt.Println(string(buffer[:readLeng]))

    if readLeng > 0 {

        _, err := client_to_proxy.Write(buffer[:readLeng])

        if err != nil {

            fmt.Println("ERR4 ", err)

            return

        }

    }


    go read80(client_to_proxy, proxy_to_server)

    for {

        readLeng, err := proxy_to_server.Read(buffer)

        if err != nil {

            fmt.Println("ERROR10 ", err)

            return

        }

        fmt.Println("WRIIIIIIIIIIIIIIIIIIIIIIT from server:")

        fmt.Println(string(buffer[:readLeng]))

        if readLeng > 0 {

            _, err := client_to_proxy.Write(buffer[:readLeng])

            if err != nil {

                fmt.Println("ERR4 ", err)

                return

            }

        }

    }

}


func read80(client_to_proxy net.Conn, proxy_to_server net.Conn) {

    buffer := make([]byte, 32*1024)


    for {

        readLeng, err := client_to_proxy.Read(buffer)

        if err != nil {

            return

        }

        fmt.Println("REEEEEEEEEEEEEEEEEEEEEEED from client:")

        fmt.Println(string(buffer[:readLeng]))

        if readLeng > 0 {

            _, err := proxy_to_server.Write(buffer[:readLeng])

            if err != nil {

                fmt.Println("ERR5 ", err)

                return

            }

        }

    }

}


func write443(client_to_proxy net.Conn, proxy_to_server net.Conn) {

    buffer := make([]byte, 32*1024)

    for {

        readLeng, err := proxy_to_server.Read(buffer)

        if err != nil {

            fmt.Println("ERROR10 ", err)

            return

        }

        fmt.Println("WRIIIIIIIIIIIIIIIIIIIIIIT from server:")

        fmt.Println(string(buffer[:readLeng]))

        if readLeng > 0 {

            _, err := client_to_proxy.Write(buffer[:readLeng])

            if err != nil {

                fmt.Println("ERR4 ", err)

                return

            }

        }

    }

}


func read443(client_to_proxy net.Conn, proxy_to_server net.Conn) {

    buffer := make([]byte, 32*1024)


    readLeng, err := client_to_proxy.Read(buffer)

    if err != nil {

        return

    }

    fmt.Println("REEEEEEEEEEEEEEEEEEEEEEED from client:")

    fmt.Println(string(buffer[:readLeng]))

    if readLeng > 0 {

        _, err := proxy_to_server.Write(buffer[:readLeng])

        if err != nil {

            fmt.Println("ERR5 ", err)

            return

        }

    }


    go write443(client_to_proxy, proxy_to_server)


    for {

        readLeng, err := client_to_proxy.Read(buffer)

        if err != nil {

            return

        }

        fmt.Println("REEEEEEEEEEEEEEEEEEEEEEED from client:")

        fmt.Println(string(buffer[:readLeng]))

        if readLeng > 0 {

            _, err := proxy_to_server.Write(buffer[:readLeng])

            if err != nil {

                fmt.Println("ERR5 ", err)

                return

            }

        }

    }

}



查看完整回答
反對(duì) 回復(fù) 2023-03-07
?
江戶川亂折騰

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊

與所有 HTTP 請(qǐng)求一樣,CONNECT 請(qǐng)求以多行請(qǐng)求標(biāo)頭開頭,該標(biāo)頭以僅包含 \r\n 的行結(jié)尾。但你只讀了它的第一行:

message, e := bufio.NewReader(client_to_proxy).ReadString('\n')

請(qǐng)求的其余部分被發(fā)送到服務(wù)器,這可能會(huì)返回一些錯(cuò)誤,因?yàn)檫@不是 TLS 握手的預(yù)期開始。TLS 握手的開始僅出現(xiàn)在請(qǐng)求標(biāo)頭之后。服務(wù)器返回的錯(cuò)誤然后被轉(zhuǎn)發(fā)到客戶端并被解釋為 TLS 消息——這被視為損壞的消息,因此是“壞 mac”。

   readAll(client_to_proxy, proxy_to_server)

無需將所有剩余數(shù)據(jù)(即除了請(qǐng)求的第一行之外的所有內(nèi)容)轉(zhuǎn)發(fā)到服務(wù)器,您需要首先讀取完整的請(qǐng)求標(biāo)頭,然后才在客戶端和服務(wù)器之間轉(zhuǎn)發(fā)所有內(nèi)容。


查看完整回答
反對(duì) 回復(fù) 2023-03-07
  • 2 回答
  • 0 關(guān)注
  • 337 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)