forked from jaeles-project/jaeles
/
report.go
82 lines (72 loc) · 2.14 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package cmd
import (
"github.com/hktalent/jaeles/core"
"github.com/hktalent/jaeles/libs"
"github.com/hktalent/jaeles/sender"
"github.com/hktalent/jaeles/utils"
"github.com/spf13/cobra"
"os"
"path"
)
func init() {
var reportCmd = &cobra.Command{
Use: "report",
Short: "Generate HTML report based on scanned output",
Long: libs.Banner(),
RunE: runReport,
}
reportCmd.Flags().String("template", "~/.jaeles/plugins/report/index.html", "Report Template File")
reportCmd.SetHelpFunc(ReportHelp)
RootCmd.AddCommand(reportCmd)
}
func runReport(cmd *cobra.Command, _ []string) error {
templateFile, _ := cmd.Flags().GetString("template")
Options.Report.TemplateFile = templateFile
DoGenReport(Options)
return nil
}
// DoGenReport generate report from scanned result
func DoGenReport(options libs.Options) error {
if options.Report.TemplateFile == "" {
options.Report.TemplateFile = "~/.jaeles/plugins/report/index.html"
}
if options.VerboseSummary {
options.Report.TemplateFile = "~/.jaeles/plugins/report/verbose.html"
}
if options.Report.ReportName == "" {
options.Report.ReportName = "jaeles-report.html"
}
// get template file
options.Report.TemplateFile = utils.NormalizePath(options.Report.TemplateFile)
if !utils.FileExists(options.Report.TemplateFile) {
// get content of remote URL via GET request
req := libs.Request{
URL: libs.REPORT,
}
if options.VerboseSummary {
req.URL = libs.VREPORT
}
utils.DebugF("Download template from: %v", req.URL)
res, err := sender.JustSend(options, req)
if err != nil || len(res.Body) <= 0 {
utils.ErrorF("Error GET templateFile: %v", err)
return nil
}
os.MkdirAll(path.Dir(options.Report.TemplateFile), 0750)
_, err = utils.WriteToFile(options.Report.TemplateFile, res.Body)
if err != nil {
utils.ErrorF("Error write templateFile: %v", err)
return nil
}
utils.InforF("Write report template to: %v", options.Report.TemplateFile)
}
err := core.GenActiveReport(options)
if err != nil {
utils.ErrorF("Error gen active report: %v", err)
}
err = core.GenPassiveReport(options)
if err != nil {
utils.ErrorF("Error gen passive report: %v", err)
}
return nil
}