From 5a4a29e72c731bd4f9992b8aa72a7ca8a50b44f3 Mon Sep 17 00:00:00 2001 From: Bhasher Date: Tue, 26 Dec 2023 18:36:18 +0100 Subject: [PATCH] Log non-login connections --- main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index f38b16c..46862bd 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,9 @@ import ( ) func main() { - path := os.Getenv("PATH") + path := os.Getenv("LOGPATH") if path == "" { - path = "/var/log/ssh-honeypot.log" + path = "./data/ssh-honeypot.log" } logFile, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) @@ -44,7 +44,7 @@ func main() { if err != nil { ip = c.RemoteAddr().String() } - _, err = fmt.Fprintf(w, "[%s] \"honeypot connection attempt: ssh - %s - %s - %s\"\n", time.Now().Format("2006-01-02 15:04:05.000"), ip, c.User(), string(pass)) + _, err = fmt.Fprintf(w, "[%s] \"honeypot login attempt: ssh - %s - %s - %s\"\n", time.Now().Format("2006-01-02 15:04:05.000"), ip, c.User(), string(pass)) if err != nil { fmt.Printf("Error writing to log file: %v", err) @@ -62,7 +62,7 @@ func main() { if err != nil { panic(err) } - fmt.Printf("Listening on port %s...", port) + fmt.Printf("Listening on port %s...\n", port) for { conn, err := listener.Accept() @@ -71,6 +71,15 @@ func main() { continue } + ip, _, err := net.SplitHostPort(conn.RemoteAddr().String()) + if err != nil { + ip = conn.RemoteAddr().String() + } + + fmt.Fprintf(w, "[%s] \"honeypot connection: ssh - %s\"\n", time.Now().Format("2006-01-02 15:04:05.000"), ip) + + w.Flush() + go handleConn(conn, config) } }