diff --git a/protocols/protocols.go b/protocols/protocols.go index 31e9087..bd18fb0 100644 --- a/protocols/protocols.go +++ b/protocols/protocols.go @@ -75,7 +75,14 @@ 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, + } if _, ok := httpMap[strings.ToUpper(string(snip))]; ok { return tcp.HandleHTTP(ctx, bufConn, md, log, h) } diff --git a/protocols/tcp/http.go b/protocols/tcp/http.go index 221ffbb..6b74fd9 100644 --- a/protocols/tcp/http.go +++ b/protocols/tcp/http.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io" "log/slog" "net" "net/http" @@ -124,6 +125,23 @@ func HandleHTTP(ctx context.Context, conn net.Conn, md connection.Metadata, logg } }() + reader := bufio.NewReader(conn) + preface, err := reader.Peek(24) + if err != nil { + if err == io.EOF { + logger.Debug("Client disconneted early") + return nil + } + return fmt.Errorf("failed to peek HTTP/2 preface: %w", err) + } + if bytes.Equal(preface, []byte("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")) { + settingsFrame := []byte("\x00\x00\x00\x04\x00\x00\x00\x00\x00") + if _, err := conn.Write(settingsFrame); err != nil { + logger.Error("Failed to write HTTP/2 response", slog.String("error", err.Error())) + } + return conn.Close() + } + req, err := http.ReadRequest(bufio.NewReader(conn)) if err != nil { return fmt.Errorf("failed to read the HTTP request: %w", err)