mirror of
https://github.com/shazow/ssh-chat.git
synced 2026-10-22 23:52:12 +03:00
This commit introduces mechanism to limit the number of concurrent SSH
handshakes to prevent resource exhaustion (goroutines/memory) during a
SYN flood or connection flood attack.
1. **Global Limit:** A semaphore limits total concurrent handshakes to 20.
This applies backpressure to the `Accept` loop.
2. **Per-IP Limit:** Using `github.com/sethvargo/go-limiter`, we now
limit the rate of connection attempts per IP to 3 per second.
3. **Timeout:** The initial handshake timeout is reduced from 20s to 10s.
The global semaphore is acquired before the handshake and released
immediately after the handshake completes (or fails), ensuring that
long-lived sessions do not consume a handshake slot.
26 lines
665 B
AMPL
26 lines
665 B
AMPL
module github.com/shazow/ssh-chat
|
|
|
|
require (
|
|
github.com/alexcesaro/log v0.0.0-20150915221235-61e686294e58
|
|
github.com/jessevdk/go-flags v1.5.0
|
|
github.com/shazow/rateio v0.0.0-20200113175441-4461efc8bdc4
|
|
golang.org/x/crypto v0.17.0
|
|
golang.org/x/sync v0.1.0
|
|
golang.org/x/sys v0.15.0
|
|
golang.org/x/term v0.15.0
|
|
golang.org/x/text v0.14.0
|
|
)
|
|
|
|
require (
|
|
github.com/sethvargo/go-limiter v1.1.0 // indirect
|
|
github.com/yuin/goldmark v1.4.13 // indirect
|
|
golang.org/x/mod v0.8.0 // indirect
|
|
golang.org/x/net v0.10.0 // indirect
|
|
golang.org/x/tools v0.6.0 // indirect
|
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
|
|
)
|
|
|
|
go 1.22
|
|
|
|
toolchain go1.24.3
|