Skip to content

Commit

Permalink
refactoring the code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeysemwal committed Aug 17, 2024
1 parent 7001edc commit 6a6bfb4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 79 deletions.
55 changes: 30 additions & 25 deletions cmd/cariddi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,31 @@ func main() {
// Setup the config according to the flags that were
// passed via the CLI
config := &crawler.Scan{
Delay: flags.Delay,
Concurrency: flags.Concurrency,
Ignore: flags.Ignore,
IgnoreTxt: flags.IgnoreTXT,
Cache: flags.Cache,
JSON: flags.JSON,
Timeout: flags.Timeout,
Intensive: flags.Intensive,
Rua: flags.Rua,
Proxy: flags.Proxy,
SecretsFlag: flags.Secrets,
Plain: flags.Plain,
EndpointsFlag: flags.Endpoints,
FileType: flags.Extensions,
ErrorsFlag: flags.Errors,
InfoFlag: flags.Info,
Debug: flags.Debug,
UserAgent: flags.UserAgent,
StoreResp: flags.StoreResp,
StoredRespPath: flags.StoredRespDir,
Delay: flags.Delay,
Concurrency: flags.Concurrency,
Ignore: flags.Ignore,
IgnoreTxt: flags.IgnoreTXT,
Cache: flags.Cache,
JSON: flags.JSON,
Timeout: flags.Timeout,
Intensive: flags.Intensive,
Rua: flags.Rua,
Proxy: flags.Proxy,
SecretsFlag: flags.Secrets,
Plain: flags.Plain,
EndpointsFlag: flags.Endpoints,
FileType: flags.Extensions,
ErrorsFlag: flags.Errors,
InfoFlag: flags.Info,
Debug: flags.Debug,
UserAgent: flags.UserAgent,
StoreResp: flags.StoreResp,
}

config.OutputDir = output.CariddiOutputFolder
if flags.StoredRespDir != "" {
config.OutputDir = flags.StoredRespDir
config.StoreResp = true
}

// Read the targets from standard input.
Expand Down Expand Up @@ -119,18 +124,18 @@ func main() {
// Create output files if needed (txt / html).
config.Txt = ""
if flags.TXTout != "" {
config.Txt = fileUtils.CreateOutputFile(flags.TXTout, "results", "txt", config.StoredRespPath)
config.Txt = fileUtils.CreateOutputFile(flags.TXTout, "results", "txt", config.OutputDir)
}

var ResultHTML = ""
if flags.HTMLout != "" {
ResultHTML = fileUtils.CreateOutputFile(flags.HTMLout, "", "html", config.StoredRespPath)
ResultHTML = fileUtils.CreateOutputFile(flags.HTMLout, "", "html", config.OutputDir)
output.BannerHTML(ResultHTML)
output.HeaderHTML("Results", ResultHTML)
}

if config.StoreResp {
fileUtils.CreateIndexOutputFile("index.responses.txt", config.StoredRespPath)
fileUtils.CreateIndexOutputFile("index.responses.txt", config.OutputDir)
}

// Read headers if needed
Expand Down Expand Up @@ -168,13 +173,13 @@ func main() {
// IF TXT OUTPUT >
if flags.TXTout != "" {
output.TxtOutput(flags, finalResults, finalSecret, finalEndpoints,
finalExtensions, finalErrors, finalInfos)
finalExtensions, finalErrors, finalInfos, config.OutputDir)
}

// IF HTML OUTPUT >
if flags.HTMLout != "" {
output.HTMLOutput(flags, ResultHTML, finalResults, finalSecret,
finalEndpoints, finalExtensions, finalErrors, finalInfos)
finalEndpoints, finalExtensions, finalErrors, finalInfos, config.OutputDir)
}

// If needed print secrets.
Expand Down
13 changes: 0 additions & 13 deletions internal/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ const (
Permission0644 = 0644
)

// constant defined in output.go as well, for circular dependency
const (
CariddiOutputFolder = "output-cariddi"
)

// CreateOutputFolder creates the output folder
// If it fails exits with an error message.
func CreateOutputFolder(outputDir string) {
Expand Down Expand Up @@ -77,10 +72,6 @@ func CreateHostOutputFolder(host string, outputDir string) {
// if no cariddi creates it.
// Whenever an instruction fails, it exits with an error message.
func CreateOutputFile(target string, subcommand string, format string, outputDir string) string {
if outputDir == "" {
outputDir = CariddiOutputFolder
}

target = ReplaceBadCharacterOutput(target)

var filename string
Expand Down Expand Up @@ -129,10 +120,6 @@ func CreateOutputFile(target string, subcommand string, format string, outputDir
// already exists, if no cariddi creates it.
// Whenever an instruction fails, it exits with an error message.
func CreateIndexOutputFile(filename string, outputDir string) {
if outputDir == "" {
outputDir = CariddiOutputFolder
}

_, err := os.Stat(filename)

if os.IsNotExist(err) {
Expand Down
10 changes: 2 additions & 8 deletions pkg/crawler/colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,9 @@ func New(scan *Scan) *Results {

var outputPath string

if scan.StoreResp || len(scan.StoredRespPath) > 0 {
outputDir := scan.StoredRespPath

if outputDir == "" {
outputDir = output.CariddiOutputFolder
}

if scan.StoreResp {
var err error
outputPath, err = output.StoreHTTPResponse(r, outputDir)
outputPath, err = output.StoreHTTPResponse(r, scan.OutputDir)
if err != nil {
log.Println(err)
}
Expand Down
42 changes: 21 additions & 21 deletions pkg/crawler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ type Results struct {

type Scan struct {
// Flags
Cache bool
Debug bool
EndpointsFlag bool
ErrorsFlag bool
InfoFlag bool
Intensive bool
Plain bool
Rua bool
SecretsFlag bool
Ignore string
IgnoreTxt string
JSON bool
HTML string
Proxy string
Target string
Txt string
UserAgent string
FileType int
Headers map[string]string
StoreResp bool
StoredRespPath string
Cache bool
Debug bool
EndpointsFlag bool
ErrorsFlag bool
InfoFlag bool
Intensive bool
Plain bool
Rua bool
SecretsFlag bool
Ignore string
IgnoreTxt string
JSON bool
HTML string
Proxy string
Target string
Txt string
UserAgent string
FileType int
Headers map[string]string
StoreResp bool
OutputDir string

// Settings
Concurrency int
Expand Down
14 changes: 2 additions & 12 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ func PrintSimpleOutput(out []string) {
// Actually it manages everything related to TXT output.
func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.SecretMatched,
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched) {

outputDir := CariddiOutputFolder
if flags.StoredRespDir != "" {
outputDir = flags.StoredRespDir
}
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {

Check failure on line 55 in pkg/output/output.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

exists, err := fileUtils.ElementExists(outputDir)
if err != nil {
Expand Down Expand Up @@ -130,12 +125,7 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S
// Actually it manages everything related to HTML output.
func HTMLOutput(flags input.Input, resultFilename string, finalResults []string, finalSecret []scanner.SecretMatched,
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched) {

outputDir := CariddiOutputFolder
if flags.StoredRespDir != "" {
outputDir = flags.StoredRespDir
}
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {

Check failure on line 128 in pkg/output/output.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

exists, err := fileUtils.ElementExists(outputDir)

Expand Down

0 comments on commit 6a6bfb4

Please sign in to comment.