6 files changed
+1962
-2
No files matched your search
@@ -22,6 +22,7 @@ All configuration is done via environment variables:
|
||||
| `SSH_TARPIT_BANNER` | `SSH-2.0-OpenSSH_9.1p1 Debian-1` | Fake SSH banner |
|
||||
| `SSH_TARPIT_MAX_CONNS` | `100` | Maximum concurrent connections |
|
||||
| `SSH_TARPIT_SHUTDOWN_TIMEOUT` | `30s` | Max time to wait for active connections on shutdown |
|
||||
| `SSH_TARPIT_PROXY_PROTOCOL` | `false` | Enable PROXY protocol v1/v2 support (`true`, `1`, `yes`, `on`) |
|
||||
|
||||
## Deployment
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -11,4 +11,5 @@ services:
|
||||
environment:
|
||||
- SSH_TARPIT_PORT=2222
|
||||
- SSH_TARPIT_TARPIT=false
|
||||
# - SSH_TARPIT_PROXY_PROTOCOL=true
|
||||
# - SSH_TARPIT_GEOIP_PATH=/app/GeoIP
|
||||
@@ -15,6 +15,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/oschwald/maxminddb-golang v1.10.0 // indirect
|
||||
github.com/pires/go-proxyproto v0.15.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
|
||||
|
||||
@@ -18,6 +18,8 @@ github.com/oschwald/geoip2-golang v1.8.0 h1:KfjYB8ojCEn/QLqsDU0AzrJ3R5Qa9vFlx3z6
|
||||
github.com/oschwald/geoip2-golang v1.8.0/go.mod h1:R7bRvYjOeaoenAp9sKRS8GX5bJWcZ0laWO5+DauEktw=
|
||||
github.com/oschwald/maxminddb-golang v1.10.0 h1:Xp1u0ZhqkSuopaKmk1WwHtjF0H9Hd9181uj2MQ5Vndg=
|
||||
github.com/oschwald/maxminddb-golang v1.10.0/go.mod h1:Y2ELenReaLAZ0b400URyGwvYxHV1dLIxBuyOsyYjHK0=
|
||||
github.com/pires/go-proxyproto v0.15.0 h1:dTshmNbFm/D+0+sbrxUuddPOZ5Y0B7c5NhtsBkm6LqI=
|
||||
github.com/pires/go-proxyproto v0.15.0/go.mod h1:OXsCrKwrK2tXS9YrI5tkHx5xaQlO8FH3lFW76orFh24=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
|
||||
+16
-2
@@ -20,6 +20,7 @@ import (
|
||||
// Pure-Go SQLite driver
|
||||
_ "modernc.org/sqlite"
|
||||
"github.com/oschwald/geoip2-golang"
|
||||
"github.com/pires/go-proxyproto"
|
||||
)
|
||||
|
||||
// Config holds all configuration sourced from environment variables.
|
||||
@@ -38,6 +39,7 @@ type Config struct {
|
||||
Banner string
|
||||
MaxConns int
|
||||
ShutdownTimeout time.Duration
|
||||
ProxyProtocol bool
|
||||
}
|
||||
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
@@ -58,6 +60,7 @@ func loadConfig() Config {
|
||||
Banner: getEnv("SSH_TARPIT_BANNER", "SSH-2.0-OpenSSH_9.1p1 Debian-1"),
|
||||
MaxConns: getEnvInt("SSH_TARPIT_MAX_CONNS", 100),
|
||||
ShutdownTimeout: getEnvDuration("SSH_TARPIT_SHUTDOWN_TIMEOUT", 30*time.Second),
|
||||
ProxyProtocol: getEnvBool("SSH_TARPIT_PROXY_PROTOCOL", false),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,11 +263,22 @@ func main() {
|
||||
}
|
||||
|
||||
addr := fmt.Sprintf(":%d", cfg.Port)
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
rawLn, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to listen on %s: %v", addr, err)
|
||||
}
|
||||
log.Printf("Listening on %s", addr)
|
||||
|
||||
var ln net.Listener
|
||||
if cfg.ProxyProtocol {
|
||||
ln = &proxyproto.Listener{
|
||||
Listener: rawLn,
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
}
|
||||
log.Printf("Listening on %s (PROXY protocol enabled)", addr)
|
||||
} else {
|
||||
ln = rawLn
|
||||
log.Printf("Listening on %s", addr)
|
||||
}
|
||||
|
||||
// Signal handling for graceful shutdown
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
Reference in new issue
Block a user