SHARE
TWEET

Untitled

a guest Dec 15th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "github.com/gliderlabs/ssh"
  6. "golang.org/x/crypto/ssh/terminal"
  7. "io"
  8. "log"
  9. "os/exec"
  10. )
  11.  
  12. func main() {
  13.     server:="localhost:2222"
  14.     ssh.Handle(func(s ssh.Session) {
  15.  
  16.         io.WriteString(s, fmt.Sprintf("Hello %s\n", s.User()))
  17.         term := terminal.NewTerminal(s, "> ")
  18.         for {
  19.             line, err := term.ReadLine()
  20.             if err != nil {
  21.                 break
  22.             }
  23.             if line =="dir"{
  24.                 out, err := exec.Command("cmd", "/C", "dir").Output()
  25.                 if err != nil {
  26.                     log.Fatal(err)
  27.                 }
  28.                 term.Write(append([]byte(out), '\n'))
  29.             } else if line =="date" {
  30.                 out, err := exec.Command("cmd", "date").Output()
  31.                 if err != nil {
  32.                     log.Fatal(err)
  33.                 }
  34.                 term.Write(append([]byte(out), '\n'))
  35.             } else if line =="server"{
  36.                 term.Write(append([]byte(server), '\n'))
  37.             } else {
  38.                 term.Write(append([]byte("unknown command"), '\n'))
  39.             }
  40.             log.Println(line)
  41.         }
  42.  
  43.     })
  44.  
  45.     log.Println("terminal closed")
  46.  
  47.     log.Println("starting ssh server on port 2222...")
  48.     log.Fatal(ssh.ListenAndServe(":2222", nil))
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top