-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgobuster.go
More file actions
75 lines (58 loc) · 1.53 KB
/
gobuster.go
File metadata and controls
75 lines (58 loc) · 1.53 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
package gocdp
import (
"bufio"
"bytes"
"fmt"
"regexp"
"strconv"
"strings"
)
var (
gbResultRegex *regexp.Regexp = regexp.MustCompile(`\s*(?P<url>https?://[^\s]+)\s*\(Status:\s*(?P<status>[0-9]+)\)\s*\[Size:\s*(?P<length>[0-9]+)\](?:\s*\[-->\s*(?P<redirect>[^\s]+)\s*])?`)
)
type GobusterParser struct {
}
func (GobusterParser) Parse(input string) (CDResults, error) {
var results CDResults
scanner := bufio.NewScanner(strings.NewReader(input))
for scanner.Scan() {
line := scanner.Text()
match := gbResultRegex.FindStringSubmatch(line)
if len(match) == 0 {
continue
}
namedMatches := make(map[string]string)
for j, name := range gbResultRegex.SubexpNames() {
if j != 0 && name != "" {
namedMatches[name] = match[j]
}
}
status, _ := strconv.Atoi(namedMatches["status"])
length, _ := strconv.Atoi(namedMatches["length"])
result := CDResult{
Url: namedMatches["url"],
Status: status,
ContentLength: length,
ContentType: "",
source: line,
}
if result.IsRedirect() {
result.Redirect = namedMatches["redirect"]
}
results = append(results, result)
}
return results, nil
}
func (GobusterParser) CanParse(input string) bool {
return gbResultRegex.MatchString(input)
}
func (GobusterParser) CanTransform() bool {
return true
}
func (p GobusterParser) Transform(input string, filtered []interface{}) (string, error) {
writer := bytes.NewBuffer(nil)
for _, line := range filtered {
writer.WriteString(fmt.Sprintln(line))
}
return writer.String(), nil
}