Exploit database

GH-0cdace6d8e0b7f68db37abcdd3527660

tal7aouy/node2shell-scanner

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-111497

61 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files3
tal7aouy/node2shell-scannerRevision c1694f06dfc2

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

internal/scanner/node_test.go

Go · 4,642 bytes
package scanner

import (
	"context"
	"errors"
	"io"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"
)

func TestNodeVersions(t *testing.T) {
	for _, tc := range []struct{ banner, want string }{
		{"Node.js/22.23.3", "POTENTIALLY_VULNERABLE"}, {"Node.js/22.23.4", "PATCHED_VERSION"},
		{"node/24.22.0", "POTENTIALLY_VULNERABLE"}, {"node/24.22.1", "PATCHED_VERSION"},
		{"Node.js/26.12.0", "POTENTIALLY_VULNERABLE"}, {"Node.js/26.12.1", "PATCHED_VERSION"},
		{"Node.js/24.23.0", "PATCHED_VERSION"}, {"Node.js v24.22.0", "POTENTIALLY_VULNERABLE"},
		{"Express", "UNKNOWN"}, {"nginx", "UNKNOWN"}, {"", "UNKNOWN"},
		{"Node.js/24.22.1-rc.1", "UNKNOWN"}, {"Node.js/24.22.0-vendor", "UNKNOWN"},
		{"node/28.0.0", "UNKNOWN"}, {"node/20.19.0", "UNKNOWN"}, {"node/25.0.0", "UNKNOWN"},
		{"node/24.22.0 Node.js/24.22.1", "UNKNOWN"},
		{"node/24.22.1 Node.js/24.22.1", "PATCHED_VERSION"},
	} {
		t.Run(tc.banner, func(t *testing.T) {
			got, _ := NodeVersionVerdict(tc.banner)
			if got != tc.want {
				t.Fatalf("got %s want %s", got, tc.want)
			}
		})
	}
}

func TestNodeScan(t *testing.T) {
	for _, tc := range []struct{ name, value, want string }{
		{"Server", "Node.js/24.22.0", "POTENTIALLY_VULNERABLE"},
		{"X-Powered-By", "Express", "UNKNOWN"},
		{"X-Powered-By", "Node.js/24.22.1", "PATCHED_VERSION"},
	} {
		t.Run(tc.value, func(t *testing.T) {
			s := New(Options{})
			defer s.Close()
			calls := 0
			s.client.Transport = handlerTransport{http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				calls++
				if r.Method != "GET" || r.URL.Path != "/" {
					t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
				}
				w.Header().Set(tc.name, tc.value)
			})}
			result := s.Scan(context.Background(), "https://example.test")
			if result.Verdict != tc.want || calls != 1 {
				t.Fatal(result, calls)
			}
		})
	}
}

type handlerTransport struct{ handler http.Handler }

func (h handlerTransport) RoundTrip(r *http.Request) (*http.Response, error) {
	// Consume the upload, matching a server that reads the complete probe.
	if r.Body != nil {
		_, _ = io.Copy(io.Discard, r.Body)
	}
	w := httptest.NewRecorder()
	h.handler.ServeHTTP(w, r)
	return w.Result(), nil
}

func TestNormalize(t *testing.T) {
	for _, tc := range []struct{ input, want string }{
		{"example.com", "https://example.com/"},
		{"https://example.com/api?q=1#fragment", "https://example.com/api?q=1"},
		{"http://[::1]:8080/api", "http://[::1]:8080/api"},
	} {
		got, err := Normalize(tc.input)
		if err != nil || got != tc.want {
			t.Fatalf("%q: %q %v", tc.input, got, err)
		}
	}
	for _, input := range []string{"", "ftp://example.com", "https://user:[email protected]", "https://example.com:0", "https://example.com:65536", "https://example.com:"} {
		if _, err := Normalize(input); err == nil {
			t.Errorf("accepted invalid target %q", input)
		}
	}
}

func TestRedirectUnknown(t *testing.T) {
	s := New(Options{})
	defer s.Close()
	calls := 0
	s.client.Transport = handlerTransport{http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		calls++
		w.Header().Set("Location", "https://other.test")
		w.WriteHeader(302)
	})}
	r := s.Scan(context.Background(), "https://example.test")
	if calls != 1 || r.Verdict != "UNKNOWN" || !strings.Contains(r.Reason, "HTTP 302") || !strings.Contains(r.Reason, "redirects are not followed") {
		t.Fatal(r, calls)
	}
}

func TestResponseBoundAndHeaders(t *testing.T) {
	headers := http.Header{"Authorization": {"Bearer secret"}, "User-Agent": {"custom-agent"}}
	s := New(Options{Headers: headers})
	defer s.Close()
	headers.Set("Authorization", "changed")
	s.client.Transport = handlerTransport{http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Header.Get("Authorization") != "Bearer secret" || r.Header.Get("User-Agent") != "custom-agent" {
			t.Error("request headers were changed")
		}
		_, _ = io.WriteString(w, strings.Repeat("x", bodyLimit+1))
	})}
	r := s.Scan(context.Background(), "https://example.test")
	if !r.Evidence[0].Truncated || r.Evidence[0].BodyBytes != bodyLimit {
		t.Fatal(r)
	}
}

type errorTransport struct{ err error }

func (e errorTransport) RoundTrip(*http.Request) (*http.Response, error) { return nil, e.err }
func TestRequestErrors(t *testing.T) {
	for _, tc := range []struct {
		err  error
		want string
	}{{context.DeadlineExceeded, "timed out"}, {errors.New("test transport failure"), "connectivity"}} {
		s := New(Options{})
		s.client.Transport = errorTransport{tc.err}
		r := s.Scan(context.Background(), "https://example.test")
		if r.Verdict != "ERROR" || !strings.Contains(r.Reason, tc.want) {
			t.Fatal(r)
		}
		s.Close()
	}
}