forked from R3dFruitRollUp/rescope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
104 lines (87 loc) · 2.59 KB
/
main.go
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
//
// Written By : Daniel Antonsen (@root4loot)
//
// Distributed Under MIT License
// Copyrights (C) 2019 root4loot
//
package main
import (
"fmt"
"log"
"os"
"github.com/fatih/color"
burp "github.com/root4loot/rescope/burp"
cli "github.com/root4loot/rescope/cli"
io "github.com/root4loot/rescope/io"
scope "github.com/root4loot/rescope/scope"
zap "github.com/root4loot/rescope/zap"
)
func main() {
// data to be written to outfile
var buf []byte
// struct containing various args
c := cli.Parse()
// fancy colors
grey := color.New(color.Faint).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
// determine if infiles exists
for _, f := range c.Infiles {
if io.IsFileExist(f) != true {
fmt.Printf("\n%s Couldn't find file %s. Does it exist?", red("[!]"), f)
}
}
// file descriptors
var fds []*os.File
// attempt to open infiles
for _, f := range c.Infiles {
fd, err := io.OpenFile(f)
// remember to close file
defer fd.Close()
// add to fds
fds = append(fds, fd)
if err, ok := err.(*os.PathError); ok {
fmt.Printf("\n%s Failed to read file at location %s. Bad permissions?", red("[!]"), f)
log.Fatal(err)
}
}
// file data
var scopes []string
// attempt to read infiles contents
for _, fd := range fds {
data, err := io.ReadFile(fd)
if err != nil {
fmt.Printf("\n%s Failed to read contents of file %s", red("[!]"), fd.Name())
log.Fatal(err)
}
// append to scopes
scopes = append(scopes, string(data[:]))
}
// apply regex matching to scopes
m := scope.Match{}
m = scope.Parse(m, scopes, c.Command, c.Infiles, c.Silent, c.ExTag)
// parse to burp/zap
if cli.IsCommand(c, "burp") {
fmt.Printf("%s Parsing to JSON (Burp Suite)", grey("[-]"))
buf = burp.Parse(m.L1, m.L2, m.L3, m.Excludes)
fmt.Printf("\n%s Done", green("[✓]"))
} else if cli.IsCommand(c, "zap") {
fmt.Printf("%s Parsing to XML (OWASP ZAP)", grey("[-]"))
buf = zap.Parse(m.L1, m.L2, m.L3, m.Excludes, c.Scopename)
fmt.Printf("\n%s Done", green("[✓]"))
}
// attempt to create outfile
outfile, err := io.CreateFile(c.Outfile)
if err != nil {
fmt.Printf("\n%s Failed to create file at location %s. Bad permisisons?", red("[!]"), outfile.Name())
log.Fatal(err)
}
// write to outfile assuming we have permissions as
// file was created
meta, err := io.WriteFile(outfile, buf)
if cli.IsCommand(c, "burp") {
fmt.Printf("\n%s Wrote %v bytes to %s\n\n", green("[✓]"), meta, outfile.Name())
} else if cli.IsCommand(c, "zap") {
fmt.Printf("\n%s Wrote %v bytes to %s\n\n", green("[✓]"), meta, outfile.Name())
}
}