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

feat: Add responses for TCP #168

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

Conversation

milinddethe15
Copy link

fixes #53

TCP handler can handle other target ports without need of seperate port handlers.

Signed-off-by: milinddethe15 <[email protected]>
Copy link
Member

@glaslos glaslos left a comment

Choose a reason for hiding this comment

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

Please add a README.md into the responses folder with a not where the responses are sourced from.

protocols/tcp/tcp.go Outdated Show resolved Hide resolved
protocols/tcp/tcp.go Outdated Show resolved Hide resolved
protocols/tcp/tcp.go Outdated Show resolved Hide resolved
protocols/tcp/tcp.go Outdated Show resolved Hide resolved
protocols/tcp/tcp.go Outdated Show resolved Hide resolved
@milinddethe15
Copy link
Author

Just to confirm:

  1. Banner should be send intially, when connected
  2. then read conn
  3. and if read conn payload > max_tcp_payload: send random data and break?

@glaslos
Copy link
Member

glaslos commented Jan 30, 2025

1 and 2 is correct. For 3, just read once, no need to read until max payload, that is just protection.

Signed-off-by: milinddethe15 <[email protected]>
@milinddethe15
Copy link
Author

what tool should I use to hit the target?
I tried telnet 127.0.0.1 4444 but banner wasn't received when connected.

@glaslos
Copy link
Member

glaslos commented Jan 30, 2025

try netcat: nc

@milinddethe15
Copy link
Author

I tried to test it and the banner isn't sent as soon as connected, but until attacker's payload. Is this how it should work?

@glaslos
Copy link
Member

glaslos commented Jan 31, 2025

You need to send the banner before we peek the connection here

Signed-off-by: milinddethe15 <[email protected]>
@milinddethe15
Copy link
Author

Tested locally with TCP port 4444. works good.

@milinddethe15 milinddethe15 requested a review from glaslos January 31, 2025 09:47
//go:embed banners/*
var bannerFiles embed.FS

func SendBanner(conn net.Conn, port uint16) error {
Copy link
Member

Choose a reason for hiding this comment

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

Needs doc string


func SendBanner(conn net.Conn, port uint16) error {
bannerPath := fmt.Sprintf("banners/%d_tcp", port)
banner, err := bannerFiles.ReadFile(bannerPath)
Copy link
Member

Choose a reason for hiding this comment

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

open the file and then use io.Copy to write the file content into the connection.

}
if _, err := conn.Write(banner); err != nil {
return fmt.Errorf("failed to write banner: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

We still want to produce an event after sending the banner, see example

Comment on lines +69 to +71
if err := tcp.SendBanner(conn, md.TargetPort); err != nil {
log.Error("failed to send service banner", producer.ErrAttr(err))
}
Copy link
Member

Choose a reason for hiding this comment

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

My concern now is that we write the banner without peeking and potentially detecting the HTTP payload. Maybe we should try to read it and, if we time out, send the banner.

@glaslos
Copy link
Member

glaslos commented Jan 31, 2025

Have a look at the failing test.

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 honeytrap service banners
2 participants