-
Notifications
You must be signed in to change notification settings - Fork 1
/
session.go
59 lines (45 loc) · 933 Bytes
/
session.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
48
49
50
51
52
53
54
55
56
57
58
59
package gomsf
import (
"fmt"
"strings"
"github.com/hupe1980/gomsf/rpc"
)
type session struct {
id int
rpc *rpc.RPC
}
func (s *session) Stop() {
// TODO
}
func (s *session) Modules() ([]string, error) {
r, err := s.rpc.Session.CompatibleModules(s.id)
if err != nil {
return nil, err
}
return r.Modules, nil
}
type MeterpreterSession struct {
session
}
func (ms *MeterpreterSession) Read() (string, error) {
r, err := ms.rpc.Session.MeterpreterRead(ms.id)
if err != nil {
return "", err
}
return r.Data, nil
}
func (ms *MeterpreterSession) Write(command string) error {
if !strings.HasSuffix(command, "\n") {
command = fmt.Sprintf("%s\n", command)
}
r, err := ms.rpc.Session.MeterpreterWrite(ms.id, command)
if err != nil {
return err
}
if r.Result == rpc.FAILURE {
return fmt.Errorf("cannot write command %s to session %d", command, ms.id)
}
return nil
}
type SessionManager struct {
}