nuclei/internal/installer/zipslip_unix_test.go
Tarun Koyalwar dc44105baf
nuclei v3 : misc updates (#4247)
* use parsed options while signing

* update project layout to v3

* fix .gitignore

* remove example template

* misc updates

* bump tlsx version

* hide template sig warning with env

* js: retain value while using log

* fix nil pointer derefernce

* misc doc update

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-10-17 17:44:13 +05:30

69 lines
1.4 KiB
Go

package installer
import (
"io/fs"
"os"
"path/filepath"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var _ fs.FileInfo = &tempFileInfo{}
type tempFileInfo struct {
name string
}
func (t *tempFileInfo) Name() string {
return t.name
}
func (t *tempFileInfo) ModTime() time.Time {
return time.Now()
}
func (t *tempFileInfo) Mode() fs.FileMode {
return fs.ModePerm
}
func (t tempFileInfo) IsDir() bool {
return false
}
func (t *tempFileInfo) Size() int64 {
return 100
}
func (t *tempFileInfo) Sys() any {
return nil
}
func TestZipSlip(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping Unix Zip LFI Check")
}
configuredTemplateDirectory := filepath.Join(os.TempDir(), "templates")
defer os.RemoveAll(configuredTemplateDirectory)
t.Run("negative scenarios", func(t *testing.T) {
filePathsFromZip := []string{
"./../nuclei-templates/../cve/test.yaml",
"nuclei-templates/../cve/test.yaml",
"nuclei-templates/././../cve/test.yaml",
"nuclei-templates/.././../cve/test.yaml",
"nuclei-templates/.././../cve/../test.yaml",
}
tm := TemplateManager{}
for _, filePathFromZip := range filePathsFromZip {
var tmp fs.FileInfo = &tempFileInfo{name: filePathFromZip}
writePath := tm.getAbsoluteFilePath(configuredTemplateDirectory, filePathFromZip, tmp)
require.Equal(t, "", writePath, filePathFromZip)
}
})
}