Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions internal/runner/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
func DoHealthCheck(options *types.Options) string {
// RW permissions on config file
var test strings.Builder
test.WriteString(fmt.Sprintf("Version: %s\n", config.Version))
test.WriteString(fmt.Sprintf("Operating System: %s\n", runtime.GOOS))
test.WriteString(fmt.Sprintf("Architecture: %s\n", runtime.GOARCH))
test.WriteString(fmt.Sprintf("Go Version: %s\n", runtime.Version()))
test.WriteString(fmt.Sprintf("Compiler: %s\n", runtime.Compiler))
fmt.Fprintf(&test, "Version: %s\n", config.Version)
fmt.Fprintf(&test, "Operating System: %s\n", runtime.GOOS)
fmt.Fprintf(&test, "Architecture: %s\n", runtime.GOARCH)
fmt.Fprintf(&test, "Go Version: %s\n", runtime.Version())
fmt.Fprintf(&test, "Compiler: %s\n", runtime.Compiler)

var testResult string
cfg := config.DefaultConfig
Expand All @@ -33,7 +33,7 @@ func DoHealthCheck(options *types.Options) string {
if err != nil {
testResult += fmt.Sprintf(" (%s)", err)
}
test.WriteString(fmt.Sprintf("File \"%s\" Read => %s\n", filename, testResult))
fmt.Fprintf(&test, "File \"%s\" Read => %s\n", filename, testResult)
ok, err = fileutil.IsWriteable(filename)
if ok {
testResult = "Ok"
Expand All @@ -43,7 +43,7 @@ func DoHealthCheck(options *types.Options) string {
if err != nil {
testResult += fmt.Sprintf(" (%s)", err)
}
test.WriteString(fmt.Sprintf("File \"%s\" Write => %s\n", filename, testResult))
fmt.Fprintf(&test, "File \"%s\" Write => %s\n", filename, testResult)
}
c4, err := net.Dial("tcp4", "scanme.sh:80")
if err == nil && c4 != nil {
Expand All @@ -53,7 +53,7 @@ func DoHealthCheck(options *types.Options) string {
if err != nil {
testResult = fmt.Sprintf("Ko (%s)", err)
}
test.WriteString(fmt.Sprintf("IPv4 connectivity to scanme.sh:80 => %s\n", testResult))
fmt.Fprintf(&test, "IPv4 connectivity to scanme.sh:80 => %s\n", testResult)
c6, err := net.Dial("tcp6", "scanme.sh:80")
if err == nil && c6 != nil {
_ = c6.Close()
Expand All @@ -62,7 +62,7 @@ func DoHealthCheck(options *types.Options) string {
if err != nil {
testResult = fmt.Sprintf("Ko (%s)", err)
}
test.WriteString(fmt.Sprintf("IPv6 connectivity to scanme.sh:80 => %s\n", testResult))
fmt.Fprintf(&test, "IPv6 connectivity to scanme.sh:80 => %s\n", testResult)
u4, err := net.Dial("udp4", "scanme.sh:53")
if err == nil && u4 != nil {
_ = u4.Close()
Expand All @@ -71,7 +71,7 @@ func DoHealthCheck(options *types.Options) string {
if err != nil {
testResult = fmt.Sprintf("Ko (%s)", err)
}
test.WriteString(fmt.Sprintf("IPv4 UDP connectivity to scanme.sh:53 => %s\n", testResult))
fmt.Fprintf(&test, "IPv4 UDP connectivity to scanme.sh:53 => %s\n", testResult)

return test.String()
}
2 changes: 1 addition & 1 deletion lib/sdk_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (e *NucleiEngine) applyRequiredDefaults(ctx context.Context) {
return
}
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf("[%v] ", event.TemplateID))
fmt.Fprintf(&sb, "[%v] ", event.TemplateID)
if event.Matched != "" {
sb.WriteString(event.Matched)
} else {
Expand Down
8 changes: 3 additions & 5 deletions pkg/fuzz/analyzers/time/time_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ func checkTimingDependency(
result := regression.IsWithinConfidence(correlationErrorRange, 1.0, slopeErrorRange)
if result {
var resultReason strings.Builder
resultReason.WriteString(fmt.Sprintf(
"[time_delay] made %d requests (baseline: %.2fs) successfully, with a regression slope of %.2f and correlation %.2f",
fmt.Fprintf(&resultReason, "[time_delay] made %d requests (baseline: %.2fs) successfully, with a regression slope of %.2f and correlation %.2f",
requestsLimit,
baselineDelay,
regression.slope,
regression.correlation,
))
regression.correlation)
for _, request := range requestsSent {
resultReason.WriteString(fmt.Sprintf("\n - delay: %ds, delayReceived: %fs", request.delay, request.delayReceived))
fmt.Fprintf(&resultReason, "\n - delay: %ds, delayReceived: %fs", request.delay, request.delayReceived)
}
return result, resultReason.String(), nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/js/devtools/scrapefuncs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ iconType: "solid"
for _, sig := range f.Signatures {
sigSlice = append(sigSlice, "`"+sig+"`")
}
sb.WriteString(fmt.Sprintf("| %s | %s | %s |\n", f.Name, f.Description, strings.Join(sigSlice, ", ")))
fmt.Fprintf(&sb, "| %s | %s | %s |\n", f.Name, f.Description, strings.Join(sigSlice, ", "))
}
sb.WriteString("\n")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/js/devtools/tsgen/cmd/tsgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func main() {
// generating index.ts file
var buff bytes.Buffer
for _, dir := range dirs {
buff.WriteString(fmt.Sprintf("export * as %s from './%s';\n", filepath.Base(dir), filepath.Base(dir)))
fmt.Fprintf(&buff, "export * as %s from './%s';\n", filepath.Base(dir), filepath.Base(dir))
}
_ = os.WriteFile(filepath.Join(out, "index.ts"), buff.Bytes(), 0755)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/js/libs/ldap/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ func DecodeSID(s string) string {

var builder strings.Builder
builder.WriteString("S-")
builder.WriteString(fmt.Sprintf("%d-", revisionLvl))
builder.WriteString(fmt.Sprintf("%d", authority))
fmt.Fprintf(&builder, "%d-", revisionLvl)
fmt.Fprintf(&builder, "%d", authority)
for _, v := range subAuthorities {
builder.WriteString(fmt.Sprintf("-%d", v))
fmt.Fprintf(&builder, "-%d", v)
}
return builder.String()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/js/libs/mysql/mysql_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func BuildDSN(opts MySQLOptions) (string, error) {
}
target := net.JoinHostPort(opts.Host, fmt.Sprintf("%d", opts.Port))
var dsn strings.Builder
dsn.WriteString(fmt.Sprintf("%v:%v", url.QueryEscape(opts.Username), opts.Password))
fmt.Fprintf(&dsn, "%v:%v", url.QueryEscape(opts.Username), opts.Password)
dsn.WriteString("@")
dsn.WriteString(fmt.Sprintf("%v(%v)", opts.Protocol, target))
fmt.Fprintf(&dsn, "%v(%v)", opts.Protocol, target)
if opts.DbName != "" {
dsn.WriteString(opts.DbName)
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/protocols/headless/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/types"
fileutil "github.com/projectdiscovery/utils/file"
osutils "github.com/projectdiscovery/utils/os"
processutil "github.com/projectdiscovery/utils/process"
)

// Browser is a browser structure for nuclei headless module
type Browser struct {
customAgent string
defaultHeaders map[string]string
tempDir string
previousPIDs map[int32]struct{} // track already running PIDs
engine *rod.Browser
options *types.Options
launcher *launcher.Launcher
Expand All @@ -36,14 +34,11 @@ type Browser struct {
// New creates a new nuclei headless browser module
func New(options *types.Options) (*Browser, error) {
var launcherURL, dataStore string
var previousPIDs map[int32]struct{}
var err error

chromeLauncher := launcher.New()

if options.CDPEndpoint == "" {
previousPIDs = processutil.FindProcesses(processutil.IsChromeProcess)

dataStore, err = os.MkdirTemp("", "nuclei-*")
if err != nil {
return nil, errors.Wrap(err, "could not create temporary directory")
Expand Down Expand Up @@ -135,7 +130,6 @@ func New(options *types.Options) (*Browser, error) {
httpClientOnce: &sync.Once{},
launcher: chromeLauncher,
}
engine.previousPIDs = previousPIDs
return engine, nil
}

Expand Down Expand Up @@ -199,5 +193,4 @@ func (b *Browser) Close() {
_ = b.engine.Close()
b.launcher.Kill()
_ = os.RemoveAll(b.tempDir)
processutil.CloseProcesses(processutil.IsChromeProcess, b.previousPIDs)
}
5 changes: 4 additions & 1 deletion pkg/protocols/headless/engine/page_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ func TestActionNavigate(t *testing.T) {

testHeadlessSimpleResponse(t, response, actions, 60*time.Second, func(page *Page, err error, out ActionData) {
require.Nilf(t, err, "could not run page actions")
require.Equal(t, "Nuclei Test Page", page.Page().MustInfo().Title, "could not navigate correctly")
require.NotNil(t, page, "page should not be nil")
info, infoErr := page.Page().Info()
require.NoError(t, infoErr, "could not fetch page info")
require.Equal(t, "Nuclei Test Page", info.Title, "could not navigate correctly")
})
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/protocols/headless/engine/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p *Page) routingRuleHandler(httpClient *http.Client) func(ctx *rod.Hijack)
var rawResp strings.Builder
respPayloads := ctx.Response.Payload()
if respPayloads != nil {
rawResp.WriteString(fmt.Sprintf("HTTP/1.1 %d %s\n", respPayloads.ResponseCode, respPayloads.ResponsePhrase))
fmt.Fprintf(&rawResp, "HTTP/1.1 %d %s\n", respPayloads.ResponseCode, respPayloads.ResponsePhrase)
for _, header := range respPayloads.ResponseHeaders {
rawResp.WriteString(header.Name + ": " + header.Value + "\n")
}
Expand Down Expand Up @@ -126,17 +126,17 @@ func (p *Page) routingRuleHandlerNative(e *proto.FetchRequestPaused) error {

// attempts to rebuild request
var rawReq strings.Builder
rawReq.WriteString(fmt.Sprintf("%s %s %s\n", e.Request.Method, e.Request.URL, "HTTP/1.1"))
fmt.Fprintf(&rawReq, "%s %s %s\n", e.Request.Method, e.Request.URL, "HTTP/1.1")
for _, header := range e.Request.Headers {
rawReq.WriteString(fmt.Sprintf("%s\n", header.String()))
fmt.Fprintf(&rawReq, "%s\n", header.String())
}
if e.Request.HasPostData {
rawReq.WriteString(fmt.Sprintf("\n%s\n", e.Request.PostData))
fmt.Fprintf(&rawReq, "\n%s\n", e.Request.PostData)
}

// attempts to rebuild the response
var rawResp strings.Builder
rawResp.WriteString(fmt.Sprintf("HTTP/1.1 %d %s\n", statusCode, e.ResponseStatusText))
fmt.Fprintf(&rawResp, "HTTP/1.1 %d %s\n", statusCode, e.ResponseStatusText)
for _, header := range e.ResponseHeaders {
rawResp.WriteString(header.Name + ": " + header.Value + "\n")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ func (c *ReportingClient) Close() {
continue
}
var msgBuilder strings.Builder
msgBuilder.WriteString(fmt.Sprintf("%d %s tickets created successfully", created, trackerName))
fmt.Fprintf(&msgBuilder, "%d %s tickets created successfully", created, trackerName)
failed := stats.Failed.Load()
if failed > 0 {
msgBuilder.WriteString(fmt.Sprintf(", %d failed", failed))
fmt.Fprintf(&msgBuilder, ", %d failed", failed)
}
gologger.Info().Msgf("%v", msgBuilder.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func MapHash[K constraints.Ordered, V any](m map[K]V) uint64 {
keys := mapsutil.GetSortedKeys(m)
var sb strings.Builder
for _, k := range keys {
sb.WriteString(fmt.Sprintf("%v:%v\n", k, m[k]))
fmt.Fprintf(&sb, "%v:%v\n", k, m[k])
}
return xxhash.Sum64([]byte(sb.String()))
}
Expand Down
Loading