-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtypes.go
More file actions
163 lines (135 loc) · 3.32 KB
/
types.go
File metadata and controls
163 lines (135 loc) · 3.32 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package zombie
import (
"context"
"fmt"
"github.com/chainreactors/sdk/pkg/types"
)
type Context struct {
ctx context.Context
opt *types.ZombieOption
statsHandler func(types.Stats)
proxy []string // per-execution 代理覆盖(优先级高于 Config / Client)
}
var _ types.Context = (*Context)(nil)
func NewContext() *Context {
return &Context{
ctx: context.Background(),
opt: types.NewDefaultZombieOption(),
}
}
func (c *Context) WithContext(ctx context.Context) *Context {
return &Context{
ctx: ctx,
opt: types.CloneZombieOption(c.opt),
statsHandler: c.statsHandler,
proxy: c.proxy,
}
}
// SetProxy 设置本次执行使用的代理(支持多级代理链)。仅对支持代理的插件生效
// (ssh/smb/vnc/ftp/rsync/redis 等原生 TCP 或可注入拨号器的插件)。
// 传入空参数表示清除 Context 级代理,回退到 Config / Client 级配置。
func (c *Context) SetProxy(proxies ...string) *Context {
c.proxy = proxies
return c
}
func (c *Context) Context() context.Context {
return c.ctx
}
func (c *Context) SetOption(opt *types.ZombieOption) *Context {
c.opt = types.CloneZombieOption(opt)
return c
}
func (c *Context) SetThreads(threads int) *Context {
if threads > 0 {
c.opt.Threads = threads
}
return c
}
func (c *Context) SetTimeout(timeout int) *Context {
if timeout > 0 {
c.opt.Timeout = timeout
}
return c
}
func (c *Context) SetTop(top int) *Context {
if top >= 0 {
c.opt.Top = top
}
return c
}
func (c *Context) SetFirstOnly(firstOnly bool) *Context {
c.opt.FirstOnly = firstOnly
return c
}
func (c *Context) SetNoUnauth(noUnauth bool) *Context {
c.opt.NoUnAuth = noUnauth
return c
}
func (c *Context) SetStatsHandler(handler func(types.Stats)) *Context {
c.statsHandler = handler
return c
}
func (c *Context) emitStats(stats types.Stats) {
if c != nil && c.statsHandler != nil {
c.statsHandler(stats)
}
}
type Config struct {
Capacity int
ResourceProvider func(string) []byte
Proxy []string // 引擎级默认代理,作用于该引擎所有执行(可被 Context 覆盖)
}
func NewConfig() *Config {
return &Config{}
}
func (c *Config) Validate() error {
return nil
}
func (c *Config) WithCapacity(total int) *Config {
c.Capacity = total
return c
}
func (c *Config) WithResourceProvider(provider func(string) []byte) *Config {
c.ResourceProvider = provider
return c
}
// WithProxy 设置引擎级默认代理(支持多级代理链)。可被 Context.SetProxy 覆盖。
func (c *Config) WithProxy(proxies ...string) *Config {
c.Proxy = proxies
return c
}
type Target = types.ZombieTarget
type Auth struct {
Username string
Password string
}
type BruteTask struct {
Targets []Target
Users []string
Passwords []string
Auths []Auth
mod string
}
func NewBruteTask(targets []Target) *BruteTask {
return &BruteTask{Targets: targets}
}
func (t *BruteTask) Type() string {
if t.mod != "" {
return t.mod
}
return "brute"
}
func (t *BruteTask) Validate() error {
if len(t.Targets) == 0 {
return fmt.Errorf("targets cannot be empty")
}
for i, target := range t.Targets {
if target.IP == "" {
return fmt.Errorf("targets[%d].IP cannot be empty", i)
}
if target.Service == "" {
return fmt.Errorf("targets[%d].Service cannot be empty", i)
}
}
return nil
}