generated from metarsit/golang-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
honeypot.go
47 lines (40 loc) · 1.02 KB
/
honeypot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package sshtest
import (
"io"
"github.com/gliderlabs/ssh"
)
// HoneyPot encapsulates the initialized struct
type HoneyPot struct {
server *ssh.Server
}
// NewHoneyPot takes in IP address to be used for honeypot
func NewHoneyPot(addr string) *HoneyPot {
return &HoneyPot{
server: &ssh.Server{
Addr: addr,
Handler: func(s ssh.Session) {
io.WriteString(s, "Honey pot")
},
PasswordHandler: func(ctx ssh.Context, password string) bool {
return true
},
},
}
}
// ListenAndServe listens on the TCP network address srv.Addr
// and then calls Serve to handle incoming connections
func (h *HoneyPot) ListenAndServe() error {
return h.server.ListenAndServe()
}
// Close returns any error returned from closing
// the Server's underlying Listener(s).
func (h *HoneyPot) Close() error {
return h.server.Close()
}
// SetReturnString takes in a string and set it as
// the response from the server
func (h *HoneyPot) SetReturnString(str string) {
h.server.Handler = func(s ssh.Session) {
io.WriteString(s, str)
}
}