segfault-relay/main.go
2023-07-09 22:07:52 -06:00

59 lines
1.2 KiB
Go

package main
import (
"io"
"log"
"net"
"strings"
)
func main() {
listener, err := net.Listen("tcp", ":1337")
if err != nil {
log.Fatal(err)
}
log.Println("SSH SEGFAULT started on port 1337")
for {
conn, err := listener.Accept()
if err != nil {
log.Println("Failed to accept connection:", err)
continue
}
go handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
defer conn.Close()
// Forward the connection to the target server
targetHost := "segfault.net"
targetPort := "22"
targetConn, err := net.Dial("tcp", targetHost+":"+targetPort)
if err != nil {
log.Println("Failed to connect to target server:", err)
return
}
defer targetConn.Close()
// Copy data from client to target server
go func() {
_, err := io.Copy(targetConn, conn)
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
log.Println("Failed to copy client to target:", err)
}
}()
// Copy data from target server to client
_, err = io.Copy(conn, targetConn)
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
log.Println("Failed to copy target to client:", err)
}
log.Println("Connection closed")
}