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 files4
cumakurt/php2shell-scanRevision 7f4ea41c2e62
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
internal/ui/target.go
Go · 9,655 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 ui
import (
"fmt"
"sort"
"strings"
"php2shell-scan/internal/model"
"php2shell-scan/internal/report"
"php2shell-scan/internal/scanner"
)
// blockWidth is the visual width of a target block, in characters.
const blockWidth = 74
// TargetStart prints a single live progress line when several targets are
// scanned. A single-target run goes straight to its result block.
func (u *UI) TargetStart(index, total int, target string) {
if u.Quiet || total < 2 {
return
}
u.lockWrite(u.Err, "%s\n", u.paint(ansiDim, fmt.Sprintf("[%d/%d] scanning %s", index, total, target)))
}
// TargetBlock renders one completed target as a self-contained block, so
// parallel workers can never interleave their lines.
func (u *UI) TargetBlock(index, total int, tr model.TargetResult, events []scanner.Event) {
if u.Quiet {
return
}
u.mu.Lock()
defer u.mu.Unlock()
u.BlocksPrinted = true
w := u.Out
rule := strings.Repeat(u.glyph("━", "-"), blockWidth)
fmt.Fprintf(w, "\n%s\n", u.paint(ansiDim, rule))
u.headerLine(index, total, tr)
fmt.Fprintf(w, "%s\n", u.paint(ansiDim, rule))
if tr.Error != "" {
fmt.Fprintf(w, " %-10s %s\n", u.label("error"), u.paint(ansiYellow, tr.Error))
}
if tr.FinalURL != "" && tr.FinalURL != tr.Target {
fmt.Fprintf(w, " %-10s %s\n", u.label("final"), u.paint(ansiDim, tr.FinalURL))
}
// A failed target has nothing else worth printing.
if tr.Status == model.TargetUnreachable || tr.Status == model.TargetTimeout || tr.Status == model.TargetError {
fmt.Fprintf(w, " %-10s %s\n", u.label("duration"), humanMillis(tr.DurationMS))
return
}
if tr.PHP != nil {
fmt.Fprintf(w, " %-10s %s\n", u.label("php"), u.phpValue(tr.PHP))
if tr.PHP.Runtime != "" && tr.PHP.Runtime != "unknown" {
fmt.Fprintf(w, " %-10s %s\n", u.label("runtime"), tr.PHP.Runtime)
}
}
if tr.Stack != nil && len(tr.Stack.Items) > 0 {
fmt.Fprintf(w, " %-10s %s\n", u.label("stack"), truncate(report.StackSummary(tr.Stack), blockWidth-13))
}
if tr.WAF != nil {
fmt.Fprintf(w, " %-10s %s\n", u.label("waf"), u.wafValue(tr.WAF))
}
if tr.Exec != nil && tr.Exec.Status != model.ExecSkipped {
fmt.Fprintf(w, " %-10s %s\n", u.label("command"), u.execValue(tr.Exec))
}
if len(tr.POC) > 0 {
fmt.Fprintf(w, " %-10s %s\n", u.label("poc"), u.pocValue(tr.POC))
}
if findings := report.TargetFindings(tr, model.SeverityMedium); len(findings) > 0 {
fmt.Fprintf(w, "\n %s\n", u.paint(ansiBold, "Findings"))
for _, f := range findings {
fmt.Fprintf(w, " %s %s %s\n",
u.severityBadge(f.Severity),
truncate(f.Title, 56),
u.paint(ansiDim, "("+string(f.Confidence)+")"))
}
}
// Evidence is printed exactly once: validated command output first, then
// any PoC observation that the command list did not already cover.
if evidence := u.evidence(tr); len(evidence) > 0 {
fmt.Fprintf(w, "\n %s\n", u.paint(ansiBold, "Evidence"))
for _, e := range evidence {
fmt.Fprintf(w, " %s\n", u.paint(ansiDim, "$ "+e.command))
for _, line := range strings.Split(e.output, "\n") {
if line == "" {
continue
}
fmt.Fprintf(w, " %s\n", truncate(line, 110))
}
}
}
if u.Verbose {
for _, event := range events {
switch event.Level {
case scanner.LevelWarn:
fmt.Fprintf(w, " %s\n", u.paint(ansiYellow, "! "+event.Text))
case scanner.LevelError:
fmt.Fprintf(w, " %s\n", u.paint(ansiRed, "x "+event.Text))
default:
fmt.Fprintf(w, " %s\n", u.paint(ansiDim, u.glyph("·", "-")+" "+event.Text))
}
}
}
fmt.Fprintf(w, "\n %-10s %s\n", u.label("duration"), humanMillis(tr.DurationMS))
}
type evidenceLine struct {
command string
output string
}
// evidence merges command output and PoC output without repeating a command.
func (u *UI) evidence(tr model.TargetResult) []evidenceLine {
seen := map[string]bool{}
var out []evidenceLine
add := func(command, output string) {
command = strings.TrimSpace(command)
output = strings.TrimSpace(output)
if command == "" || output == "" || seen[command] {
return
}
seen[command] = true
out = append(out, evidenceLine{command: command, output: output})
}
if tr.Exec != nil {
for _, c := range tr.Exec.Commands {
if !c.Validated {
continue
}
add(c.Command, c.Output)
}
}
for _, p := range tr.POC {
if p.Status != model.POCConfirmed {
continue
}
for _, o := range p.Outputs {
if !o.Validated {
continue
}
add(o.Command, o.Output)
}
}
return out
}
// headerLine prints the target on the left and the status badge flush right.
// Widths are computed on the plain text so ANSI escapes cannot skew alignment.
func (u *UI) headerLine(index, total int, tr model.TargetResult) {
prefix := ""
if total > 1 {
prefix = fmt.Sprintf("[%d/%d] ", index, total)
}
badge := "[" + string(tr.Status) + "]"
const inner = blockWidth - 2
titleRoom := inner - len(prefix) - len(badge) - 1
title := prefix + truncate(tr.Target, titleRoom)
pad := inner - len(title) - len(badge)
if pad < 1 {
pad = 1
}
fmt.Fprintf(u.Out, " %s%s%s\n",
u.paint(ansiBold, title),
strings.Repeat(" ", pad),
u.statusBadge(tr))
}
func (u *UI) label(name string) string {
return u.paint(ansiDim, name)
}
// statusBadge renders the right-aligned status pill.
func (u *UI) statusBadge(tr model.TargetResult) string {
text := string(tr.Status)
if tr.Status == "" {
text = "unknown"
}
pill := "[" + text + "]"
switch tr.Status {
case model.TargetScanned:
return u.paint(ansiGreen, pill)
case model.TargetPartial:
return u.paint(ansiYellow, pill)
default:
return u.paint(ansiRed, pill)
}
}
// severityBadge renders a fixed-width, colour-coded severity tag.
func (u *UI) severityBadge(s model.Severity) string {
text := strings.ToUpper(string(s))
switch s {
case model.SeverityCritical:
return u.paint(ansiBold+ansiRed, fmt.Sprintf("%-8s", text))
case model.SeverityHigh:
return u.paint(ansiRed, fmt.Sprintf("%-8s", text))
case model.SeverityMedium:
return u.paint(ansiYellow, fmt.Sprintf("%-8s", text))
case model.SeverityLow:
return u.paint(ansiCyan, fmt.Sprintf("%-8s", text))
default:
return u.paint(ansiDim, fmt.Sprintf("%-8s", text))
}
}
func (u *UI) phpValue(p *model.PHPInfo) string {
if !p.Detected {
return u.paint(ansiDim, "not detected")
}
if p.Version == "" {
return u.paint(ansiYellow, "detected, version not determined")
}
value := fmt.Sprintf("%s %s %s %s", p.Version,
u.glyph("·", "-"), p.Confidence, u.glyph("·", "-")+" "+p.PatchStatus)
switch p.PatchStatus {
case "vulnerable", "vulnerable-eol":
return u.paint(ansiRed, value)
default:
return value
}
}
func (u *UI) wafValue(w *model.WAFFinding) string {
value := fmt.Sprintf("%s (%s confidence)", w.Status, w.Confidence)
switch w.Status {
case model.WAFDetected:
if len(w.Vendors) > 0 {
value = fmt.Sprintf("detected: %s (%s confidence)", strings.Join(w.Vendors, ", "), w.Confidence)
}
return u.paint(ansiYellow, value)
case model.WAFAmbiguous:
return u.paint(ansiYellow, value)
default:
return u.paint(ansiDim, value)
}
}
func (u *UI) execValue(e *model.ExecCheck) string {
switch e.Status {
case model.ExecExecuted:
var names []string
for _, c := range e.Commands {
if c.Validated {
names = append(names, c.Command)
}
}
sort.Strings(names)
value := fmt.Sprintf("%d validated", len(names))
if len(names) > 0 {
value += " (" + strings.Join(names, ", ") + ")"
}
return u.paint(ansiRed, value)
case model.ExecUncertain:
return u.paint(ansiDim, "uncertain (no validated output)")
case model.ExecFailed:
return u.paint(ansiDim, "failed (no response)")
default:
return u.paint(ansiDim, "skipped")
}
}
func (u *UI) pocValue(items []model.POCEvidence) string {
confirmed := 0
for _, item := range items {
if item.Status == model.POCConfirmed {
confirmed++
}
}
value := fmt.Sprintf("%d of %d checks confirmed", confirmed, len(items))
if confirmed == 0 {
return u.paint(ansiDim, value)
}
return u.paint(ansiGreen, value)
}
// ResultsTable prints a compact one-line-per-target table so a batch run can be
// reviewed at a glance.
func (u *UI) ResultsTable(r *model.Report) {
if u.Quiet || len(r.Targets) < 2 {
return
}
u.mu.Lock()
defer u.mu.Unlock()
w := u.Out
fmt.Fprintf(w, "\n %s\n", u.paint(ansiBold, "Target overview"))
fmt.Fprintf(w, " %-3s %-12s %-20s %-14s %s\n",
u.paint(ansiDim, "#"), u.paint(ansiDim, "STATUS"),
u.paint(ansiDim, "PHP"), u.paint(ansiDim, "WAF"), u.paint(ansiDim, "TARGET"))
for i, tr := range r.Targets {
php := "-"
if tr.PHP != nil {
switch {
case tr.PHP.Version != "":
php = tr.PHP.Version
case tr.PHP.Detected:
php = "unknown version"
}
}
waf := "-"
if tr.WAF != nil && tr.WAF.Status != model.WAFSkipped {
waf = string(tr.WAF.Status)
}
fmt.Fprintf(w, " %-3d %-12s %-20s %-14s %s\n",
i+1, string(tr.Status), truncate(php, 19), truncate(waf, 13), truncate(tr.Target, 56))
}
}
func truncate(s string, n int) string {
if n <= 3 || len(s) <= n {
return s
}
return s[:n-3] + "..."
}
func humanMillis(ms int64) string {
if ms < 1000 {
return fmt.Sprintf("%d ms", ms)
}
return fmt.Sprintf("%.1f s", float64(ms)/1000)
}