Exploit database

GH-2ee13264a6c5b7d8fd4f0c7537d8699c

abodystudio/php2shell-shield

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-109618

412 sources

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

Repository files15
abodystudio/php2shell-shieldRevision 954137004fe2

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

includes/class-lockdown.php

PHP · 8,065 bytes
<?php
/**
 * Lockdown switch for AbodyStudio Shield — the "take it offline" button.
 *
 * Writes an .htaccess block that denies all access except from the owner's
 * IP(s), and serves a static maintenance page to everyone else. Because the
 * deny happens at the web server before PHP runs, it genuinely stops PHP2Shell
 * from reaching the vulnerable code — unlike anything done in PHP.
 *
 * Important Cloudflare caveat: behind Cloudflare the server sees Cloudflare's
 * IPs, not the visitor's, so server-level IP rules are unreliable there. The
 * admin layer detects this and recommends the Cloudflare-side lockdown instead.
 *
 * WordPress-independent so it can be tested from the CLI.
 *
 * @package AbodyStudio_Shield
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Abody_Lockdown {

	const LABEL = 'Lockdown';
	const PAGE  = 'p2s-maintenance.html';

	/** @var Abody_Files */
	protected $files;

	/** @var string Base dir (no trailing slash) — normally ABSPATH. */
	protected $base;

	public function __construct( $base = null ) {
		if ( null === $base ) {
			$base = defined( 'ABSPATH' ) ? ABSPATH : getcwd();
		}
		$this->base  = rtrim( $base, '/\\' );
		$this->files = new Abody_Files( $base );
	}

	/**
	 * Where the maintenance page is written and the site-absolute URL that
	 * serves it.
	 *
	 * Under WordPress the page lives in the uploads folder and the ErrorDocument
	 * uses the uploads URL path — which already includes any subdirectory the
	 * site is installed in, so the 403 document resolves correctly on
	 * subdirectory installs. Without WordPress (CLI tests) it falls back to the
	 * base directory with a root-relative URL.
	 *
	 * @return array dir, url_path
	 */
	protected function page_target() {
		$slug = defined( 'ABODY_SLUG' ) ? ABODY_SLUG : 'abodystudio-old-php-versions-shield';
		if ( function_exists( 'wp_upload_dir' ) ) {
			$u = wp_upload_dir();
			if ( empty( $u['error'] ) && ! empty( $u['basedir'] ) && ! empty( $u['baseurl'] ) ) {
				$dir  = rtrim( $u['basedir'], '/\\' ) . '/' . $slug;
				$path = (string) parse_url( $u['baseurl'], PHP_URL_PATH ); // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- URL path only, for an ErrorDocument directive.
				$path = '/' . trim( $path, '/' ) . '/' . $slug . '/' . self::PAGE;
				return array( 'dir' => $dir, 'url_path' => $path );
			}
		}
		return array( 'dir' => $this->base, 'url_path' => '/' . self::PAGE );
	}

	/** Ensure the maintenance page's directory exists. */
	protected function ensure_dir( $dir ) {
		if ( is_dir( $dir ) ) {
			return true;
		}
		if ( function_exists( 'wp_mkdir_p' ) ) {
			return wp_mkdir_p( $dir );
		}
		return @mkdir( $dir, 0755, true ); // phpcs:ignore WordPress.WP.AlternativeFunctions -- CLI-test fallback only; WordPress uses wp_mkdir_p above.
	}

	/**
	 * .htaccess lines that allow only the given IPs and send everyone else to
	 * the maintenance page. Covers both Apache 2.4 (authz_core) and 2.2.
	 *
	 * @param array  $ips        Allowed IPs.
	 * @param string $error_path Site-absolute URL path to the maintenance page.
	 * @return array
	 */
	public function htaccess_lines( $ips, $error_path = null ) {
		if ( null === $error_path ) {
			$error_path = '/' . self::PAGE;
		}
		$lines = array();

		// Apache 2.4+
		$lines[] = '<IfModule mod_authz_core.c>';
		$lines[] = '  <RequireAny>';
		foreach ( $ips as $ip ) {
			$lines[] = '    Require ip ' . $ip;
		}
		$lines[] = '  </RequireAny>';
		$lines[] = '</IfModule>';

		// Apache 2.2
		$lines[] = '<IfModule !mod_authz_core.c>';
		$lines[] = '  Order deny,allow';
		$lines[] = '  Deny from all';
		foreach ( $ips as $ip ) {
			$lines[] = '  Allow from ' . $ip;
		}
		$lines[] = '</IfModule>';

		// Let everyone reach the maintenance page itself. The match is by
		// filename, so it applies wherever the page is served from (including
		// the uploads folder) even while the rest of the site is denied.
		$lines[] = '<Files "' . self::PAGE . '">';
		$lines[] = '  <IfModule mod_authz_core.c>';
		$lines[] = '    Require all granted';
		$lines[] = '  </IfModule>';
		$lines[] = '  <IfModule !mod_authz_core.c>';
		$lines[] = '    Order allow,deny';
		$lines[] = '    Allow from all';
		$lines[] = '  </IfModule>';
		$lines[] = '</Files>';

		$lines[] = 'ErrorDocument 403 ' . $error_path;
		return $lines;
	}

	public function maintenance_html() {
		return "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\">"
			. "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
			. "<title>Temporarily offline</title>"
			. "<style>body{margin:0;background:#0b0f10;color:#fff;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;"
			. "display:flex;min-height:100vh;align-items:center;justify-content:center;text-align:center}"
			. ".box{max-width:480px;padding:32px}h1{font-size:24px;margin:16px 0 8px}p{color:#9aa0a6;line-height:1.5}"
			. ".m{font-size:40px}</style></head><body><div class=\"box\">"
			. "<div class=\"m\">&#128274;</div><h1>We&rsquo;ll be right back</h1>"
			. "<p>This site is temporarily offline for security maintenance. Please check back soon.</p>"
			. "</div></body></html>\n";
	}

	/**
	 * Turn lockdown on.
	 *
	 * @param array $ips Allowed IPs (owner).
	 * @return array
	 */
	public function enable( $ips ) {
		$ips = $this->clean_ips( $ips );
		if ( empty( $ips ) ) {
			return array( 'ok' => false, 'reason' => 'no_valid_ip' );
		}
		if ( ! $this->files->writable( '.htaccess' ) ) {
			return array( 'ok' => false, 'reason' => 'cannot_write' );
		}

		// Write the maintenance page first so the 403 document exists. It goes
		// in the uploads folder (not the site root), and the ErrorDocument below
		// points at its uploads URL so it also works on subdirectory installs.
		$target = $this->page_target();
		$this->ensure_dir( $target['dir'] );
		$page_files = new Abody_Files( $target['dir'] );
		if ( ! $page_files->write( self::PAGE, $this->maintenance_html() ) ) {
			return array( 'ok' => false, 'reason' => 'page_write_failed' );
		}

		$content = $this->files->read( '.htaccess' );
		if ( null === abody_opt_get( 'abody_lock_backup' ) ) {
			abody_opt_set( 'abody_lock_backup', array( 'existed' => $this->files->exists( '.htaccess' ) ? 1 : 0 ) );
		}
		$new = $this->files->set_block( $content, $this->htaccess_lines( $ips, $target['url_path'] ), '.htaccess', self::LABEL );
		if ( ! $this->files->write( '.htaccess', $new ) ) {
			return array( 'ok' => false, 'reason' => 'write_failed' );
		}
		abody_opt_set( 'abody_lock', array( 'active' => 1, 'ips' => $ips, 'at' => time() ) );
		return array( 'ok' => true, 'ips' => $ips );
	}

	public function disable() {
		$content  = $this->files->read( '.htaccess' );
		$stripped = $this->files->strip_block( $content, self::LABEL );
		$backup   = abody_opt_get( 'abody_lock_backup' );
		if ( is_array( $backup ) && empty( $backup['existed'] ) && '' === trim( $stripped ) ) {
			$this->files->delete( '.htaccess' );
		} else {
			$this->files->write( '.htaccess', $stripped );
		}
		// Remove the maintenance page from wherever it was written (uploads).
		$target     = $this->page_target();
		$page_files = new Abody_Files( $target['dir'] );
		$page_files->delete( self::PAGE );
		// Also clear a copy an earlier version may have left in the site root.
		$this->files->delete( self::PAGE );
		abody_opt_set( 'abody_lock', array( 'active' => 0 ) );
		abody_opt_delete( 'abody_lock_backup' );
		return array( 'ok' => true );
	}

	public function is_active() {
		$s = abody_opt_get( 'abody_lock' );
		return ( is_array( $s ) && ! empty( $s['active'] ) );
	}

	public function allowed_ips() {
		$s = abody_opt_get( 'abody_lock' );
		if ( is_array( $s ) && isset( $s['ips'] ) ) {
			return $s['ips'];
		}
		return array();
	}

	protected function clean_ips( $ips ) {
		$out = array();
		if ( ! is_array( $ips ) ) {
			$ips = array( $ips );
		}
		foreach ( $ips as $ip ) {
			$ip = trim( (string) $ip );
			if ( abody_is_ip( $ip ) && ! in_array( $ip, $out, true ) ) {
				$out[] = $ip;
			}
		}
		return $out;
	}
}