Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handler for HTTP2/PRI #178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Beeram12
Copy link

@Beeram12 Beeram12 commented Mar 8, 2025

fixes #159

Key Changes

  1. Added PRI in protocols.go to httpMap such that it detects HTTP/2 connections
  2. Modified HandleHTTP function in tcp/http.go
  3. In the handler it reads the first 24 bytes (exact length of HTTP/2 client preface: PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n) and checks if data matches with HTTP/2 preface
  4. The server then responds with a minimal settings frame .

@glaslos
If there are any changes to be made I am ready to modify them.

@@ -75,7 +75,7 @@ func MapTCPProtocolHandlers(log interfaces.Logger, h interfaces.Honeypot) map[st
return nil
}
// poor mans check for HTTP request
httpMap := map[string]bool{"GET ": true, "POST": true, "HEAD": true, "OPTI": true, "CONN": true}
httpMap := map[string]bool{"GET ": true, "POST": true, "HEAD": true, "OPTI": true, "CONN": true,"PRI": true}
Copy link
Member

Choose a reason for hiding this comment

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

please use go fmt

Copy link
Author

Choose a reason for hiding this comment

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

Formatted the code


reader := bufio.NewReader(conn)
preface,err := reader.Peek(24)
if err==nil && bytes.Equal(preface, []byte("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")){
Copy link
Member

Choose a reason for hiding this comment

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

in go we handle the error case in the conditional

Copy link
Author

Choose a reason for hiding this comment

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

errors handled in conditional

@Beeram12
Copy link
Author

@glaslos I modified code as stated if anything needed to be still changed please let me know.

@Beeram12 Beeram12 requested a review from glaslos March 13, 2025 08:07
@glaslos
Copy link
Member

glaslos commented Mar 21, 2025

Please add a test for your change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add handler for HTTP/2 PRI
2 participants