Skip to content

[issue] Edge-case HTTP/2 support #709

Closed

Description

@sullo

Describe the bug
I stumbled upon an edge case where the server responds with HTTP/2 without an upgrade response to or from the client. Browsers, Burpsuite, curl, and some other tools take this in stride but the underly Golang libraries used by Nuclei are more strict.

Nuclei version
v2.3.2, compiled from github 05/23/2021.

Screenshot of the error or bug
I can't upload an image from here, so:

GET / HTTP/1.1
Host: <redacted>
User-Agent: Nuclei - Open-source project (github.com/projectdiscovery/nuclei)
HTTP/2 200 OK
Date: Thu, 13 May 2021 19:18:13 GMT
Content-Type: text/html;charset=UTF-8
Set-Cookie:...

I changed some of Nuclei's error handling so I could see more, and got:
net/http: HTTP/1.x transport connection broken: malformed HTTP version "HTTP/2"

Details

  • I don't see that nuclei is specifically disabling HTTP/2, and it should be enabled by default as of 1.6. I can confirm Nuclei works against https://http2.golang.org/.
  • After digging into Go's net/http quite too far, I think the problem lies in the fact that http/2 is supported but not very well implemented. This post details the exact some condition I found in the code--that Golang's request.go does not validate that HTTP/2 is valid (it would validate HTTP/2.0 though :/). The logic can be seen here in the ParseHTTPVersion function (line 783), and per this issue it's just simply not supported by Golang unless using net/http2.
  • According it's own page, net/http2 is a work in progress and the "client work has just started"

Suggestions

As this is an edge case and I'm not sure how many servers this may impact, so I'm not sure what the right answer is for Nuclei.

  • Obvious option is to start testing and using net/http2.
  • Don't use Golang's built-in http modules, instead use lower-level functionality where you manually build requests (I think I saw nuclei has some of this already). This might be a better long-term strategy as Nuclei grows and tries to support more complex and non-standard requests.
  • "Override" the Golang error by forcing the response to be HTTP/2.0 as talked about here or here (the latter seeming more straightforward).
  • Ignore me and my edge case. I used Burp to change the HTTP version. But perhaps spit out a warning that suggests a user do that.

I don't mind working on this and test it if I can get some direction from the core team as to how it could be fixed, or if this shouldn't be considered now. FWIW, back in the day I had to quickly move off perl's built in HTTP libraries because of things like this, so Nuclei should consider the future.

Cheers!

