Exploit database

GH-e76a3d3d0be61d55e6620c59c6a75b15

cumakurt/php2shell-scan

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-109618

413 sources

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

Repository files2
cumakurt/php2shell-scanRevision 7f4ea41c2e62

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

internal/baseline/baseline_test.go

Go · 4,242 bytes
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Cuma KURT <[email protected]>
//
// php2shell-scan is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any
// later version. It is distributed WITHOUT ANY WARRANTY; see the LICENSE file
// for the full text.

package baseline

import (
	"os"
	"path/filepath"
	"testing"
	"time"

	"php2shell-scan/internal/model"
)

func sampleReport() *model.Report {
	r := &model.Report{
		Tool:        "php2shell-scan",
		Version:     "test",
		GeneratedAt: time.Now().UTC(),
		Targets: []model.TargetResult{
			{
				Target: "http://example.test/",
				Status: model.TargetScanned,
				Findings: []model.Finding{
					{ID: "php-version-vulnerable", Target: "http://example.test/", Severity: model.SeverityHigh},
					{ID: "web-stack", Target: "http://example.test/", Severity: model.SeverityInfo},
				},
			},
			{
				Target: "http://other.test/",
				Status: model.TargetScanned,
				Findings: []model.Finding{
					{ID: "web-stack", Target: "http://other.test/", Severity: model.SeverityInfo},
				},
			},
		},
	}
	r.BuildSummary()
	return r
}

func TestBuildAndApplyRoundTrip(t *testing.T) {
	dir := t.TempDir()
	path := filepath.Join(dir, "baseline.json")

	original := sampleReport()
	file := Build(original, "accepted risk")
	if len(file.Entries) != 3 {
		t.Fatalf("expected 3 baseline entries, got %d", len(file.Entries))
	}
	if err := Write(path, file); err != nil {
		t.Fatal(err)
	}

	loaded, err := Load(path)
	if err != nil {
		t.Fatal(err)
	}

	// Simulate a rescan that also introduces one new finding.
	rescan := sampleReport()
	rescan.Targets[1].Findings = append(rescan.Targets[1].Findings, model.Finding{
		ID: "command-execution", Target: "http://other.test/", Severity: model.SeverityHigh,
	})

	suppressed := Apply(rescan, loaded)
	if suppressed != 3 {
		t.Errorf("expected 3 suppressed findings, got %d", suppressed)
	}
	rescan.BuildSummary()

	if rescan.Summary.Suppressed != 3 {
		t.Errorf("summary suppressed = %d, want 3", rescan.Summary.Suppressed)
	}
	if rescan.Summary.NewFindings != 1 {
		t.Errorf("summary new findings = %d, want 1", rescan.Summary.NewFindings)
	}
	if rescan.Summary.NewBySeverity["high"] != 1 {
		t.Errorf("new high findings = %d, want 1", rescan.Summary.NewBySeverity["high"])
	}

	newOnes := NewFindings(rescan)
	if len(newOnes) != 1 || newOnes[0].ID != "command-execution" {
		t.Fatalf("unexpected new findings: %+v", newOnes)
	}
}

func TestApplyScopesToTarget(t *testing.T) {
	report := sampleReport()
	file := &File{Version: 1, Entries: []Entry{
		{Target: "http://example.test/", FindingID: "web-stack"},
	}}

	Apply(report, file)
	if !report.Targets[0].Findings[1].Suppressed {
		t.Error("finding on the matching target should be suppressed")
	}
	if report.Targets[1].Findings[0].Suppressed {
		t.Error("a finding with the same id on another target must stay active")
	}
}

func TestSuppressionIsVisible(t *testing.T) {
	report := sampleReport()
	file := &File{Version: 1, Entries: []Entry{
		{Target: "http://example.test/", FindingID: "php-version-vulnerable", Reason: "risk accepted"},
	}}
	Apply(report, file)

	f := report.Targets[0].Findings[0]
	if !f.Suppressed || f.SuppressedReason != "risk accepted" {
		t.Fatalf("unexpected suppression state: %+v", f)
	}
	if len(f.Limitations) == 0 {
		t.Error("suppressed findings must explain themselves in limitations")
	}
}

func TestNilBaselineIsNoop(t *testing.T) {
	report := sampleReport()
	if got := Apply(report, nil); got != 0 {
		t.Errorf("nil baseline suppressed %d findings", got)
	}
}

func TestLoadRejectsBadFiles(t *testing.T) {
	dir := t.TempDir()
	bad := filepath.Join(dir, "bad.json")
	if err := os.WriteFile(bad, []byte("{not json"), 0o600); err != nil {
		t.Fatal(err)
	}
	if _, err := Load(bad); err == nil {
		t.Error("expected a parse error")
	}

	unsupported := filepath.Join(dir, "v9.json")
	if err := os.WriteFile(unsupported, []byte(`{"version":9}`), 0o600); err != nil {
		t.Fatal(err)
	}
	if _, err := Load(unsupported); err == nil {
		t.Error("expected an unsupported version error")
	}
}