mirror of
https://github.com/edoardottt/cariddi.git
synced 2026-09-12 04:37:47 +02:00
Enhanced performance and UI for HTML and TXT output
This commit is contained in:
+38
-4
@@ -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(`<div class="summary-card">
|
||||
<h2>Scan Summary</h2>
|
||||
<p>Scan timestamp: %s</p>
|
||||
<ul>
|
||||
<li><strong>Results:</strong> %d</li>
|
||||
<li><strong>Secrets:</strong> %d</li>
|
||||
<li><strong>Endpoints:</strong> %d</li>
|
||||
<li><strong>Extensions:</strong> %d</li>
|
||||
<li><strong>Errors:</strong> %d</li>
|
||||
<li><strong>Info:</strong> %d</li>
|
||||
</ul>
|
||||
</div>
|
||||
`, 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("<li><a target='_blank' href='" +
|
||||
html.EscapeString(output) + "'>" +
|
||||
html.EscapeString(output) +
|
||||
"</a> " + html.EscapeString(statusColor) + "</li>"); err != nil {
|
||||
"</a> " + html.EscapeString(statusColor) + "</li>\n"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if _, err := file.WriteString("<li>" + html.EscapeString(output) + "</li>"); err != nil {
|
||||
if _, err := file.WriteString("<li>" + html.EscapeString(output) + "</li>\n"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -164,7 +198,7 @@ func HeaderHTML(header string, filename string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := file.WriteString("<h3>" + html.EscapeString(header) + "</h3><ul>"); err != nil {
|
||||
if _, err := file.WriteString("<h3>" + html.EscapeString(header) + "</h3><ul>\n"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -179,7 +213,7 @@ func FooterHTML(filename string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := file.WriteString("</ul>"); err != nil {
|
||||
if _, err := file.WriteString("</ul>\n"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user