AddCustomExtractor creates a one-off regex extractor at runtime (for --extract ).
(name, pattern string)
| 99 | |
| 100 | // AddCustomExtractor creates a one-off regex extractor at runtime (for --extract <regex>). |
| 101 | func AddCustomExtractor(name, pattern string) { |
| 102 | protonMu.Lock() |
| 103 | defer protonMu.Unlock() |
| 104 | |
| 105 | req := &file.Request{ |
| 106 | Extensions: []string{"all"}, |
| 107 | } |
| 108 | req.Operators.Extractors = append(req.Operators.Extractors, &operators.Extractor{ |
| 109 | Name: name, |
| 110 | Type: "regex", |
| 111 | Regex: []string{pattern}, |
| 112 | }) |
| 113 | opts := &protocols.ExecuterOptions{Options: &protocols.Options{}} |
| 114 | if err := req.Compile(opts); err != nil { |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | tmpl := &protonTmpl.Template{ |
| 119 | Id: "custom-" + name, |
| 120 | RequestsFile: []*file.Request{req}, |
| 121 | } |
| 122 | tmpl.Info.Name = name |
| 123 | tmpl.Info.Severity = "info" |
| 124 | tmpl.Info.Tags = "spray, custom" |
| 125 | |
| 126 | protonTemplates = append(protonTemplates, tmpl) |
| 127 | protonTemplateMap[tmpl.Id] = tmpl |
| 128 | rebuildScanner() |
| 129 | } |
| 130 | |
| 131 | // EnableExtractors activates a subset of templates by name or tag. |
| 132 | // Called after LoadProtonTemplates to filter what runs during scanning. |