Skip to content

go1.19 std h1/h2 native unsafe http - #112

Open
Mzack9999 wants to merge 10 commits into
mainfrom
issue-22-go1.19-fork
Open

go1.19 std h1/h2 native unsafe http#112
Mzack9999 wants to merge 10 commits into
mainfrom
issue-22-go1.19-fork

Conversation

@Mzack9999

Copy link
Copy Markdown
Member

The PR covers the following issues:

@Mzack9999Mzack9999 added the Type: Enhancement Most issues will probably ask for additions or changes. label Mar 28, 2023
@Mzack9999Mzack9999 self-assigned this Mar 28, 2023
@Mzack9999
Mzack9999 marked this pull request as ready for review March 29, 2023 20:57
@Mzack9999
Mzack9999 marked this pull request as draft March 29, 2023 22:52

@tarunKoyalwartarunKoyalwar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was able to test h1 example provided at example/httpclient/h1/main.go

$ go run .[*] standard request------------------------------[+] Request:GET /standard HTTP/1.1Host: scanme.shUser-Agent: Go-http-client/1.1Accept-Encoding: gzip[+] Response:HTTP/1.1 200 OKContent-Length: 2Content-Type: text/plain; charset=utf-8Date: Fri, 19 May 2023 12:20:23 GMTok[*] request with invalid header:------------------------------[+] Request:GET /invalid-header HTTP/1.1Host: scanme.shUser-Agent: Go-http-client/1.1test test: testAccept-Encoding: gzip[+] Response:HTTP/1.1 400 Bad Request: invalid header nameConnection: closeContent-Type: text/plain; charset=utf-8400 Bad Request: invalid header name[*] request with unescaped path------------------------------[+] Request:GET /?bar=;&baz=foobar&abc&xyz=&ikj=n;m "'@ HTTP/1.1Host: scanme.shUser-Agent: Go-http-client/1.1Accept-Encoding: gzip[+] Response:HTTP/1.1 400 Bad RequestConnection: closeContent-Type: text/plain; charset=utf-8400 Bad Request[*] request with proxy (burp/proxify must be listening on port 8080)------------------------------[+] Request:GET / HTTP/1.1Host: scanme.shUser-Agent: Go-http-client/1.1Accept-Encoding: gzip[+] Response:HTTP/1.1 200 OKConnection: closeContent-Length: 2Content-Type: text/plain; charset=utf-8Date: Fri, 19 May 2023 12:20:23 GMTok
  • example provided in h2/main.go does not seems to work

Suggesting Changes / Discussion

  • since we are forking go stdlib we should update existing directory structure to make it more easy to read/review and maintain as well as to update based on any upstream changes
    suggesting changing existing directory structure to
fork/crypto
fork/internal
fork/net
fork/README.md
fork/Notes.md
fork/metadata [if any]

^ seems necessary to provide proper/easy distinction b/w packages
by doing this we are sure all fork packages are available at /fork and we can implement some kind of diff to track any changes with std lib

  • Since we have forked stdlib packages i think it is necessary to make proper distinction b/w what fields / functions were added/updated. we could do this by following a naming convention such as Custom_xxx or Fork_xxx that would provide proper distinction b/w newly added fields/functions . currently we are not following any convention so it is extremely difficult to find/validate changes (ref:

    HeaderSeparatorstring
    NewLinestring
    UseLastValidResponsebool
    AutomaticContentLengthbool
    AutomaticHostHeaderbool
    Unsafebool
    AutomaticUserAgentbool
    AutomaticAcceptEndocingbool
    AutomaticSchemebool
    AutomaticMethodbool
    AutomaticPathbool
    )

  • we could also add unit tests for h1/main.go and h2/main.go

Comment on lines +1 to +47
package main

import (
"log"
"net"
"strings"

"github.com/projectdiscovery/rawhttp/crypto/tls"
"github.com/projectdiscovery/rawhttp/example/httpclient"

// normal
// "net/http"
// "golang.org/x/net/http2"
// weaponized
"github.com/projectdiscovery/rawhttp/net/http"
"github.com/projectdiscovery/rawhttp/net/http2"
)