Activity

  1. ehsandeep commented on May 13, 2021

    @ehsandeep
    Member

    @sullo woah! Just wanted to say, thank you for writing this well-detailed issue with a list of suggestions to address this. We are looking into this and will be addressing this in the coming release of nuclei.

  2. added
    Type: Bug
    Type: Enhancement
    on May 13, 2021
  3. sullo commented on May 14, 2021

    @sullo
    ContributorAuthor

    No problem @ehsandeep. Glad to help.

  4. self-assigned this
    on May 24, 2021
  5. linked a pull request that will close this issueUpdating retryablehttp with http2 support #731on May 25, 2021
  6. Mzack9999 commented on May 25, 2021

    @Mzack9999
    Member

    @sullo Thanks again for the very detailed analysis. After further tests, it looks like that the http2 connection upgrade is already supported by the standard net/http library. I wasn't able to find a target replying directly with http/2 and noticed the behavior happens mostly when using Burp as a proxy, as a conversion layer wraps the http/1.x protocol to the binary http/2 one, but leaves the http/2 version when converting back to http/1.x representation, basically:

    nuclei => http/1.x => burp => http/2 => target
    nuclei <= http/2 <= burp <= http/2 <= target
    

    The returned version lacks the minor version number required by the net/http library. I think the library implementation might be the correct one, as the stream happens within the http/1.x context and according to RFC2145, both major and minor version needs to be specified.
    I've implemented a patch in retryablehttp consisting of a retry strategy with a transport layer compatible with http/2 if the go error is related to http/2 over http/1.x. Most likely, we will implement some low-level libraries to support non-standard requests (e.g., for http/2 smuggling). Please let us know if this fixes the issue.

  7. added and removed
    Type: Enhancement
    on May 26, 2021
  8. sullo commented on May 27, 2021

    @sullo
    ContributorAuthor

    Trying those changes out but I'm experiencing the same behavior.

    Curl:

    ╰─○ curl -v https://<redacted>/
    *   Trying 10.47.193.158...
    * TCP_NODELAY set
    * Connected to <redacted> (<redacted>) port 443 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    [ ssl things]
    * Using HTTP2, server supports multi-use
    * Connection state changed (HTTP/2 confirmed)
    * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
    * Using Stream ID: 1 (easy handle 0x7fa1a080d600)
    > GET / HTTP/2
    > Host: <redacted>
    > User-Agent: curl/7.64.1
    > Accept: */*
    >
    * Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
    < HTTP/2 200
    < date: Thu, 27 May 2021 19:00:09 GMT
    < content-type: text/html;charset=UTF-8
    [content]
    

    When connecting directly , it still doesn't see the response from the server:

    [INF] [compal-panel-detect] Dumped HTTP request for https://<redacted>/
    
    GET /common_page/login.html HTTP/1.1
    Host: <redacted>
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36
    Connection: close
    Accept: */*
    Accept-Language: en
    Accept-Encoding: gzip
    
    [WRN] [compal-panel-detect] Could not execute request for https://<redacted>/: GET https://<redacted>/common_page/login.html giving up after 2 attempts: Get "https://<redacted>/common_page/login.html": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
    [INF] No results found. Better luck next time!
    

    However, going through burpsuite (without changing HTTP/2 to HTTP/2.0 manually via a replace), it does see the 404:

    ╰─⠠⠵ ./nuclei -t ~/nuclei-templates/exposed-panels/compal-panel.yaml -u https://<redacted>/ -debug-resp -debug-req -debug -proxy-url http://localhost:8080/
    
    [snipped for brevity]
    
    GET /common_page/login.html HTTP/1.1
    Host: <redacted>
    User-Agent: Mozilla/5.0 (Windows NT 4.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36
    Connection: close
    Accept: */*
    Accept-Language: en
    Accept-Encoding: gzip
    
    [INF] [compal-panel-detect] Dumped HTTP response for https://<redacted>/common_page/login.html
    
    HTTP/2.0 404 Not Found
    Content-Length: 1100
    Content-Language: en
    Content-Type: text/html;charset=utf-8
    Date: Thu, 27 May 2021 20:12:56 GMT
    
    
    <!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title>...
    [INF] No results found. Better luck next time!
    

    It seems likely Burp is fixing the HTTP/2 in the background.

  9. ehsandeep commented on Jun 3, 2021

    @ehsandeep
    Member

    Hi @sullo,

    Just to double-check, we pushed the fix in the following PR #731. Can you please confirm if you tested the fix with binary built from this PR, otherwise do you have an example host with this edge case that you can share will be helpful to confirm or prepare a new fix on our side?

  10. added
    Status: Review Needed
    on Jun 3, 2021
  11. dpnishant commented on Jun 7, 2021

    @dpnishant

    Doesn't seem to be fixed yet.
    Screen Shot 2021-06-06 at 5 47 54 PM

  12. ehsandeep commented on Jun 7, 2021

    @ehsandeep
    Member

    @dpnishant thanks for checking, I'm not sure if you checked out the PR branch and build binary to test changes, here is how you can do it if not already.

    Building Nuclei from bugfix-709-http2 branch.

    git clone https://github.com/projectdiscovery/nuclei.git; cd nuclei/v2/cmd/nuclei; git checkout bugfix-709-http2; go build
    

    Running nuclei binary build frombugfix-709-http2 branch.

    ./nuclei -u https://mobile.twitter.com -proxy-url http://127.0.0.1:8080 -t .
    
  13. dpnishant commented on Jun 8, 2021

    @dpnishant

    @ehsandeep Yes I haven't tried with a local PR build. Will give it a shot.

  14. ehsandeep commented on Jun 12, 2021

    @ehsandeep
    Member

    Closing as this has been resolved and fixed in the latest release, fix is verified locally, we can reopen this again if we encounter more new edge cases to handle.

  15. added
    Status: Completed
    and removed
    Status: Review Needed
    on Jun 12, 2021
  16. sullo commented on Jun 17, 2021

    @sullo
    ContributorAuthor

    Sorry I fell into a black-hole for a week here... but can confirm this is resolved. Thanks for the great support!

  17. ehsandeep commented on Jun 17, 2021

    @ehsandeep
    Member

    Thanks again for confirming @sullo

  18. added
    Type: Enhancement
    and removed on Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Status: CompletedType: BugType: Enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions