Exploit databaseDownload repository ZIP
GH-e76a3d3d0be61d55e6620c59c6a75b15
cumakurt/php2shell-scan
Sources for CVE-2026-109618
412 sourcesPreferred 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/poc/poc.go
Suggested starting fileGo · 15,787 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 poc produces proof-of-concept evidence for findings that are already
// suspected, using only benign and read-only checks.
//
// Safety contract, enforced by construction:
// - every PoC sends a fixed, harmless request; no caller-supplied code runs,
// - no file is written, no shell is dropped, no listener is opened,
// - memory-corruption PoCs for CVE-2026-109618/109619 are reported as
// "not_attempted" with the reason, because triggering them can crash or
// corrupt the target,
// - a PoC is only reported as "confirmed" when its expected marker is
// observed in the response; everything else stays "unconfirmed".
package poc
import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"net/http"
"regexp"
"strings"
"php2shell-scan/internal/execprobe"
"php2shell-scan/internal/httpx"
"php2shell-scan/internal/model"
)
// MaxRequests bounds the number of HTTP requests a PoC phase may issue.
const MaxRequests = 12
// systemInfoCommands are the fixed, read-only commands whose verbatim output is
// captured as PoC evidence. They cannot write, delete, or change state.
var systemInfoCommands = []string{"uname -a", "id", "whoami", "hostname"}
var (
versionRe = regexp.MustCompile(`(?i)PHP\s*[/ ]?v?(\d+\.\d+\.\d+)`)
phpinfoRe = regexp.MustCompile(`(?i)PHP\s+Version[^0-9]{0,64}?(\d+\.\d+\.\d+)`)
titleRe = regexp.MustCompile(`(?i)PHP\s+(\d+\.\d+\.\d+)\s*-\s*phpinfo\(\)`)
)
// Options describes which PoCs are applicable to the current target.
type Options struct {
Enabled bool
Target string
// OS selects the read-only command set: auto, linux, or windows.
OS string
// Interface is a command interface that already validated a read-only
// command. Nil means the RCE nonce PoC cannot run.
Interface *execprobe.Interface
// PhpInfoPath is a diagnostic page that disclosed a PHP version.
PhpInfoPath string
// UploadURL is a discovered upload handler.
UploadURL string
// Nonce overrides the random marker. Used by tests only.
Nonce string
}
// Run executes the applicable PoCs and returns one record per PoC that was
// relevant to the target.
func Run(ctx context.Context, c *httpx.Client, opts Options) []model.POCEvidence {
if !opts.Enabled {
return nil
}
budget := MaxRequests
out := []model.POCEvidence{
systemInfo(ctx, c, opts, &budget),
rceNonce(ctx, c, opts, &budget),
infoDisclosure(ctx, c, opts, &budget),
uploadMethods(ctx, c, opts, &budget),
memoryCorruption("CVE-2026-109618", "RFC 1867 multipart OOM memory corruption",
"the RFC 1867 nested-multipart OOM payload is the documented trigger", opts.Target),
memoryCorruption("CVE-2026-109619", "stale global state use-after-free",
"the PHP_SESSION_UPLOAD_PROGRESS reference-hijack chain is the documented trigger", opts.Target),
}
return out
}
// systemInfoCommandsFor selects the fixed read-only commands for the target OS.
// An unknown OS keeps the Linux set because that is the common case for PHP;
// the Windows pair is only used when the platform was detected as Windows.
func systemInfoCommandsFor(osName string) []string {
if strings.EqualFold(osName, "windows") {
return []string{"whoami", "hostname"}
}
return systemInfoCommands
}
// systemInfo captures the verbatim output of the fixed read-only commands so
// the proof shows exactly what the target reported, not just a marker.
func systemInfo(ctx context.Context, c *httpx.Client, opts Options, budget *int) model.POCEvidence {
ev := model.POCEvidence{
ID: "poc-system-info",
Title: "Read-only system information collected from the target",
Status: model.POCSkipped,
Confidence: model.ConfidenceUnknown,
Target: opts.Target,
Method: "fixed read-only commands sent to an already validated command interface",
Expected: "each command returns output that matches its own expected format",
}
if opts.Interface == nil {
ev.Limitations = append(ev.Limitations,
"No validated command interface was available, so system information could not be collected.")
return ev
}
commands := systemInfoCommandsFor(opts.OS)
ev.Method = fmt.Sprintf("fixed read-only commands (%s) sent to an already validated command interface",
strings.Join(commands, ", "))
method := opts.Interface.Method
if method == "" || method == "auto" {
method = http.MethodGet
}
var executed, validated int
for _, command := range commands {
if *budget <= 0 {
ev.Limitations = append(ev.Limitations, "PoC request budget for this target was exhausted.")
break
}
*budget--
executed++
res, err := execprobe.SendCommand(ctx, c, *opts.Interface, method, command)
if err != nil {
ev.Outputs = append(ev.Outputs, model.POCCommandOutput{
Command: command,
Note: "request failed: " + trim(err.Error(), 120),
})
continue
}
if ev.HTTPStatus == 0 {
ev.HTTPStatus = res.Status
ev.LatencyMS = res.Latency.Milliseconds()
}
output := execprobe.ExtractOutput(res)
ok := execprobe.ValidateCommand(command, output)
if ok {
validated++
}
entry := model.POCCommandOutput{
Command: command,
Output: excerpt(output, 1200),
Validated: ok,
}
if !ok {
entry.Note = "output did not match the expected format for this command"
}
ev.Outputs = append(ev.Outputs, entry)
}
switch {
case validated > 0:
ev.Status = model.POCConfirmed
ev.Confidence = model.ConfidenceHigh
ev.Payload = fmt.Sprintf("%s %s?%s={%s}",
strings.ToUpper(method), opts.Interface.URL, opts.Interface.Param, strings.Join(commands, " | "))
ev.Observed = summaryOfOutputs(ev.Outputs)
ev.Evidence = []string{fmt.Sprintf("%d/%d read-only commands returned verifiable output", validated, executed)}
ev.Limitations = append(ev.Limitations,
"Outputs are verbatim but truncated for very long responses; they were produced by read-only commands only.")
default:
if executed == 0 {
ev.Limitations = append(ev.Limitations, "No command could be sent within the request budget.")
return ev
}
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Observed = summaryOfOutputs(ev.Outputs)
ev.Limitations = append(ev.Limitations,
"Commands were sent but no output matched the expected format, so this is not treated as proof.")
}
return ev
}
// summaryOfOutputs renders a compact one-line digest used on the console.
func summaryOfOutputs(outputs []model.POCCommandOutput) string {
var parts []string
for _, o := range outputs {
if o.Validated {
parts = append(parts, o.Command+" = "+excerpt(o.Output, 120))
}
}
return strings.Join(parts, " | ")
}
// rceNonce proves command execution with a random marker instead of output
// that could be produced by a static page.
func rceNonce(ctx context.Context, c *httpx.Client, opts Options, budget *int) model.POCEvidence {
ev := model.POCEvidence{
ID: "poc-command-execution",
Title: "Read-only command execution with a random marker",
Status: model.POCSkipped,
Confidence: model.ConfidenceUnknown,
Target: opts.Target,
Method: "fixed template echo <random marker> sent to an already validated command interface",
}
if opts.Interface == nil {
ev.Limitations = append(ev.Limitations,
"No validated command interface was available, so the execution PoC was not attempted.")
return ev
}
if *budget <= 0 {
ev.Limitations = append(ev.Limitations, "PoC request budget for this target was exhausted.")
return ev
}
nonce := opts.Nonce
if nonce == "" {
nonce = randomNonce()
}
payload := "echo p2s-" + nonce
ev.Payload = payload
ev.Expected = "the response contains the marker p2s-" + nonce
method := opts.Interface.Method
if method == "" || method == "auto" {
method = http.MethodGet
}
*budget--
res, err := execprobe.SendCommand(ctx, c, *opts.Interface, method, payload)
if err != nil {
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Observed = "request failed: " + trim(err.Error(), 160)
ev.Limitations = append(ev.Limitations,
"A transport failure is not evidence for or against command execution.")
return ev
}
output := execprobe.ExtractOutput(res)
ev.HTTPStatus = res.Status
ev.LatencyMS = res.Latency.Milliseconds()
ev.Observed = excerpt(output, 200)
marker := "p2s-" + nonce
switch {
case strings.Contains(output, marker):
ev.Status = model.POCConfirmed
ev.Confidence = model.ConfidenceHigh
ev.Evidence = []string{
fmt.Sprintf("%s %s?%s=%s -> HTTP %d", strings.ToUpper(method), opts.Interface.URL, opts.Interface.Param, payload, res.Status),
"observed marker: " + marker,
"observed output: " + ev.Observed,
}
ev.Limitations = append(ev.Limitations,
"The marker is unique to this run, so a cached or static response cannot explain it.",
"Only a read-only echo was executed; no file was written and no persistence was attempted.")
default:
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Limitations = append(ev.Limitations,
"The random marker was not observed in the response, so the PoC is unconfirmed.",
"An unconfirmed PoC is not evidence that the interface executes commands.")
}
return ev
}
// infoDisclosure re-reads a diagnostic page and records the version string it
// exposes as reproducible evidence.
func infoDisclosure(ctx context.Context, c *httpx.Client, opts Options, budget *int) model.POCEvidence {
ev := model.POCEvidence{
ID: "poc-phpinfo-disclosure",
Title: "PHP diagnostic page discloses runtime details",
Status: model.POCSkipped,
Confidence: model.ConfidenceUnknown,
Target: opts.Target,
Method: "single read-only GET request to the previously discovered diagnostic page",
}
if opts.PhpInfoPath == "" {
ev.Limitations = append(ev.Limitations, "No diagnostic page was discovered for this target.")
return ev
}
if *budget <= 0 {
ev.Limitations = append(ev.Limitations, "PoC request budget for this target was exhausted.")
return ev
}
ev.Payload = "GET " + opts.PhpInfoPath
ev.Expected = "the response contains a PHP version string"
*budget--
res, err := c.Get(ctx, opts.PhpInfoPath)
if err != nil {
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Observed = "request failed: " + trim(err.Error(), 160)
return ev
}
ev.HTTPStatus = res.Status
ev.LatencyMS = res.Latency.Milliseconds()
body := string(res.Body)
version := extractVersion(body)
ev.Observed = excerpt(body, 200)
switch {
case res.Status == http.StatusOK && version != "":
ev.Status = model.POCConfirmed
ev.Confidence = model.ConfidenceHigh
ev.Evidence = []string{
fmt.Sprintf("GET %s -> HTTP %d", opts.PhpInfoPath, res.Status),
"disclosed PHP version: " + version,
}
ev.Limitations = append(ev.Limitations,
"The page content is public; the scanner only reads the version and does not persist other fields.")
default:
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Limitations = append(ev.Limitations,
"The page did not return a PHP version at scan time, so the disclosure PoC is unconfirmed.")
}
return ev
}
// uploadMethods checks which verbs an upload handler advertises. OPTIONS is a
// safe, idempotent request and no file is transferred.
func uploadMethods(ctx context.Context, c *httpx.Client, opts Options, budget *int) model.POCEvidence {
ev := model.POCEvidence{
ID: "poc-upload-handler",
Title: "Upload handler advertises a write verb",
Status: model.POCSkipped,
Confidence: model.ConfidenceUnknown,
Target: opts.Target,
Method: "single OPTIONS request (safe and idempotent; no file is uploaded)",
}
if opts.UploadURL == "" {
ev.Limitations = append(ev.Limitations, "No upload handler was discovered for this target.")
return ev
}
if *budget <= 0 {
ev.Limitations = append(ev.Limitations, "PoC request budget for this target was exhausted.")
return ev
}
ev.Payload = "OPTIONS " + opts.UploadURL
ev.Expected = "the Allow header lists POST"
*budget--
res, err := c.Options(ctx, opts.UploadURL)
if err != nil {
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Observed = "request failed: " + trim(err.Error(), 160)
return ev
}
allow := strings.ToUpper(res.HeaderValue("Allow"))
ev.HTTPStatus = res.Status
ev.LatencyMS = res.Latency.Milliseconds()
if allow != "" {
ev.Observed = "Allow: " + allow
} else {
ev.Observed = fmt.Sprintf("HTTP %d without an Allow header", res.Status)
}
if strings.Contains(allow, "POST") || strings.Contains(allow, "PUT") {
ev.Status = model.POCConfirmed
ev.Confidence = model.ConfidenceMedium
ev.Evidence = []string{
fmt.Sprintf("OPTIONS %s -> HTTP %d", opts.UploadURL, res.Status),
"advertised verbs: " + allow,
}
ev.Limitations = append(ev.Limitations,
"An advertised write verb does not prove the handler is vulnerable; no upload was attempted.")
} else {
ev.Status = model.POCUnconfirmed
ev.Confidence = model.ConfidenceLow
ev.Limitations = append(ev.Limitations,
"An empty Allow header is common and does not rule out upload handling.")
}
return ev
}
// memoryCorruption documents, per CVE, why the destructive PoC was not run.
func memoryCorruption(cve, title, trigger, target string) model.POCEvidence {
return model.POCEvidence{
ID: "poc-" + strings.ToLower(strings.TrimPrefix(cve, "CVE-")),
Title: cve + " trigger PoC",
CVE: cve,
Status: model.POCNotAttempted,
Confidence: model.ConfidenceUnknown,
Target: target,
Method: "deliberately not executed",
Payload: "withheld",
Expected: "not applicable",
Observed: "not executed",
Evidence: []string{"scope: " + title},
Limitations: []string{
trigger + "; running it can exhaust the worker, corrupt heap memory, or take the service down.",
"Active exploitation is outside this tool's scope: the PoC is withheld and the finding remains an exposure indicator.",
},
}
}
func randomNonce() string {
buf := make([]byte, 8)
if _, err := rand.Read(buf); err != nil {
// A predictable marker would be worse than no marker; fall back to a
// constant that still cannot appear in a cached page by accident.
return "fallbackstatic"
}
return hex.EncodeToString(buf)
}
// extractVersion returns the first PHP version string found in a page.
func extractVersion(body string) string {
for _, re := range []*regexp.Regexp{phpinfoRe, titleRe, versionRe} {
if m := re.FindStringSubmatch(body); m != nil {
return m[1]
}
}
return ""
}
func excerpt(s string, n int) string {
s = strings.Join(strings.Fields(s), " ")
if len(s) > n {
return s[:n] + " [truncated]"
}
return s
}
func trim(s string, n int) string {
if len(s) <= n {
return s
}
return s[:n] + "..."
}
// Summary renders a one-line digest for the console.
func Summary(items []model.POCEvidence) string {
if len(items) == 0 {
return "not run"
}
var confirmed, unconfirmed, notAttempted, skipped int
for _, item := range items {
switch item.Status {
case model.POCConfirmed:
confirmed++
case model.POCUnconfirmed:
unconfirmed++
case model.POCNotAttempted:
notAttempted++
default:
skipped++
}
}
return fmt.Sprintf("%d confirmed, %d unconfirmed, %d not attempted, %d skipped",
confirmed, unconfirmed, notAttempted, skipped)
}