mirror of https://github.com/daffainfo/nuclei.git
RES-84 # Improve Nuclei CLI interface
* changed the template info content retrieval logic not to use reflectiondev
parent
75b21282ab
commit
ccf65ab1d3
|
@ -3,9 +3,9 @@ package format
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||||
)
|
||||
|
@ -35,29 +35,21 @@ func MarkdownDescription(event *output.ResultEvent) string { // TODO remove the
|
|||
builder.WriteString("**Details**: **")
|
||||
builder.WriteString(template)
|
||||
builder.WriteString("** ")
|
||||
|
||||
builder.WriteString(" matched at ")
|
||||
builder.WriteString(event.Host)
|
||||
|
||||
builder.WriteString("\n\n**Protocol**: ")
|
||||
builder.WriteString(strings.ToUpper(event.Type))
|
||||
|
||||
builder.WriteString("\n\n**Full URL**: ")
|
||||
builder.WriteString(event.Matched)
|
||||
|
||||
builder.WriteString("\n\n**Timestamp**: ")
|
||||
builder.WriteString(event.Timestamp.Format("Mon Jan 2 15:04:05 -0700 MST 2006"))
|
||||
|
||||
builder.WriteString("\n\n**Template Information**\n\n| Key | Value |\n|---|---|\n")
|
||||
|
||||
fields := reflect.TypeOf(event.Info)
|
||||
values := reflect.ValueOf(event.Info)
|
||||
numberOfFields := fields.NumField()
|
||||
|
||||
for i := 0; i < numberOfFields; i++ { // TODO review
|
||||
field := fields.Field(i)
|
||||
value := values.Field(i)
|
||||
|
||||
if field.Name == "reference" {
|
||||
continue
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("| %s | %s |\n", field.Name, value))
|
||||
}
|
||||
builder.WriteString(toMarkdownTableString(&event.Info))
|
||||
|
||||
if event.Request != "" {
|
||||
builder.WriteString("\n**Request**\n\n```http\n")
|
||||
|
@ -176,3 +168,27 @@ func GetMatchedTemplate(event *output.ResultEvent) string {
|
|||
template := builder.String()
|
||||
return template
|
||||
}
|
||||
|
||||
/*
|
||||
TODO remove and reuse the duplicated logic below jira.go <-> format.go
|
||||
*/
|
||||
|
||||
func toMarkdownTableString(templateInfo *model.Info) string {
|
||||
fields := map[string]string{
|
||||
"Name": templateInfo.Name,
|
||||
"Authors": sliceToString(templateInfo.Authors),
|
||||
"Tags": sliceToString(templateInfo.Tags),
|
||||
"Description": templateInfo.Description,
|
||||
"Severity": templateInfo.SeverityHolder.Severity.String(),
|
||||
}
|
||||
|
||||
builder := &bytes.Buffer{}
|
||||
for k, v := range fields {
|
||||
builder.WriteString(fmt.Sprintf("| %s | %s |\n", k, v))
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func sliceToString(stringSlice model.StringSlice) string {
|
||||
return strings.Join(stringSlice.ToSlice(), ", ")
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/andygrunwald/go-jira"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/format"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
||||
|
@ -102,33 +102,27 @@ func jiraFormatDescription(event *output.ResultEvent) string { // TODO remove th
|
|||
builder.WriteString("*Details*: *")
|
||||
builder.WriteString(template)
|
||||
builder.WriteString("* ")
|
||||
|
||||
builder.WriteString(" matched at ")
|
||||
builder.WriteString(event.Host)
|
||||
|
||||
builder.WriteString("\n\n*Protocol*: ")
|
||||
builder.WriteString(strings.ToUpper(event.Type))
|
||||
|
||||
builder.WriteString("\n\n*Full URL*: ")
|
||||
builder.WriteString(event.Matched)
|
||||
|
||||
builder.WriteString("\n\n*Timestamp*: ")
|
||||
builder.WriteString(event.Timestamp.Format("Mon Jan 2 15:04:05 -0700 MST 2006"))
|
||||
|
||||
builder.WriteString("\n\n*Template Information*\n\n| Key | Value |\n")
|
||||
|
||||
fields := reflect.TypeOf(event.Info)
|
||||
values := reflect.ValueOf(event.Info)
|
||||
numberOfFields := fields.NumField()
|
||||
|
||||
for i := 0; i < numberOfFields; i++ { // TODO review
|
||||
field := fields.Field(i)
|
||||
value := values.Field(i)
|
||||
|
||||
if field.Name == "reference" {
|
||||
continue
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("| %s | %s |\n", field.Name, value))
|
||||
}
|
||||
builder.WriteString(toMarkdownTableString(&event.Info))
|
||||
|
||||
builder.WriteString("\n*Request*\n\n{code}\n")
|
||||
builder.WriteString(event.Request)
|
||||
builder.WriteString("\n{code}\n\n*Response*\n\n{code}\n")
|
||||
builder.WriteString("\n{code}\n")
|
||||
|
||||
builder.WriteString("\n*Response*\n\n{code}\n")
|
||||
// If the response is larger than 5 kb, truncate it before writing.
|
||||
if len(event.Response) > 5*1024 {
|
||||
builder.WriteString(event.Response[:5*1024])
|
||||
|
@ -221,3 +215,27 @@ func jiraFormatDescription(event *output.ResultEvent) string { // TODO remove th
|
|||
data := builder.String()
|
||||
return data
|
||||
}
|
||||
|
||||
/*
|
||||
TODO remove and reuse the duplicated logic below jira.go <-> format.go
|
||||
*/
|
||||
|
||||
func toMarkdownTableString(templateInfo *model.Info) string {
|
||||
fields := map[string]string{
|
||||
"Name": templateInfo.Name,
|
||||
"Authors": sliceToString(templateInfo.Authors),
|
||||
"Tags": sliceToString(templateInfo.Tags),
|
||||
"Description": templateInfo.Description,
|
||||
"Severity": templateInfo.SeverityHolder.Severity.String(),
|
||||
}
|
||||
|
||||
builder := &bytes.Buffer{}
|
||||
for k, v := range fields {
|
||||
builder.WriteString(fmt.Sprintf("| %s | %s |\n", k, v))
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func sliceToString(stringSlice model.StringSlice) string {
|
||||
return strings.Join(stringSlice.ToSlice(), ", ")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue