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
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||||
|
@ -118,25 +119,15 @@ func (request *Request) MakeResultEvent(wrapped *output.InternalWrappedEvent) []
|
||||||
result.Lines = calculateLineFunc(allMatches, lineWords)
|
result.Lines = calculateLineFunc(allMatches, lineWords)
|
||||||
}
|
}
|
||||||
// Identify the position of match in file using a dirty hack.
|
// Identify the position of match in file using a dirty hack.
|
||||||
// for _, result := range results {
|
for _, result := range results {
|
||||||
// for _, extraction := range result.ExtractedResults {
|
for _, extraction := range result.ExtractedResults {
|
||||||
// file, _ := os.Open(filePath)
|
if result.FileToIndexPosition == nil {
|
||||||
// scanner := bufio.NewScanner(file)
|
result.FileToIndexPosition = make(map[string]int)
|
||||||
|
}
|
||||||
// line := 1
|
result.FileToIndexPosition[result.Matched] = calculateFileIndexFunc(allMatches, extraction)
|
||||||
// for scanner.Scan() {
|
log.Fatalf("%s %#v\n", extraction, result.FileToIndexPosition)
|
||||||
// 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()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,3 +166,20 @@ func calculateLineFunc(allMatches []*output.InternalEvent, words map[string]stru
|
||||||
sort.Ints(lines)
|
sort.Ints(lines)
|
||||||
return 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