mirror of https://github.com/daffainfo/nuclei.git
dev
parent
11286210e5
commit
91ad446212
|
@ -1,35 +0,0 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
||||
)
|
||||
|
||||
func TestFileCompile(t *testing.T) {
|
||||
options := testutils.DefaultOptions
|
||||
|
||||
testutils.Init(options)
|
||||
templateID := "testing-file"
|
||||
request := &Request{
|
||||
ID: templateID,
|
||||
MaxSize: "1Gb",
|
||||
NoRecursive: false,
|
||||
Extensions: []string{"all", ".lock"},
|
||||
DenyList: []string{".go"},
|
||||
}
|
||||
executerOpts := testutils.NewMockExecuterOptions(options, &testutils.TemplateInfo{
|
||||
ID: templateID,
|
||||
Info: model.Info{SeverityHolder: severity.Holder{Severity: severity.Low}, Name: "test"},
|
||||
})
|
||||
err := request.Compile(executerOpts)
|
||||
require.Nil(t, err, "could not compile file request")
|
||||
|
||||
require.Contains(t, request.denyList, ".go", "could not get .go in denylist")
|
||||
require.NotContains(t, request.extensions, ".go", "could get .go in allowlist")
|
||||
require.True(t, request.allExtensions, "could not get correct allExtensions")
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||
|
@ -118,25 +119,15 @@ func (request *Request) MakeResultEvent(wrapped *output.InternalWrappedEvent) []
|
|||
result.Lines = calculateLineFunc(allMatches, lineWords)
|
||||
}
|
||||
// Identify the position of match in file using a dirty hack.
|
||||
// for _, result := range results {
|
||||
// for _, extraction := range result.ExtractedResults {
|
||||
// file, _ := os.Open(filePath)
|
||||
// scanner := bufio.NewScanner(file)
|
||||
|
||||
// line := 1
|
||||
// for scanner.Scan() {
|
||||
// if strings.Contains(scanner.Text(), extraction) {
|
||||
// if result.FileToIndexPosition == nil {
|
||||
// result.FileToIndexPosition = make(map[string]int)
|
||||
// }
|
||||
// result.FileToIndexPosition[result.Matched] = line
|
||||
// continue
|
||||
// }
|
||||
// line++
|
||||
// }
|
||||
// file.Close()
|
||||
// }
|
||||
// }
|
||||
for _, result := range results {
|
||||
for _, extraction := range result.ExtractedResults {
|
||||
if result.FileToIndexPosition == nil {
|
||||
result.FileToIndexPosition = make(map[string]int)
|
||||
}
|
||||
result.FileToIndexPosition[result.Matched] = calculateFileIndexFunc(allMatches, extraction)
|
||||
log.Fatalf("%s %#v\n", extraction, result.FileToIndexPosition)
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
|
|
|
@ -166,3 +166,20 @@ func calculateLineFunc(allMatches []*output.InternalEvent, words map[string]stru
|
|||
sort.Ints(lines)
|
||||
return lines
|
||||
}
|
||||
|
||||
func calculateFileIndexFunc(allMatches []*output.InternalEvent, extraction string) int {
|
||||
for _, match := range allMatches {
|
||||
matchPt := *match
|
||||
opResult := matchPt["results"].(operators.Result)
|
||||
if opResult.Matched {
|
||||
for _, extracts := range opResult.Extracts {
|
||||
for _, extract := range extracts {
|
||||
if extraction == extract {
|
||||
return matchPt["results"].(int)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue