MCPcopy Create free account
hub / github.com/Xenov-X/csbot / executePortScan

Method executePortScan

workflow/executor_network.go:153–232  ·  view source on GitHub ↗

executePortScan runs a portscan against the specified hosts

(ctx context.Context, client *csclient.Client, beaconID string, action Action)

Source from the content-addressed store, hash-verified

151
152// executePortScan runs a portscan against the specified hosts
153func (e *Executor) executePortScan(ctx context.Context, client *csclient.Client, beaconID string, action Action) (string, error) {
154 // Extract required parameters
155 targetsRaw, ok := action.Parameters["targets"]
156 if !ok {
157 return "", fmt.Errorf("portscan requires 'targets' parameter")
158 }
159
160 portsRaw, ok := action.Parameters["ports"]
161 if !ok {
162 return "", fmt.Errorf("portscan requires 'ports' parameter")
163 }
164
165 // Convert targets to []string
166 var targets []string
167 switch v := targetsRaw.(type) {
168 case []interface{}:
169 for _, t := range v {
170 if str, ok := t.(string); ok {
171 targets = append(targets, str)
172 }
173 }
174 case []string:
175 targets = v
176 case string:
177 targets = []string{v}
178 default:
179 return "", fmt.Errorf("targets must be a string or array of strings")
180 }
181
182 if len(targets) == 0 {
183 return "", fmt.Errorf("targets must contain at least one host")
184 }
185
186 // Convert ports to []string
187 var ports []string
188 switch v := portsRaw.(type) {
189 case []interface{}:
190 for _, p := range v {
191 if str, ok := p.(string); ok {
192 ports = append(ports, str)
193 } else if num, ok := p.(int); ok {
194 ports = append(ports, fmt.Sprintf("%d", num))
195 } else if num, ok := p.(float64); ok {
196 ports = append(ports, fmt.Sprintf("%.0f", num))
197 }
198 }
199 case []string:
200 ports = v
201 case string:
202 ports = []string{v}
203 case int:
204 ports = []string{fmt.Sprintf("%d", v)}
205 case float64:
206 ports = []string{fmt.Sprintf("%.0f", v)}
207 default:
208 return "", fmt.Errorf("ports must be a string, number, or array")
209 }
210

Callers 1

executeActionMethod · 0.95

Calls 1

waitForOutputMethod · 0.95

Tested by

no test coverage detected