diff --git a/cmd/main.go b/cmd/main.go index bf88f05..fbdd1c6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,10 +1,13 @@ package main import ( + "encoding/json" "flag" "fmt" + "html/template" "log" "os" + "strings" "time" "github.com/zcyberseclab/zscan/pkg/stage" @@ -25,6 +28,7 @@ func main() { censysAPIKey := flag.String("censys-api-key", "", "Censys API Key") censysSecret := flag.String("censys-secret", "", "Censys API Secret") versionFlag := flag.Bool("version", false, "Show version information") + outputFormat := flag.String("output", "", "Output format: json, html, or md") flag.Parse() if *versionFlag { @@ -69,6 +73,138 @@ func main() { log.Printf("Error printing results: %v", err) } + // 处理输出格式 + if *outputFormat != "" { + if err := saveResults(results, *outputFormat); err != nil { + log.Printf("Error saving results: %v", err) + } else { + log.Printf("Results saved in %s format", *outputFormat) + } + } + duration := time.Since(startTime) log.Printf("\nScan completed in: %v\n", duration) } + +func saveResults(results []stage.Node, format string) error { + switch strings.ToLower(format) { + case "json": + return saveJSON(results) + case "html": + return saveHTML(results) + case "md": + return saveMarkdown(results) + default: + return fmt.Errorf("unsupported output format: %s", format) + } +} + +func saveJSON(results []stage.Node) error { + data, err := json.MarshalIndent(results, "", " ") + if err != nil { + return err + } + return os.WriteFile("zscan_results.json", data, 0644) +} + +func saveHTML(results []stage.Node) error { + tmpl := ` + +
+OS: {{.OS}}
{{end}} + {{if .Tags}}Tags: {{join .Tags ", "}}
{{end}} +Port: {{.Port}} ({{.Protocol}})
+ {{if .Banner}}Banner: {{.Banner}}
{{end}} + {{if .Version}}Version: {{.Version}}
{{end}} +CVE: {{.CVEID}}
+Severity: {{.Severity}}
+