From 016fcccfc99fd86afc1d69b2e100700202f5cd3b Mon Sep 17 00:00:00 2001 From: edoardottt Date: Wed, 9 Apr 2025 14:04:23 +0200 Subject: [PATCH] Enhanced performance and UI for HTML and TXT output --- pkg/output/html.go | 42 ++++++++++++++++++++++++++++++++++++++---- pkg/output/output.go | 17 +++++++++-------- pkg/output/txt.go | 15 +++++++++++++++ 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/pkg/output/html.go b/pkg/output/html.go index 3aa7297..2f6542f 100644 --- a/pkg/output/html.go +++ b/pkg/output/html.go @@ -27,9 +27,11 @@ along with this program. If not, see http://www.gnu.org/licenses/. package output import ( + "fmt" "html" "log" "os" + "time" fileUtils "github.com/edoardottt/cariddi/internal/file" ) @@ -120,6 +122,38 @@ func BannerHTML(filename string) { file.Close() } +// WriteSummaryCard adds a summary card. +func WriteSummaryCard(filename string, results, secrets, endpoints, extensions, errors, infos int) { + file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, fileUtils.Permission0644) + if err != nil { + log.Println(err) + os.Exit(1) + } + + defer file.Close() + + content := fmt.Sprintf(`
+

Scan Summary

+

Scan timestamp: %s

+ +
+`, time.Now().Format("2006-01-02 15:04:05"), results, secrets, endpoints, extensions, errors, infos) + + _, err = file.WriteString(content) + if err != nil { + log.Fatal(err) + } + + file.Close() +} + // AppendOutputToHTML appends the output to html file. func AppendOutputToHTML(output string, status string, filename string, isLink bool) { file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, fileUtils.Permission0644) @@ -144,11 +178,11 @@ func AppendOutputToHTML(output string, status string, filename string, isLink bo if _, err := file.WriteString("
  • " + html.EscapeString(output) + - " " + html.EscapeString(statusColor) + "
  • "); err != nil { + " " + html.EscapeString(statusColor) + "\n"); err != nil { log.Fatal(err) } } else { - if _, err := file.WriteString("
  • " + html.EscapeString(output) + "
  • "); err != nil { + if _, err := file.WriteString("
  • " + html.EscapeString(output) + "
  • \n"); err != nil { log.Fatal(err) } } @@ -164,7 +198,7 @@ func HeaderHTML(header string, filename string) { os.Exit(1) } - if _, err := file.WriteString("

    " + html.EscapeString(header) + "

    \n"); err != nil { log.Fatal(err) } diff --git a/pkg/output/output.go b/pkg/output/output.go index a00e841..e116822 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -30,6 +30,7 @@ import ( "fmt" "html" "os" + "strings" fileUtils "github.com/edoardottt/cariddi/internal/file" "github.com/edoardottt/cariddi/pkg/input" @@ -73,9 +74,7 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S } ResultFilename := fileUtils.CreateOutputFile(flags.TXTout, ResultFile, "txt") - for _, elem := range finalResults { - AppendOutputToTxt(elem, ResultFilename) - } + WriteAllTxt(finalResults, ResultFilename) // if secrets flag enabled save also secrets if flags.Secrets && len(finalSecret) > 0 { @@ -91,15 +90,17 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S for _, elem := range finalEndpoints { for _, parameter := range elem.Parameters { - finalString := "" + parameter.Parameter - if len(parameter.Attacks) != 0 { - finalString += " -" + var sb strings.Builder + sb.WriteString(parameter.Parameter) + if len(parameter.Attacks) > 0 { + sb.WriteString(" -") for _, attack := range parameter.Attacks { - finalString += " " + attack + sb.WriteString(" ") + sb.WriteString(attack) } } - AppendOutputToTxt(fmt.Sprintf("%s in %s", finalString, elem.URL), EndpointFilename) + AppendOutputToTxt(fmt.Sprintf("%s in %s", sb.String(), elem.URL), EndpointFilename) } } } diff --git a/pkg/output/txt.go b/pkg/output/txt.go index c5802db..20f41bb 100644 --- a/pkg/output/txt.go +++ b/pkg/output/txt.go @@ -29,6 +29,7 @@ package output import ( "log" "os" + "strings" fileUtils "github.com/edoardottt/cariddi/internal/file" ) @@ -47,3 +48,17 @@ func AppendOutputToTxt(output string, filename string) { file.Close() } + +// WriteAllTxt opens the output file and append all the strings +// taken as input in one-shot operation. +func WriteAllTxt(output []string, filename string) { + var buf strings.Builder + + for _, elem := range output { + buf.WriteString(elem + "\n") + } + + if err := os.WriteFile(filename, []byte(buf.String()), fileUtils.Permission0644); err != nil { + log.Fatal(err) + } +}