Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Icewind\SMB\Wrapped; use Icewind\SMB\AbstractShare; use Icewind\SMB\ACL; ..
Decoded Output download
<?php
namespace Icewind\SMB\Wrapped; use Icewind\SMB\AbstractShare; use Icewind\SMB\ACL; use Icewind\SMB\Exception\AlreadyExistsException; use Icewind\SMB\Exception\AuthenticationException; use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\ConnectionException; use Icewind\SMB\Exception\DependencyException; use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\FileInUseException; use Icewind\SMB\Exception\InvalidHostException; use Icewind\SMB\Exception\InvalidTypeException; use Icewind\SMB\Exception\NotFoundException; use Icewind\SMB\Exception\InvalidRequestException; use Icewind\SMB\IFileInfo; use Icewind\SMB\INotifyHandler; use Icewind\SMB\IServer; use Icewind\SMB\ISystem; use Icewind\Streams\CallbackWrapper; use Icewind\SMB\Native\NativeShare; use Icewind\SMB\Native\NativeServer; class Share extends AbstractShare { private $server; private $name; public $connection = null; protected $parser; private $system; const MODE_MAP = array(FileInfo::MODE_READONLY => "r", FileInfo::MODE_HIDDEN => "h", FileInfo::MODE_ARCHIVE => "a", FileInfo::MODE_SYSTEM => "s"); const EXEC_CMD = "exec"; public function __construct(IServer $server, string $name, ISystem $system) { parent::__construct(); $this->server = $server; $this->name = $name; $this->system = $system; $this->parser = new Parser("UTC"); } private function getAuthFileArgument() : string { if ($this->server->getAuth()->getUsername()) { return "--authentication-file=" . $this->system->getFD(3); } else { return ''; } } protected function getConnection() : Connection { $maxProtocol = $this->server->getOptions()->getMaxProtocol(); $minProtocol = $this->server->getOptions()->getMinProtocol(); $smbClient = $this->system->getSmbclientPath(); $stdBuf = $this->system->getStdBufPath(); if ($smbClient === null) { throw new Exception("Backend not available"); } $command = sprintf("%s %s%s -t %s %s %s %s %s %s", self::EXEC_CMD, $stdBuf ? $stdBuf . " -o0 " : '', $smbClient, $this->server->getOptions()->getTimeout(), $this->getAuthFileArgument(), $this->server->getAuth()->getExtraCommandLineArguments(), $maxProtocol ? "--option='client max protocol=" . $maxProtocol . "'" : '', $minProtocol ? "--option='client min protocol=" . $minProtocol . "'" : '', escapeshellarg("//" . $this->server->getHost() . "/" . $this->name)); $connection = new Connection($command, $this->parser); $connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword()); $connection->connect(); if (!$connection->isValid()) { throw new ConnectionException((string) $connection->readLine()); } $connection->clearTillPrompt(); return $connection; } protected function connect() : Connection { if ($this->connection and $this->connection->isValid()) { return $this->connection; } $this->connection = $this->getConnection(); return $this->connection; } protected function reconnect() : void { if ($this->connection === null) { $this->connect(); } else { $this->connection->reconnect(); if (!$this->connection->isValid()) { throw new ConnectionException(); } } } public function getName() : string { return $this->name; } protected function simpleCommand(string $command, string $path) : bool { $escapedPath = $this->escapePath($path); $cmd = $command . " " . $escapedPath; $output = $this->execute($cmd); return $this->parseOutput($output, $path); } public function dir(string $path) : array { $escapedPath = $this->escapePath($path); $output = $this->execute("cd " . $escapedPath); $this->parseOutput($output, $path); $output = $this->execute("dir"); $this->execute("cd /"); return $this->parser->parseDir($output, $path, function (string $path) { return $this->getAcls($path); }); } public function stat(string $path) : IFileInfo { if ($path !== '' && $path !== "/") { $parent = dirname($path); $dir = $this->dir($parent); $file = array_values(array_filter($dir, function (IFileInfo $info) use($path) { return $info->getPath() === $path; })); if ($file) { return $file[0]; } } $escapedPath = $this->escapePath($path); $output = $this->execute("allinfo " . $escapedPath); if ($escapedPath == """" && count($output) < 2) { $output = $this->execute("allinfo " . "".""); } if (count($output) < 3) { $this->parseOutput($output, $path); } $stat = $this->parser->parseStat($output); return new FileInfo($path, basename($path), $stat["size"], $stat["mtime"], $stat["mode"], function () use($path) { return $this->getAcls($path); }); } public function mkdir(string $path) : bool { return $this->simpleCommand("mkdir", $path); } public function rmdir(string $path) : bool { return $this->simpleCommand("rmdir", $path); } public function del(string $path, bool $secondTry = false) : bool { try { return $this->simpleCommand("del", $path); } catch (NotFoundException $e) { try { $this->simpleCommand("ls", $path); } catch (NotFoundException $e2) { throw $e; } catch (\Exception $e2) { throw new InvalidTypeException($path); } throw $e; } catch (FileInUseException $e) { if ($secondTry) { throw $e; } $this->reconnect(); return $this->del($path, true); } } public function rename(string $from, string $to) : bool { $path1 = $this->escapePath($from); $path2 = $this->escapePath($to); $output = $this->execute("rename " . $path1 . " " . $path2); return $this->parseOutput($output, $to); } public function put(string $source, string $target) : bool { $path1 = $this->escapeLocalPath($source); $path2 = $this->escapePath($target); $output = $this->execute("put " . $path1 . " " . $path2); return $this->parseOutput($output, $target); } public function get(string $source, string $target) : bool { $path1 = $this->escapePath($source); $path2 = $this->escapeLocalPath($target); $output = $this->execute("get " . $path1 . " " . $path2); return $this->parseOutput($output, $source); } public function read(string $source) { $source = $this->escapePath($source); $connection = $this->getConnection(); stream_set_blocking($connection->getOutputStream(), false); $connection->write("get " . $source . " " . $this->system->getFD(5)); $connection->write("exit"); $fh = $connection->getFileOutputStream(); $fh = CallbackWrapper::wrap($fh, function () use($connection) { $connection->write(''); }); if (!is_resource($fh)) { throw new Exception("Failed to wrap file output"); } return $fh; } public function write(string $target) { $target = $this->escapePath($target); $connection = $this->getConnection(); $fh = $connection->getFileInputStream(); $connection->write("put " . $this->system->getFD(4) . " " . $target); $connection->write("exit"); $stream = CallbackWrapper::wrap($fh, function () use($connection) { $connection->write(''); }, null, function () use($connection) { $connection->close(false); }); if (is_resource($stream)) { return $stream; } else { throw new InvalidRequestException($target); } } public function append(string $target) { throw new DependencyException("php-libsmbclient is required for append"); } public function setMode(string $path, int $mode) { $modeString = ''; foreach (self::MODE_MAP as $modeByte => $string) { if ($mode & $modeByte) { $modeString .= $string; } } $path = $this->escapePath($path); $cmd = "setmode " . $path . " -rsha"; $output = $this->execute($cmd); $this->parseOutput($output, $path); if ($mode !== FileInfo::MODE_NORMAL) { $cmd = "setmode " . $path . " " . $modeString; $output = $this->execute($cmd); return $this->parseOutput($output, $path); } else { return true; } } public function notify(string $path) : INotifyHandler { if (!$this->system->getStdBufPath()) { throw new DependencyException("stdbuf is required for usage of the notify command"); } $connection = $this->getConnection(); $command = "notify " . $this->escapePath($path); $connection->write($command . PHP_EOL); return new NotifyHandler($connection, $path); } protected function execute(string $command) : array { $this->connect()->write($command); return $this->connect()->read(); } protected function parseOutput(array $lines, string $path = '') : bool { if (count($lines) === 0) { return true; } else { $this->parser->checkForError($lines, $path); } } protected function escape(string $string) : string { return escapeshellarg($string); } protected function escapePath(string $path) : string { $this->verifyPath($path); if ($path === "/") { $path = ''; } $path = str_replace("/", "\", $path); $path = str_replace(""", "^"", $path); $path = ltrim($path, "\"); return """ . $path . """; } protected function escapeLocalPath(string $path) : string { $path = str_replace(""", "\"", $path); return """ . $path . """; } protected function getAcls(string $path) : array { $commandPath = $this->system->getSmbcAclsPath(); if (!$commandPath) { return array(); } $command = sprintf("%s %s %s %s/%s %s", $commandPath, $this->getAuthFileArgument(), $this->server->getAuth()->getExtraCommandLineArguments(), escapeshellarg("//" . $this->server->getHost()), escapeshellarg($this->name), escapeshellarg($path)); $connection = new RawConnection($command); $connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword()); $connection->connect(); if (!$connection->isValid()) { throw new ConnectionException((string) $connection->readLine()); } $rawAcls = $connection->readAll(); return $this->parser->parseACLs($rawAcls); } public function getServer() : IServer { return $this->server; } public function __destruct() { unset($this->connection); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Icewind\SMB\Wrapped; use Icewind\SMB\AbstractShare; use Icewind\SMB\ACL; use Icewind\SMB\Exception\AlreadyExistsException; use Icewind\SMB\Exception\AuthenticationException; use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\ConnectionException; use Icewind\SMB\Exception\DependencyException; use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\FileInUseException; use Icewind\SMB\Exception\InvalidHostException; use Icewind\SMB\Exception\InvalidTypeException; use Icewind\SMB\Exception\NotFoundException; use Icewind\SMB\Exception\InvalidRequestException; use Icewind\SMB\IFileInfo; use Icewind\SMB\INotifyHandler; use Icewind\SMB\IServer; use Icewind\SMB\ISystem; use Icewind\Streams\CallbackWrapper; use Icewind\SMB\Native\NativeShare; use Icewind\SMB\Native\NativeServer; class Share extends AbstractShare { private $server; private $name; public $connection = null; protected $parser; private $system; const MODE_MAP = array(FileInfo::MODE_READONLY => "\162", FileInfo::MODE_HIDDEN => "\150", FileInfo::MODE_ARCHIVE => "\141", FileInfo::MODE_SYSTEM => "\163"); const EXEC_CMD = "\x65\x78\145\x63"; public function __construct(IServer $server, string $name, ISystem $system) { parent::__construct(); $this->server = $server; $this->name = $name; $this->system = $system; $this->parser = new Parser("\125\x54\x43"); } private function getAuthFileArgument() : string { if ($this->server->getAuth()->getUsername()) { return "\x2d\55\141\x75\164\x68\145\156\x74\x69\x63\141\164\x69\157\x6e\x2d\x66\151\x6c\145\x3d" . $this->system->getFD(3); } else { return ''; } } protected function getConnection() : Connection { $maxProtocol = $this->server->getOptions()->getMaxProtocol(); $minProtocol = $this->server->getOptions()->getMinProtocol(); $smbClient = $this->system->getSmbclientPath(); $stdBuf = $this->system->getStdBufPath(); if ($smbClient === null) { throw new Exception("\x42\x61\x63\153\x65\x6e\144\40\x6e\x6f\164\40\141\166\x61\x69\154\141\142\154\145"); } $command = sprintf("\45\163\x20\x25\163\x25\163\x20\x2d\164\x20\45\163\x20\45\x73\40\x25\163\x20\45\x73\x20\x25\x73\40\x25\163", self::EXEC_CMD, $stdBuf ? $stdBuf . "\40\x2d\x6f\60\x20" : '', $smbClient, $this->server->getOptions()->getTimeout(), $this->getAuthFileArgument(), $this->server->getAuth()->getExtraCommandLineArguments(), $maxProtocol ? "\x2d\55\157\160\x74\x69\157\x6e\x3d\x27\x63\154\151\145\x6e\x74\x20\155\x61\170\x20\160\162\157\x74\157\x63\157\154\x3d" . $maxProtocol . "\x27" : '', $minProtocol ? "\55\x2d\157\160\164\x69\x6f\156\x3d\x27\x63\154\x69\x65\156\x74\x20\155\x69\156\40\x70\x72\157\x74\157\143\x6f\x6c\x3d" . $minProtocol . "\47" : '', escapeshellarg("\57\57" . $this->server->getHost() . "\57" . $this->name)); $connection = new Connection($command, $this->parser); $connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword()); $connection->connect(); if (!$connection->isValid()) { throw new ConnectionException((string) $connection->readLine()); } $connection->clearTillPrompt(); return $connection; } protected function connect() : Connection { if ($this->connection and $this->connection->isValid()) { return $this->connection; } $this->connection = $this->getConnection(); return $this->connection; } protected function reconnect() : void { if ($this->connection === null) { $this->connect(); } else { $this->connection->reconnect(); if (!$this->connection->isValid()) { throw new ConnectionException(); } } } public function getName() : string { return $this->name; } protected function simpleCommand(string $command, string $path) : bool { $escapedPath = $this->escapePath($path); $cmd = $command . "\40" . $escapedPath; $output = $this->execute($cmd); return $this->parseOutput($output, $path); } public function dir(string $path) : array { $escapedPath = $this->escapePath($path); $output = $this->execute("\143\144\40" . $escapedPath); $this->parseOutput($output, $path); $output = $this->execute("\144\x69\162"); $this->execute("\143\144\40\x2f"); return $this->parser->parseDir($output, $path, function (string $path) { return $this->getAcls($path); }); } public function stat(string $path) : IFileInfo { if ($path !== '' && $path !== "\57") { $parent = dirname($path); $dir = $this->dir($parent); $file = array_values(array_filter($dir, function (IFileInfo $info) use($path) { return $info->getPath() === $path; })); if ($file) { return $file[0]; } } $escapedPath = $this->escapePath($path); $output = $this->execute("\141\x6c\x6c\151\x6e\146\x6f\x20" . $escapedPath); if ($escapedPath == "\x22\x22" && count($output) < 2) { $output = $this->execute("\141\x6c\x6c\151\156\x66\x6f\40" . "\x22\56\42"); } if (count($output) < 3) { $this->parseOutput($output, $path); } $stat = $this->parser->parseStat($output); return new FileInfo($path, basename($path), $stat["\x73\151\x7a\145"], $stat["\155\x74\151\155\x65"], $stat["\155\x6f\x64\145"], function () use($path) { return $this->getAcls($path); }); } public function mkdir(string $path) : bool { return $this->simpleCommand("\155\153\144\x69\162", $path); } public function rmdir(string $path) : bool { return $this->simpleCommand("\162\155\x64\x69\x72", $path); } public function del(string $path, bool $secondTry = false) : bool { try { return $this->simpleCommand("\144\145\154", $path); } catch (NotFoundException $e) { try { $this->simpleCommand("\154\163", $path); } catch (NotFoundException $e2) { throw $e; } catch (\Exception $e2) { throw new InvalidTypeException($path); } throw $e; } catch (FileInUseException $e) { if ($secondTry) { throw $e; } $this->reconnect(); return $this->del($path, true); } } public function rename(string $from, string $to) : bool { $path1 = $this->escapePath($from); $path2 = $this->escapePath($to); $output = $this->execute("\162\145\x6e\141\x6d\145\x20" . $path1 . "\x20" . $path2); return $this->parseOutput($output, $to); } public function put(string $source, string $target) : bool { $path1 = $this->escapeLocalPath($source); $path2 = $this->escapePath($target); $output = $this->execute("\x70\x75\164\40" . $path1 . "\x20" . $path2); return $this->parseOutput($output, $target); } public function get(string $source, string $target) : bool { $path1 = $this->escapePath($source); $path2 = $this->escapeLocalPath($target); $output = $this->execute("\147\145\x74\40" . $path1 . "\40" . $path2); return $this->parseOutput($output, $source); } public function read(string $source) { $source = $this->escapePath($source); $connection = $this->getConnection(); stream_set_blocking($connection->getOutputStream(), false); $connection->write("\x67\145\x74\40" . $source . "\40" . $this->system->getFD(5)); $connection->write("\145\170\x69\x74"); $fh = $connection->getFileOutputStream(); $fh = CallbackWrapper::wrap($fh, function () use($connection) { $connection->write(''); }); if (!is_resource($fh)) { throw new Exception("\106\141\x69\x6c\x65\x64\40\x74\157\x20\x77\x72\x61\160\x20\x66\151\x6c\x65\x20\x6f\165\164\160\x75\x74"); } return $fh; } public function write(string $target) { $target = $this->escapePath($target); $connection = $this->getConnection(); $fh = $connection->getFileInputStream(); $connection->write("\x70\165\164\40" . $this->system->getFD(4) . "\40" . $target); $connection->write("\145\x78\x69\x74"); $stream = CallbackWrapper::wrap($fh, function () use($connection) { $connection->write(''); }, null, function () use($connection) { $connection->close(false); }); if (is_resource($stream)) { return $stream; } else { throw new InvalidRequestException($target); } } public function append(string $target) { throw new DependencyException("\x70\150\160\x2d\x6c\151\x62\163\x6d\x62\x63\154\x69\145\x6e\x74\40\x69\x73\x20\x72\x65\x71\165\x69\x72\145\x64\40\146\x6f\162\40\x61\160\160\145\x6e\x64"); } public function setMode(string $path, int $mode) { $modeString = ''; foreach (self::MODE_MAP as $modeByte => $string) { if ($mode & $modeByte) { $modeString .= $string; } } $path = $this->escapePath($path); $cmd = "\x73\x65\164\155\x6f\144\x65\40" . $path . "\x20\55\162\x73\x68\x61"; $output = $this->execute($cmd); $this->parseOutput($output, $path); if ($mode !== FileInfo::MODE_NORMAL) { $cmd = "\163\x65\164\x6d\157\x64\145\40" . $path . "\40" . $modeString; $output = $this->execute($cmd); return $this->parseOutput($output, $path); } else { return true; } } public function notify(string $path) : INotifyHandler { if (!$this->system->getStdBufPath()) { throw new DependencyException("\x73\x74\x64\142\165\x66\40\151\x73\40\162\x65\161\165\151\x72\145\144\40\x66\x6f\x72\x20\x75\x73\141\147\x65\40\x6f\x66\40\164\150\145\x20\156\x6f\164\151\146\x79\x20\x63\x6f\155\155\141\x6e\144"); } $connection = $this->getConnection(); $command = "\x6e\157\x74\x69\146\x79\x20" . $this->escapePath($path); $connection->write($command . PHP_EOL); return new NotifyHandler($connection, $path); } protected function execute(string $command) : array { $this->connect()->write($command); return $this->connect()->read(); } protected function parseOutput(array $lines, string $path = '') : bool { if (count($lines) === 0) { return true; } else { $this->parser->checkForError($lines, $path); } } protected function escape(string $string) : string { return escapeshellarg($string); } protected function escapePath(string $path) : string { $this->verifyPath($path); if ($path === "\x2f") { $path = ''; } $path = str_replace("\x2f", "\134", $path); $path = str_replace("\42", "\136\x22", $path); $path = ltrim($path, "\134"); return "\x22" . $path . "\x22"; } protected function escapeLocalPath(string $path) : string { $path = str_replace("\x22", "\x5c\42", $path); return "\42" . $path . "\42"; } protected function getAcls(string $path) : array { $commandPath = $this->system->getSmbcAclsPath(); if (!$commandPath) { return array(); } $command = sprintf("\45\163\40\x25\x73\40\45\x73\40\45\163\x2f\x25\x73\40\x25\x73", $commandPath, $this->getAuthFileArgument(), $this->server->getAuth()->getExtraCommandLineArguments(), escapeshellarg("\57\57" . $this->server->getHost()), escapeshellarg($this->name), escapeshellarg($path)); $connection = new RawConnection($command); $connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword()); $connection->connect(); if (!$connection->isValid()) { throw new ConnectionException((string) $connection->readLine()); } $rawAcls = $connection->readAll(); return $this->parser->parseACLs($rawAcls); } public function getServer() : IServer { return $this->server; } public function __destruct() { unset($this->connection); } }
Function Calls
None |
Stats
MD5 | 4de7e938bb14464694db87a6e67d0541 |
Eval Count | 0 |
Decode Time | 90 ms |