github.com/projectdiscovery/nuclei/v2@v2.9.15/internal/runner/healthcheck.go (about)

     1  package runner
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"runtime"
     7  	"strings"
     8  
     9  	"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
    10  	"github.com/projectdiscovery/nuclei/v2/pkg/types"
    11  	fileutil "github.com/projectdiscovery/utils/file"
    12  )
    13  
    14  // DoHealthCheck performs self-diagnostic checks
    15  func DoHealthCheck(options *types.Options) string {
    16  	// RW permissions on config file
    17  	var test strings.Builder
    18  	test.WriteString(fmt.Sprintf("Version: %s\n", config.Version))
    19  	test.WriteString(fmt.Sprintf("Operating System: %s\n", runtime.GOOS))
    20  	test.WriteString(fmt.Sprintf("Architecture: %s\n", runtime.GOARCH))
    21  	test.WriteString(fmt.Sprintf("Go Version: %s\n", runtime.Version()))
    22  	test.WriteString(fmt.Sprintf("Compiler: %s\n", runtime.Compiler))
    23  
    24  	var testResult string
    25  	cfg := config.DefaultConfig
    26  	for _, filename := range []string{cfg.GetFlagsConfigFilePath(), cfg.GetIgnoreFilePath(), cfg.GetChecksumFilePath()} {
    27  		ok, err := fileutil.IsReadable(filename)
    28  		if ok {
    29  			testResult = "Ok"
    30  		} else {
    31  			testResult = "Ko"
    32  		}
    33  		if err != nil {
    34  			testResult += fmt.Sprintf(" (%s)", err)
    35  		}
    36  		test.WriteString(fmt.Sprintf("File \"%s\" Read => %s\n", filename, testResult))
    37  		ok, err = fileutil.IsWriteable(filename)
    38  		if ok {
    39  			testResult = "Ok"
    40  		} else {
    41  			testResult = "Ko"
    42  		}
    43  		if err != nil {
    44  			testResult += fmt.Sprintf(" (%s)", err)
    45  		}
    46  		test.WriteString(fmt.Sprintf("File \"%s\" Write => %s\n", filename, testResult))
    47  	}
    48  	c4, err := net.Dial("tcp4", "scanme.sh:80")
    49  	if err == nil && c4 != nil {
    50  		c4.Close()
    51  	}
    52  	testResult = "Ok"
    53  	if err != nil {
    54  		testResult = fmt.Sprintf("Ko (%s)", err)
    55  	}
    56  	test.WriteString(fmt.Sprintf("IPv4 connectivity to scanme.sh:80 => %s\n", testResult))
    57  	c6, err := net.Dial("tcp6", "scanme.sh:80")
    58  	if err == nil && c6 != nil {
    59  		c6.Close()
    60  	}
    61  	testResult = "Ok"
    62  	if err != nil {
    63  		testResult = fmt.Sprintf("Ko (%s)", err)
    64  	}
    65  	test.WriteString(fmt.Sprintf("IPv6 connectivity to scanme.sh:80 => %s\n", testResult))
    66  	u4, err := net.Dial("udp4", "scanme.sh:53")
    67  	if err == nil && u4 != nil {
    68  		u4.Close()
    69  	}
    70  	testResult = "Ok"
    71  	if err != nil {
    72  		testResult = fmt.Sprintf("Ko (%s)", err)
    73  	}
    74  	test.WriteString(fmt.Sprintf("IPv4 UDP connectivity to scanme.sh:53 => %s\n", testResult))
    75  
    76  	return test.String()
    77  }