Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion protocols/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 18 additions & 0 deletions protocols/tcp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"log/slog"
"net"
"net/http"
Expand Down Expand Up @@ -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)
Expand Down