Skip to content

Commit 6a6bfb4

Browse files
refactoring the code changes
1 parent 7001edc commit 6a6bfb4

File tree

5 files changed

+55
-79
lines changed

5 files changed

+55
-79
lines changed

cmd/cariddi/main.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,31 @@ func main() {
6969
// Setup the config according to the flags that were
7070
// passed via the CLI
7171
config := &crawler.Scan{
72-
Delay: flags.Delay,
73-
Concurrency: flags.Concurrency,
74-
Ignore: flags.Ignore,
75-
IgnoreTxt: flags.IgnoreTXT,
76-
Cache: flags.Cache,
77-
JSON: flags.JSON,
78-
Timeout: flags.Timeout,
79-
Intensive: flags.Intensive,
80-
Rua: flags.Rua,
81-
Proxy: flags.Proxy,
82-
SecretsFlag: flags.Secrets,
83-
Plain: flags.Plain,
84-
EndpointsFlag: flags.Endpoints,
85-
FileType: flags.Extensions,
86-
ErrorsFlag: flags.Errors,
87-
InfoFlag: flags.Info,
88-
Debug: flags.Debug,
89-
UserAgent: flags.UserAgent,
90-
StoreResp: flags.StoreResp,
91-
StoredRespPath: flags.StoredRespDir,
72+
Delay: flags.Delay,
73+
Concurrency: flags.Concurrency,
74+
Ignore: flags.Ignore,
75+
IgnoreTxt: flags.IgnoreTXT,
76+
Cache: flags.Cache,
77+
JSON: flags.JSON,
78+
Timeout: flags.Timeout,
79+
Intensive: flags.Intensive,
80+
Rua: flags.Rua,
81+
Proxy: flags.Proxy,
82+
SecretsFlag: flags.Secrets,
83+
Plain: flags.Plain,
84+
EndpointsFlag: flags.Endpoints,
85+
FileType: flags.Extensions,
86+
ErrorsFlag: flags.Errors,
87+
InfoFlag: flags.Info,
88+
Debug: flags.Debug,
89+
UserAgent: flags.UserAgent,
90+
StoreResp: flags.StoreResp,
91+
}
92+
93+
config.OutputDir = output.CariddiOutputFolder
94+
if flags.StoredRespDir != "" {
95+
config.OutputDir = flags.StoredRespDir
96+
config.StoreResp = true
9297
}
9398

9499
// Read the targets from standard input.
@@ -119,18 +124,18 @@ func main() {
119124
// Create output files if needed (txt / html).
120125
config.Txt = ""
121126
if flags.TXTout != "" {
122-
config.Txt = fileUtils.CreateOutputFile(flags.TXTout, "results", "txt", config.StoredRespPath)
127+
config.Txt = fileUtils.CreateOutputFile(flags.TXTout, "results", "txt", config.OutputDir)
123128
}
124129

125130
var ResultHTML = ""
126131
if flags.HTMLout != "" {
127-
ResultHTML = fileUtils.CreateOutputFile(flags.HTMLout, "", "html", config.StoredRespPath)
132+
ResultHTML = fileUtils.CreateOutputFile(flags.HTMLout, "", "html", config.OutputDir)
128133
output.BannerHTML(ResultHTML)
129134
output.HeaderHTML("Results", ResultHTML)
130135
}
131136

132137
if config.StoreResp {
133-
fileUtils.CreateIndexOutputFile("index.responses.txt", config.StoredRespPath)
138+
fileUtils.CreateIndexOutputFile("index.responses.txt", config.OutputDir)
134139
}
135140

136141
// Read headers if needed
@@ -168,13 +173,13 @@ func main() {
168173
// IF TXT OUTPUT >
169174
if flags.TXTout != "" {
170175
output.TxtOutput(flags, finalResults, finalSecret, finalEndpoints,
171-
finalExtensions, finalErrors, finalInfos)
176+
finalExtensions, finalErrors, finalInfos, config.OutputDir)
172177
}
173178

174179
// IF HTML OUTPUT >
175180
if flags.HTMLout != "" {
176181
output.HTMLOutput(flags, ResultHTML, finalResults, finalSecret,
177-
finalEndpoints, finalExtensions, finalErrors, finalInfos)
182+
finalEndpoints, finalExtensions, finalErrors, finalInfos, config.OutputDir)
178183
}
179184

180185
// If needed print secrets.

internal/file/file.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ const (
4242
Permission0644 = 0644
4343
)
4444

45-
// constant defined in output.go as well, for circular dependency
46-
const (
47-
CariddiOutputFolder = "output-cariddi"
48-
)
49-
5045
// CreateOutputFolder creates the output folder
5146
// If it fails exits with an error message.
5247
func CreateOutputFolder(outputDir string) {
@@ -77,10 +72,6 @@ func CreateHostOutputFolder(host string, outputDir string) {
7772
// if no cariddi creates it.
7873
// Whenever an instruction fails, it exits with an error message.
7974
func CreateOutputFile(target string, subcommand string, format string, outputDir string) string {
80-
if outputDir == "" {
81-
outputDir = CariddiOutputFolder
82-
}
83-
8475
target = ReplaceBadCharacterOutput(target)
8576

8677
var filename string
@@ -129,10 +120,6 @@ func CreateOutputFile(target string, subcommand string, format string, outputDir
129120
// already exists, if no cariddi creates it.
130121
// Whenever an instruction fails, it exits with an error message.
131122
func CreateIndexOutputFile(filename string, outputDir string) {
132-
if outputDir == "" {
133-
outputDir = CariddiOutputFolder
134-
}
135-
136123
_, err := os.Stat(filename)
137124

138125
if os.IsNotExist(err) {

pkg/crawler/colly.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,9 @@ func New(scan *Scan) *Results {
136136

137137
var outputPath string
138138

139-
if scan.StoreResp || len(scan.StoredRespPath) > 0 {
140-
outputDir := scan.StoredRespPath
141-
142-
if outputDir == "" {
143-
outputDir = output.CariddiOutputFolder
144-
}
145-
139+
if scan.StoreResp {
146140
var err error
147-
outputPath, err = output.StoreHTTPResponse(r, outputDir)
141+
outputPath, err = output.StoreHTTPResponse(r, scan.OutputDir)
148142
if err != nil {
149143
log.Println(err)
150144
}

pkg/crawler/options.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ type Results struct {
3939

4040
type Scan struct {
4141
// Flags
42-
Cache bool
43-
Debug bool
44-
EndpointsFlag bool
45-
ErrorsFlag bool
46-
InfoFlag bool
47-
Intensive bool
48-
Plain bool
49-
Rua bool
50-
SecretsFlag bool
51-
Ignore string
52-
IgnoreTxt string
53-
JSON bool
54-
HTML string
55-
Proxy string
56-
Target string
57-
Txt string
58-
UserAgent string
59-
FileType int
60-
Headers map[string]string
61-
StoreResp bool
62-
StoredRespPath string
42+
Cache bool
43+
Debug bool
44+
EndpointsFlag bool
45+
ErrorsFlag bool
46+
InfoFlag bool
47+
Intensive bool
48+
Plain bool
49+
Rua bool
50+
SecretsFlag bool
51+
Ignore string
52+
IgnoreTxt string
53+
JSON bool
54+
HTML string
55+
Proxy string
56+
Target string
57+
Txt string
58+
UserAgent string
59+
FileType int
60+
Headers map[string]string
61+
StoreResp bool
62+
OutputDir string
6363

6464
// Settings
6565
Concurrency int

pkg/output/output.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ func PrintSimpleOutput(out []string) {
5252
// Actually it manages everything related to TXT output.
5353
func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.SecretMatched,
5454
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
55-
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched) {
56-
57-
outputDir := CariddiOutputFolder
58-
if flags.StoredRespDir != "" {
59-
outputDir = flags.StoredRespDir
60-
}
55+
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {
6156

6257
exists, err := fileUtils.ElementExists(outputDir)
6358
if err != nil {
@@ -130,12 +125,7 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S
130125
// Actually it manages everything related to HTML output.
131126
func HTMLOutput(flags input.Input, resultFilename string, finalResults []string, finalSecret []scanner.SecretMatched,
132127
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
133-
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched) {
134-
135-
outputDir := CariddiOutputFolder
136-
if flags.StoredRespDir != "" {
137-
outputDir = flags.StoredRespDir
138-
}
128+
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {
139129

140130
exists, err := fileUtils.ElementExists(outputDir)
141131

0 commit comments

Comments
 (0)