-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules_test.go
More file actions
167 lines (132 loc) · 3.85 KB
/
modules_test.go
File metadata and controls
167 lines (132 loc) · 3.85 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
164
165
166
167
package gomsf
import (
"context"
"testing"
)
func TestModuleManager_Exploits(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
exploits, err := client.Modules().Exploits(context.Background())
if err != nil {
t.Fatalf("Exploits failed: %v", err)
}
if len(exploits) == 0 {
t.Error("Expected at least one exploit")
}
}
func TestModuleManager_Payloads(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
payloads, err := client.Modules().Payloads(context.Background())
if err != nil {
t.Fatalf("Payloads failed: %v", err)
}
if len(payloads) == 0 {
t.Error("Expected at least one payload")
}
}
func TestModuleManager_Auxiliary(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
aux, err := client.Modules().Auxiliary(context.Background())
if err != nil {
t.Fatalf("Auxiliary failed: %v", err)
}
if len(aux) == 0 {
t.Error("Expected at least one auxiliary module")
}
}
func TestModuleManager_Post(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
post, err := client.Modules().Post(context.Background())
if err != nil {
t.Fatalf("Post failed: %v", err)
}
if len(post) == 0 {
t.Error("Expected at least one post module")
}
}
func TestModuleManager_Encoders(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
encoders, err := client.Modules().Encoders(context.Background())
if err != nil {
t.Fatalf("Encoders failed: %v", err)
}
if len(encoders) == 0 {
t.Error("Expected at least one encoder")
}
}
func TestModuleManager_Nops(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
nops, err := client.Modules().Nops(context.Background())
if err != nil {
t.Fatalf("Nops failed: %v", err)
}
if len(nops) == 0 {
t.Error("Expected at least one nop module")
}
}
func TestModuleManager_Use(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
mod, err := client.Modules().Use(context.Background(), ExploitModuleType, "windows/smb/ms08_067_netapi")
if err != nil {
t.Fatalf("Use failed: %v", err)
}
if mod.Name != "windows/smb/ms08_067_netapi" {
t.Errorf("Expected module name to be windows/smb/ms08_067_netapi, got %s", mod.Name)
}
if mod.ModuleType != ExploitModuleType {
t.Errorf("Expected module type to be exploit, got %s", mod.ModuleType)
}
}
func TestModule_Options(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
mod, err := client.Modules().Use(context.Background(), ExploitModuleType, "windows/smb/ms08_067_netapi")
if err != nil {
t.Fatalf("Use failed: %v", err)
}
options := mod.Options()
if len(options) == 0 {
t.Error("Expected at least one option")
}
required := mod.RequiredOptions()
if len(required) == 0 {
t.Log("Module has no required options (this may be OK)")
}
}
func TestModule_SetOption(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
mod, err := client.Modules().Use(context.Background(), ExploitModuleType, "windows/smb/ms08_067_netapi")
if err != nil {
t.Fatalf("Use failed: %v", err)
}
err = mod.SetOption("RHOSTS", "192.168.1.1")
if err != nil {
t.Errorf("SetOption failed: %v", err)
}
val, err := mod.GetOption("RHOSTS")
if err != nil {
t.Errorf("GetOption failed: %v", err)
}
if val != "192.168.1.1" {
t.Errorf("Expected RHOSTS to be 192.168.1.1, got %v", val)
}
}
func TestModule_SetOption_Invalid(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
mod, err := client.Modules().Use(context.Background(), ExploitModuleType, "windows/smb/ms08_067_netapi")
if err != nil {
t.Fatalf("Use failed: %v", err)
}
err = mod.SetOption("INVALID_OPTION", "value")
if err == nil {
t.Error("Expected error for invalid option")
}
}