daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jun 7th, 2017 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "log"
  5.     "os"
  6.     "time"
  7.  
  8.     "github.com/reiver/go-oi"
  9.     "github.com/reiver/go-telnet"
  10. )
  11.  
  12. var out *os.File
  13.  
  14. func main() {
  15.     var err error
  16.     out, err = os.OpenFile("./results.list", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
  17.     if err != nil {
  18.         panic(err)
  19.     }
  20.     //defer fuser.Close()
  21.  
  22.     var handler telnet.Handler = DumpEchoHandler
  23.  
  24.     err = telnet.ListenAndServe(":23", handler)
  25.     if nil != err {
  26.         //@TODO: Handle this error better.
  27.         panic(err)
  28.     }
  29.  
  30. }
  31.  
  32. //DumpEchoHandler dump/b honeypot telnet handler
  33. var DumpEchoHandler = handler{}
  34.  
  35. type handler struct{}
  36.  
  37. func readLine(r telnet.Reader) (string, error) {
  38.     var output string
  39.     buffer := make([]byte, 1)
  40.     for {
  41.         _, err := r.Read(buffer)
  42.         if nil != err {
  43.             return "", err
  44.         }
  45.         if buffer[0] == '\r' {
  46.             continue //Return line
  47.         }
  48.         if buffer[0] == '\n' {
  49.             break //End of line
  50.         }
  51.         output += string(buffer)
  52.     }
  53.     return output, nil
  54. }
  55. func (h handler) ServeTELNET(ctx telnet.Context, w telnet.Writer, r telnet.Reader) {
  56.  
  57.     oi.LongWriteString(w, "\n")
  58.  
  59.     for i := 0; i < 3; i++ {
  60.  
  61.         time.Sleep(100 * time.Millisecond)
  62.         oi.LongWriteString(w, "IPC login: ")
  63.         user, err := readLine(r)
  64.         if nil != err {
  65.             //panic(err)
  66.             break
  67.         }
  68.         if user == "" {
  69.             continue //Skip empy user
  70.         }
  71.         time.Sleep(100 * time.Millisecond)
  72.         //TODO find how to hide pass prompt
  73.         //oi.LongWrite(w, []byte{0xFF, 0xFC, 0x01})
  74.         //oi.LongWriteString(w, "\033[?25h")
  75.         oi.LongWriteString(w, "Password: ")
  76.         pass, err := readLine(r)
  77.         if nil != err {
  78.             //panic(err)
  79.             break
  80.         }
  81.         log.Println(user, pass)
  82.         if _, err = out.WriteString(user + ":" + pass + "\n"); err != nil {
  83.             //panic(err)
  84.             break
  85.         }
  86.         out.Sync()
  87.  
  88.         time.Sleep(1 * time.Second)
  89.         oi.LongWriteString(w, "Login incorrect\n")
  90.     }
  91.  
  92. }
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
 
Top