Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion protocols/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Formatted the code

if _, ok := httpMap[strings.ToUpper(string(snip))]; ok {
return tcp.HandleHTTP(ctx, bufConn, md, log, h)
}
Expand Down
10 changes: 9 additions & 1 deletion protocols/tcp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ func HandleHTTP(ctx context.Context, conn net.Conn, md connection.Metadata, logg
logger.Error("Failed to close the HTTP connection", producer.ErrAttr(err))
}
}()


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
Copy Markdown
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
Copy Markdown
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

settingsFrame := []byte("\x00\x00\x00\x04\x00\x00\x00\x00\x00")
_,_ = conn.Write(settingsFrame)
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