func main() {
log.SetFlags(0)
client := http.Client{
Transport: &http2.Transport{
AllowHTTP: true,
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(network, addr)
},
},
}

log.Println("[*] Malformed Header")
req, err := http.NewRequest("GET", "http://localhost:8000", nil)
if err != nil {
log.Fatal(err)
}
// some malformed header
req.Header.Add("TeSt ", "test")
req.Header["Test"] = []string{"test"}

_, err = httpclient.SendAndDump(&client, req)
if err != nil {
log.Printf("[Client] error: %s\n", err)
}

log.Println("[*] H2.CL desync")
// https://youtu.be/gAnDUoq1NzQ?t=672 - H2.CL desync
payload := "abcdGET /n HTTP/1.1\r\nHost: 02.rs?localhost\r\nFoo: bar"
req1, err := http.NewRequest(http.MethodPost, "http://localhost:8000/n", strings.NewReader(payload))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mzack9999 h2 seems to be not working at all . does this require any special setup i tried it with simplehttpserver but couldn't get it to work

$ (rawhttp/example/httpclient/h2) go run .[*] Malformed Header[Client] error: Get "http://localhost:8000": invalid HTTP header name "TeSt "[*] H2.CL desync[Client] error: Post "http://localhost:8000/n": unexpected EOF[*] H2.TE desync[Client] error: Post "http://localhost:8000/identify/XUI": read tcp [::1]:50913->[::1]:8000: read: connection reset by peer[*] H2.TE via request header injection[Client] error: Get "http://localhost:8000": invalid HTTP header name "TeSt "[*] H2.TE via request splitting[Client] error: Get "http://localhost:8000/": read tcp [::1]:50914->[::1]:8000: read: connection reset by peer[*] H2.TE via request line injection[Client] error: Get "http://localhost:8000/ignored": read tcp [::1]:50915->[::1]:8000: read: connection reset by peer[*] Header name splitting[Client] error: Post "http://localhost:8000/": read tcp [::1]:50916->[::1]:8000: read: connection reset by peer[*] Fake path[Client] error: Post "http://localhost:8000/": read tcp [::1]:50917->[::1]:8000: read: connection reset by peer
$ simplehttpserver  _____ _ __ __ __________________  / ___/(_)___ ___ ____ / /__ / / / /_ __/_ __/ __ \________ ______ _____ _____ \__ \/ / __ -__ \/ __ \/ / _ \/ /_/ / / / / / / /_/ / ___/ _ \/ ___/ | / / _ \/ ___/ ___/ / / / / / / / /_/ / / __/ __ / / / / / / ____(__ ) __/ / | |/ / __/ / /____/_/_/ /_/ /_/ .___/_/\___/_/ /_/ /_/ /_/ /_/ /____/\___/_/ |___/\___/_/  /_/ - v0.0.5 projectdiscovery.ioUse with caution. You are responsible for your actionsDevelopers assume no liability and are not responsible for any misuse or damage.Serving /Users/tarun/Codebase/rawhttp/example/httpclient/h2 on http://0.0.0.0:8000/[2023-05-19 17:48:30] [::1]:50912 "PRI * HTTP/2.0" 405 10[2023-05-19 17:48:30] [::1]:50913 "PRI * HTTP/2.0" 405 10[2023-05-19 17:48:30] [::1]:50914 "PRI * HTTP/2.0" 405 10[2023-05-19 17:48:30] [::1]:50915 "PRI * HTTP/2.0" 405 10[2023-05-19 17:48:30] [::1]:50916 "PRI * HTTP/2.0" 405 10[2023-05-19 17:48:30] [::1]:50917 "PRI * HTTP/2.0" 405 10

@shubham-dogra-s1

Copy link
Copy Markdown

@Mzack9999 when this pr be merged any timeline?

@dogancanbakir

Copy link
Copy Markdown
Member

bump

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: EnhancementMost issues will probably ask for additions or changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for http proxy HTTP/2 Support

5 participants

@Mzack9999@shubham-dogra-s1@dogancanbakir@tarunKoyalwar@ehsandeep