├── LICENSE ├── README.md ├── client └── client.go ├── common.go └── server └── server.go /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # httpt 2 | Prototype of circumvention system described in https://www.usenix.org/conference/foci20/presentation/frolov 3 | -------------------------------------------------------------------------------- /client/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "encoding/base64" 6 | "errors" 7 | "flag" 8 | tls "github.com/refraction-networking/utls" 9 | "httpt" 10 | "log" 11 | "net" 12 | "net/http" 13 | "net/http/httputil" 14 | "strconv" 15 | "strings" 16 | ) 17 | 18 | // TODO: clean up descriptions 19 | var mode = flag.String("mode", "http", "transparent/http.") 20 | var debug = flag.Bool("debug", true, "Enable debug output.") 21 | var port = flag.Int("port", 4714, "Port for local transparent proxy") 22 | var addr = flag.String("addr", "52.33.220.110:443", "") 23 | var sni = flag.String("sni", "sfrolov.io", "") 24 | var secretLink = flag.String("secret", "secretLink", "") 25 | 26 | var bufferSize = flag.Int("buffer", 0, "Size of buffer (in KB) for local buffering per connection. Set to 0 to turn off.") 27 | 28 | // TODO: try using/expanding the HTTPS client: use github.com/caddyserver/forwardproxy/httpclient ? 29 | 30 | var tlsDialer *tls.Roller 31 | 32 | // TODO: make error print vs dont before exit consistent 33 | func DialWS(addr string, args map[string]string, targetAddr string, hello []byte) (net.Conn, []byte, error) { 34 | serverName, ok := args["serverName"] 35 | if !ok || serverName == "" { 36 | err := errors.New("serverName argument is missing") 37 | log.Println(err) 38 | return nil, nil, err 39 | } 40 | 41 | secretLink, ok := args["secretLink"] 42 | if !ok || secretLink == "" { 43 | err := errors.New("secretLink argument is missing") 44 | log.Println(err) 45 | return nil, nil, err 46 | } 47 | 48 | // // if reframerID is nil, creates new connection to reframer server 49 | // establish TLS to server 50 | // send HTTP/1.1 WS request. It will include the ID to reconnect, if reconnecting 51 | // WS response will include in the headers the InitialState or ReconnectState 52 | conn, err := tlsDialer.Dial("tcp", addr, serverName) 53 | if err != nil { 54 | log.Println(err) 55 | return nil, nil, err 56 | } 57 | 58 | log.Printf("[uTLS] mimicking %v. ALPN offered: %v, chosen: %v\n", 59 | conn.ClientHelloID.Str(), conn.HandshakeState.Hello.AlpnProtocols, conn.HandshakeState.ServerHello.AlpnProtocol) 60 | 61 | switch conn.HandshakeState.ServerHello.AlpnProtocol { 62 | case "http/1.1", "": 63 | req, err := http.NewRequest("GET", "/"+secretLink, nil) 64 | if err != nil { 65 | log.Println(err) 66 | return nil, nil, err 67 | } 68 | req.Host = serverName 69 | 70 | req.Header.Set("Connection", "Upgrade") 71 | req.Header.Set("Upgrade", "websocket") 72 | req.Header.Set("X-ReframerCH", base64.StdEncoding.EncodeToString(hello)) 73 | req.Header.Set("X-TargetAddr", targetAddr) 74 | 75 | // TODO: req.Header.Set("X-Padding", "[][]") 76 | 77 | err = req.Write(conn) 78 | if err != nil { 79 | log.Printf("failed to write WebSocket Upgrade Request: %v\n", err) 80 | return nil, nil, err 81 | } 82 | log.Println("DEBUG wrote req, err", err) 83 | 84 | resp, err := http.ReadResponse(bufio.NewReader(conn), req) 85 | if err != nil { 86 | log.Println(err) 87 | return nil, nil, err 88 | } 89 | 90 | if resp.Status == "101 Switching Protocols" && 91 | strings.ToLower(resp.Header.Get("Upgrade")) == "websocket" && 92 | strings.ToLower(resp.Header.Get("Connection")) == "upgrade" { 93 | 94 | serverHello, err := base64.StdEncoding.DecodeString(resp.Header.Get("X-ReframerSH")) 95 | if err != nil { 96 | return nil, nil, err 97 | } 98 | 99 | return conn, serverHello, nil 100 | } else { 101 | respBytes, err := httputil.DumpResponse(resp, false) 102 | if err != nil { 103 | log.Println(err) 104 | return nil, nil, err 105 | } 106 | err = errors.New("Got unexpected response:\n" + string(respBytes) + "\nstatus:" + resp.Status) 107 | log.Println(err) 108 | return nil, nil, err 109 | } 110 | case "h2": 111 | return nil, nil, errors.New("http2 is not implemented yet") 112 | default: 113 | return nil, nil, errors.New("Unknown ALPN: " + conn.HandshakeState.ServerHello.AlpnProtocol) 114 | } 115 | 116 | return nil, nil, err 117 | } 118 | 119 | func main() { 120 | flag.Parse() 121 | 122 | if *debug { 123 | log.SetFlags(log.Lmicroseconds | log.Lshortfile) 124 | } else { 125 | log.SetFlags(log.Lmicroseconds | log.Ldate) 126 | } 127 | log.SetPrefix("[init] ") 128 | 129 | // hook up Reframer with: 130 | // func DialWS(id connectionID) 131 | var err error 132 | tlsDialer, err = tls.NewRoller() 133 | if err != nil { 134 | log.Fatal(err) 135 | } 136 | 137 | // Remove all ClientHellos that have ALPN, as h2 is not supported yet. 138 | // TODO: remove next line when h2 is implemented 139 | //tlsDialer.HelloIDs = []tls.ClientHelloID{tls.HelloChrome_58} 140 | tlsDialer.HelloIDs = []tls.ClientHelloID{tls.HelloRandomizedNoALPN} 141 | 142 | switch *mode { 143 | case "test": 144 | //conn, err := DialWS(0, "52.33.220.110:443", map[string]string{"serverName" : "sfrolov.io", 145 | // "secretLink" : "secretLink"}) 146 | //if err != nil { 147 | // log.Fatalln(err) 148 | //} 149 | //_ = DialWS(0, "52.33.220.110:2443", map[string]string{"serverName" : "sfrolov.io", 150 | // "secretLink" : "secretLink"}) 151 | //_ = DialWS(0, "52.33.220.110:3443", map[string]string{"serverName" : "sfrolov.io", 152 | // "secretLink" : "secretLink"}) 153 | case "http": 154 | ln, err := net.Listen("tcp", "localhost:"+strconv.Itoa(*port)) 155 | if err != nil { 156 | log.Fatalln(err) 157 | } 158 | log.Println("Listening for incoming connections on", ln.Addr().String()) 159 | // TODO: more info where connecting and with which options 160 | 161 | log.SetPrefix("[runtime] ") 162 | for { 163 | clientConn, err := ln.Accept() 164 | if err != nil { 165 | log.Println("Failed to accept connection:", err) 166 | continue 167 | } 168 | go handleConn(clientConn) 169 | } 170 | case "transparent": 171 | default: 172 | panic("unknown mode") 173 | } 174 | } 175 | 176 | func handleConn(clientConn net.Conn) { 177 | defer clientConn.Close() 178 | 179 | log.SetPrefix("["+ clientConn.RemoteAddr().String() + "] ") 180 | 181 | req, err := http.ReadRequest(bufio.NewReader(clientConn)) 182 | if err != nil { 183 | log.Println(err) 184 | return 185 | } 186 | 187 | if req.Method != "CONNECT" { 188 | dump, dumpErr := httputil.DumpRequest(req, true) 189 | log.Println("unexpected request" , dump, "\nerror:", dumpErr) 190 | return 191 | } 192 | 193 | res := &http.Response{StatusCode: http.StatusOK, 194 | Proto: "HTTP/1.1", 195 | ProtoMajor: 1, 196 | ProtoMinor: 1, 197 | Header: make(http.Header), 198 | } 199 | err = res.Write(clientConn) 200 | if err != nil { 201 | log.Fatalln(err) 202 | } 203 | 204 | hello := make([]byte, 1024) 205 | n, err := clientConn.Read(hello) 206 | if err != nil { 207 | log.Println("failed to read client hello:", hello) 208 | return 209 | } 210 | 211 | serverConn, _, err := DialWS(*addr, map[string]string{"serverName": *sni, 212 | "secretLink": *secretLink}, req.RequestURI, hello[:n]) 213 | if err != nil { 214 | log.Fatalln(err) 215 | } 216 | 217 | 218 | httpt.TransparentProxy(clientConn, serverConn) 219 | } 220 | -------------------------------------------------------------------------------- /common.go: -------------------------------------------------------------------------------- 1 | package httpt 2 | 3 | import ( 4 | "io" 5 | "sync" 6 | ) 7 | 8 | func TransparentProxy(clientConn, serverConn io.ReadWriteCloser) error { 9 | wg := sync.WaitGroup{} 10 | wg.Add(2) 11 | 12 | copyAndCloseWrite := func(dst io.WriteCloser, src io.ReadCloser) error { 13 | _, err := io.Copy(dst, src) 14 | if closeWriter, ok := dst.(interface { 15 | CloseWrite() error 16 | }); ok { 17 | closeWriter.CloseWrite() 18 | } else { 19 | dst.Close() 20 | } 21 | wg.Done() 22 | return err 23 | } 24 | 25 | go copyAndCloseWrite(serverConn, clientConn) 26 | err := copyAndCloseWrite(clientConn, serverConn) 27 | 28 | wg.Wait() 29 | return err 30 | } 31 | -------------------------------------------------------------------------------- /server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "encoding/base64" 6 | "flag" 7 | "fmt" 8 | "httpt" 9 | "log" 10 | "net" 11 | "net/http" 12 | "net/http/httputil" 13 | "strings" 14 | ) 15 | 16 | var secretLink = flag.String("secret-link", "secretLink", "TODO") // TODO: description 17 | var debug = flag.Bool("debug", true, "Enable debug output. Default: TODO.") // TODO 18 | var statsPeriod = flag.Int("stats-period", 1, "Period in minutes for printing aggregate stats."+ 19 | "Set to 0 to disable aggregate stats printing. Default: 1 minute.") 20 | var addr = flag.String("addr", "localhost:4714", "Transparent proxy target") 21 | var mode = flag.String("mode", "transparent", "tor/transparent/TODO") // TODO 22 | 23 | func debugPrintln(v ...interface{}) { 24 | if *debug { 25 | log.Println(v) 26 | } 27 | } 28 | 29 | func debugPrintf(format string, v ...interface{}) { 30 | if *debug { 31 | log.Printf(format, v) 32 | } 33 | } 34 | 35 | // Reads ClientHello from the connection. 36 | // Returns addr, hello, http req, and error 37 | func ReadInitiaWSRequest(clientConn net.Conn) (string, []byte, interface{}, error) { 38 | expectedH1Req := "GET /" + *secretLink 39 | log.SetPrefix(fmt.Sprintf("[%s] ", clientConn.RemoteAddr().String())) 40 | connReader := bufio.NewReader(clientConn) 41 | 42 | firstBytes, err := connReader.Peek(len(expectedH1Req)) 43 | if err != nil { 44 | return "", nil, nil, err 45 | } 46 | 47 | if string(firstBytes) == expectedH1Req { 48 | req, err := http.ReadRequest(connReader) 49 | if err != nil { 50 | return "", nil, nil, err 51 | } 52 | 53 | if strings.ToLower(req.Header.Get("Connection")) != "upgrade" { 54 | return "", nil, nil, fmt.Errorf("Connection header expected: upgrade, got: %s\n", 55 | strings.ToLower(req.Header.Get("Connection"))) 56 | } 57 | if strings.ToLower(req.Header.Get("Upgrade")) != "websocket" { 58 | return "", nil, nil, fmt.Errorf("Upgrade header expected: websocket, got: %s\n", 59 | strings.ToLower(req.Header.Get("Upgrade"))) 60 | } 61 | 62 | clientHello, err := base64.StdEncoding.DecodeString(req.Header.Get("X-ReframerCH")) 63 | if err != nil { 64 | return "", nil, nil, err 65 | } 66 | targetAddr := req.Header.Get("X-TargetAddr") 67 | 68 | return targetAddr, clientHello, req, nil 69 | } else { 70 | // TODO: golang.org/x/net/http2 instead 71 | req, err := http.ReadRequest(connReader) 72 | if err != nil { 73 | log.Println(err) 74 | return "", nil, nil, err 75 | } 76 | reqBytes, err := httputil.DumpRequest(req, false) 77 | log.Println(string(reqBytes), err) 78 | return "", nil, nil, err 79 | } 80 | } 81 | 82 | func GenerateInitialWSResponse(hello []byte, _req interface{}) ([]byte, error) { 83 | req, ok := _req.(*http.Request) 84 | if !ok { 85 | panic(_req) 86 | } 87 | 88 | resp := http.Response{ 89 | Status: "101 Switching Protocols", 90 | StatusCode: 101, 91 | Proto: "HTTP/1.1", 92 | ProtoMajor: 1, 93 | ProtoMinor: 1, 94 | Header: http.Header{}, 95 | Body: nil, 96 | ContentLength: 0, 97 | TransferEncoding: nil, 98 | Close: false, 99 | Uncompressed: false, 100 | Trailer: nil, 101 | Request: nil, 102 | TLS: nil, 103 | } 104 | resp.Header.Set("Upgrade", req.Header.Get("Upgrade")) 105 | resp.Header.Set("Connection", req.Header.Get("Connection")) 106 | if len(hello) > 0 { 107 | resp.Header.Set("X-ReframerSH", base64.StdEncoding.EncodeToString(hello)) 108 | } 109 | 110 | log.Println("GenerateInitialWSResponse") 111 | return httputil.DumpResponse(&resp, true) 112 | } 113 | 114 | func handleConn(clientConn net.Conn) error { 115 | log.SetPrefix("["+ clientConn.LocalAddr().String() + "] ") 116 | defer func() { 117 | closeErr := clientConn.Close() 118 | if closeErr == nil { 119 | log.Println("Closed Connection") 120 | } else { 121 | log.Printf("Closed Connection with error: %v\n", closeErr) 122 | } 123 | }() 124 | 125 | targetAddr, clientHello, req, err := ReadInitiaWSRequest(clientConn) 126 | if err != nil { 127 | log.Println("error reading initial request", err) 128 | return err 129 | } 130 | 131 | serverConn, err := net.Dial("tcp", targetAddr) 132 | log.Println("connecting to ", targetAddr) 133 | if err != nil { 134 | log.Println("failed to connect to ", targetAddr, "error:", err) 135 | return err 136 | } 137 | 138 | resp, err := GenerateInitialWSResponse(nil, req) 139 | if err != nil { 140 | log.Println("error generating ws response", err) 141 | return err 142 | } 143 | 144 | _, err = clientConn.Write(resp) 145 | if err != nil { 146 | log.Println("error writing ws response", err) 147 | return err 148 | } 149 | 150 | _, err = serverConn.Write(clientHello) 151 | if err != nil { 152 | log.Println("error sending initial client request to the target:", err) 153 | return err 154 | } 155 | 156 | return httpt.TransparentProxy(clientConn, serverConn) 157 | } 158 | 159 | func main() { 160 | flag.Parse() 161 | 162 | if *debug { 163 | log.SetFlags(log.Lmicroseconds | log.Lshortfile) 164 | } else { 165 | log.SetFlags(log.Lmicroseconds | log.Ldate) 166 | } 167 | log.SetPrefix("[init] ") 168 | 169 | l, err := net.Listen("tcp", "127.0.0.1:5091") 170 | if err != nil { 171 | log.Fatalln(err) 172 | } 173 | log.Printf("Started HTTPT server at %v\n", l.Addr().String()) 174 | log.Printf("Secret Link is %v\n", *secretLink) 175 | // TODO: more info about config, exit etc here 176 | 177 | log.SetPrefix("[runtime] ") 178 | for { 179 | conn, err := l.Accept() 180 | if err != nil { 181 | log.Println("Failed to accept connection:", err) 182 | continue 183 | } 184 | go handleConn(conn) 185 | } 186 | } --------------------------------------------------------------------------------