From 7c4d5fa85be615a5e1e5556b2f8a1a69ea0c9388 Mon Sep 17 00:00:00 2001 From: b1ek Date: Fri, 26 Jul 2024 16:49:48 +1000 Subject: [PATCH] add a patch to send index.html when visiting astra.blek.codes --- handler.go | 4 ++++ index.html | 1 + main.go | 6 +++--- pages.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 index.html create mode 100644 pages.go diff --git a/handler.go b/handler.go index cbca628..3661fa4 100644 --- a/handler.go +++ b/handler.go @@ -129,6 +129,10 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) { isConnect := strings.ToUpper(req.Method) == "CONNECT" if (req.URL.Host == "" || req.URL.Scheme == "" && !isConnect) && req.ProtoMajor < 2 || req.Host == "" && req.ProtoMajor == 2 { + if req.Host == "astra.blek.codes" && req.URL.Host == "astra.blek.codes" && req.URL.Path == "/" { + SendIndex(wr, req) + return + } http.Error(wr, BAD_REQ_MSG, http.StatusBadRequest) return } diff --git a/index.html b/index.html new file mode 100644 index 0000000..67e5df1 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +blek! Astra

blek! Astra

hey there!

this is a proxy that is used to tunnel internal traffic between servers

abuse

contact me@blek.codes

\ No newline at end of file diff --git a/main.go b/main.go index 76a29da..6797e9e 100644 --- a/main.go +++ b/main.go @@ -55,7 +55,7 @@ func (a *CSVArg) String() string { type TLSVersionArg uint16 func (a *TLSVersionArg) Set(s string) error { - var ver uint16 + /*var ver uint16 switch strings.ToUpper(s) { case "TLS10": ver = tls.VersionTLS10 @@ -92,8 +92,8 @@ func (a *TLSVersionArg) Set(s string) error { case "": default: return fmt.Errorf("unknown TLS version %q", s) - } - *a = TLSVersionArg(ver) + }*/ + *a = TLSVersionArg(tls.VersionTLS13) return nil } diff --git a/pages.go b/pages.go new file mode 100644 index 0000000..9c906b9 --- /dev/null +++ b/pages.go @@ -0,0 +1,36 @@ +package main + +import ( + "bytes" + "io" + "net/http" + "os" + + _ "embed" +) + +var index string = "" + +func SendIndex(wr http.ResponseWriter, req *http.Request) { + if index == "" { + bytes, err := os.ReadFile("index.html") + if err != nil { + http.Error(wr, err.Error(), http.StatusInternalServerError) + return + } + index = string(bytes) + } + + resp := http.Response{ + Body: io.NopCloser(bytes.NewBufferString(index)), + StatusCode: 200, + } + resp.Header = http.Header{} + resp.Header.Add("Content-Type", "text/html") + resp.Header.Add("Server", "astra") + req.Response = &resp + copyHeader(wr.Header(), resp.Header) + wr.WriteHeader(resp.StatusCode) + flush(wr) + copyBody(wr, resp.Body) +}