MCPcopy Create free account
hub / github.com/chainreactors/spray / Validate

Method Validate

core/option.go:323–397  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

321}
322
323func (opt *Option) Validate() error {
324 if opt.Uppercase && opt.Lowercase {
325 return errors.New("cannot set -U and -L at the same time")
326 }
327
328 if (opt.Offset != 0 || opt.Limit != 0) && opt.Depth > 0 {
329 // 偏移和上限与递归同时使用时也会造成混淆.
330 return errors.New("--offset and --limit cannot be used with --depth at the same time")
331 }
332
333 if opt.Depth > 0 && opt.ResumeFrom != "" {
334 // 递归与断点续传会造成混淆, 断点续传的word与rule不是通过命令行获取的
335 return errors.New("--resume and --depth cannot be used at the same time")
336 }
337
338 if opt.ResumeFrom == "" && len(opt.URL) == 0 && opt.URLFile == "" && len(opt.CIDRs) == 0 && opt.RawFile == "" {
339 return fmt.Errorf("without any target, please use -u/-l/-c/--resume to set targets")
340 }
341
342 // FunctionOptions 只在 Brute 模式下生效
343 // Check 模式(无字典、无 word、无 rule)下使用 FunctionOptions 会报错
344 hasMask := func() bool {
345 for _, u := range opt.URL {
346 if containsMask(u) {
347 return true
348 }
349 }
350 for _, h := range opt.Headers {
351 if containsMask(h) {
352 return true
353 }
354 }
355 for _, c := range opt.Cookie {
356 if containsMask(c) {
357 return true
358 }
359 }
360 return containsMask(opt.Host) || containsMask(opt.Path)
361 }
362 isCheckMode := len(opt.Dictionaries) == 0 && opt.Word == "" && !hasMask() && len(opt.Rules) == 0 && len(opt.AppendRule) == 0 && !opt.DefaultDict
363 if isCheckMode {
364 if opt.Extensions != "" {
365 return errors.New("FunctionOptions: -e/--extension only works in Brute mode, not in Check mode. Please provide dictionary (-d) to enable Brute mode")
366 }
367 if opt.ForceExtension {
368 return errors.New("FunctionOptions: --force-extension only works in Brute mode, not in Check mode. Please provide dictionary (-d) to enable Brute mode")
369 }
370 if opt.ExcludeExtensions != "" {
371 return errors.New("FunctionOptions: --exclude-extension only works in Brute mode, not in Check mode. Please provide dictionary (-d) to enable Brute mode")
372 }
373 if opt.RemoveExtensions != "" {
374 return errors.New("FunctionOptions: --remove-extension only works in Brute mode, not in Check mode. Please provide dictionary (-d) to enable Brute mode")
375 }
376 if opt.Uppercase {
377 return errors.New("FunctionOptions: -U/--uppercase only works in Brute mode, not in Check mode. Please provide dictionary (-d) to enable Brute mode")
378 }
379 if opt.Lowercase {
380 return errors.New("FunctionOptions: -L/--lowercase only works in Brute mode, not in Check mode. Please provide dictionary (-d) to enable Brute mode")

Callers 1

PrepareMethod · 0.95

Calls 1

containsMaskFunction · 0.85

Tested by

no test coverage detected