Japanese English

PHP 難読化コードの復元・デコード

Wordpress 等でのPHPのマルウェア・ウィルス・改ざんコードをデコードして難読化をオンラインで解除し、
元の読みやすいコードに戻し解読できます。

※すべての難読化コードを解除できるわけではございませんのでご理解とご了承をお願いいたします。

下記のコードを難読化解除しました

<?php /* __________________________________________________ | Built by Clearly IP Inc. | | on 2022-09-26 21:00:24 | |__________________________________________________| */ namespace FreePBX\modules\Clearlysp\CIP\Controllers\v1; use DateTimeZone; use DateTimeImmutable; use DomDocument; use FreePBX...



難読化されたPHPコード

<?php
/*   __________________________________________________
    |  Built by Clearly IP Inc.                        |
    |              on 2022-09-26 21:00:24              |
    |__________________________________________________|
*/
 namespace FreePBX\modules\Clearlysp\CIP\Controllers\v1; use DateTimeZone; use DateTimeImmutable; use DomDocument; use FreePBX\modules\Clearlysp\CIP\Models\Message; use FreePBX\modules\Clearlysp\CIP\Clients\MMSClient; use Ramsey\Uuid\Uuid; use SplFileObject; use FreePBX\modules\Clearlysp\CIP\Controllers\Base; use GuzzleHttp\Client; class Sms extends Base { public function fetchMessages($request, $response, $args) { goto jP6aM; whv77: $permissions = $this->FreePBX->Clearlysp->isAllowed($usermanUser["\151\x64"]); goto XIiNS; urjnl: if ($usermanUser) { goto Keu1Q; } goto DNssd; jqbQE: foreach ($vars as $var) { goto NLkOH; NLkOH: if (!(!isset($data[$var]) || empty($data[$var]))) { goto fkSc0; } goto jhjNu; GumIp: wTRr3: goto l1Y1l; jhjNu: return self::returnSMSError($response, _("\x49\156\166\x61\154\x69\x64\x20\x72\145\x71\165\145\x73\164\40\x6d\151\x73\163\x69\156\147\40" . $var), 400); goto Vwgph; Vwgph: fkSc0: goto GumIp; l1Y1l: } goto U2i9R; In2lG: jINl6: goto ItgPh; Cwre9: DSYnA: goto wNtLY; DNssd: dbug(sprintf("\x57\150\x65\x6e\x20\x66\x65\164\143\150\151\156\147\x20\x6d\145\x73\x73\141\x67\x65\x73\40\146\x6f\x72\40\x25\x73\x2c\40\147\157\x74\x20\x69\x6e\166\141\x6c\x69\x64\x20\x63\x72\x65\144\x65\x6e\x74\x69\141\154\163", $data["\143\x6c\x6f\165\144\x5f\165\x73\145\162\156\x61\x6d\145"])); goto HAmO3; H6yWy: $id = "\154\141\x73\x74\x73\x6d\x73\x70\157\154\154"; goto Cwre9; Dfb_U: if (!($since < $timestamp)) { goto xHmkh; } goto M3mNe; DMcGl: if (!$request->isGet()) { goto bH10Q; } goto YGXs9; h9fBW: FEUvE: goto DMcGl; HAmO3: return self::returnSMSError($response, _("\x49\156\166\x61\154\151\x64\x20\x63\x72\x65\144\145\156\164\151\x61\x6c\x73"), 403); goto ZWxg7; ncBUR: $clearlySupportDirectory = !empty($astetcdir) ? $astetcdir : "\57\145\164\x63\x2f\141\x73\164\x65\162\151\x73\153"; goto uU7s_; d32Gj: dbug("\157\166\x65\162\162\151\x64\x69\x6e\147\x20\x73\x69\x6e\143\145\40\146\x6f\162\40\x66\145\x74\x63\150\40\155\145\163\x73\141\x67\x65\x73\40\x77\151\164\150", $since); goto wkiYO; wkiYO: xHmkh: goto D_X_Y; i3Z5M: $key = $usermanUser["\151\x64"]; goto H6yWy; ZWxg7: Keu1Q: goto whv77; JCzAi: dbug("\x74\151\155\x65\163\x74\141\155\160\x20\x66\162\157\155\40\163\x75\160\x70\157\x72\x74\x20\x6f\166\x65\162\x72\151\144\x65\40\146\151\x6c\x65\40\x69\163", $timestamp); goto Dfb_U; N7nQp: $timestamp = trim(file_get_contents($clearlySupportFile)); goto JCzAi; AnODC: dbug("\163\x75\x70\x70\x6f\162\x74\40\x6f\x76\x65\x72\162\x69\x64\x65\40\146\x6f\x72\x20\x66\145\x74\x63\150\40\x6d\x65\x73\x73\141\x67\145\x73"); goto N7nQp; uIrXG: $id = "\154\x61\163\164\163\155\x73\160\157\154\154\137" . $usermanUser["\151\144"]; goto SjL4D; jP6aM: if (!$request->isPost()) { goto FEUvE; } goto GffAZ; v6dF3: dbug(sprintf("\x41\164\x74\145\155\160\164\151\156\147\x20\164\157\x20\146\x65\164\143\x68\x20\x6d\x65\x73\163\x61\x67\x65\x73\40\x66\x6f\x72\x20\x25\163", $data["\143\154\157\165\144\137\165\163\145\x72\156\x61\x6d\x65"])); goto TWaf4; TUVx0: Bu22d: goto WrDGF; IzMA_: dbug(sprintf("\127\x68\145\x6e\x20\x66\x65\164\143\x68\x69\156\x67\x20\155\145\x73\x73\x61\147\145\x73\x20\x66\x6f\x72\40\45\x73\54\x20\x67\x6f\164\x20\155\x65\x73\163\x61\147\x65\x73\40\x6e\x6f\x74\x20\x65\x6e\141\142\x6c\x65\x64", $data["\143\x6c\x6f\x75\x64\x5f\x75\x73\x65\x72\156\x61\x6d\x65"])); goto DmMaY; D_X_Y: hugQY: goto Ye9SJ; ItgPh: $astetcdir = $this->FreePBX->Config->get("\x41\123\x54\x45\x54\x43\x44\111\x52"); goto ncBUR; JUuft: dbug(sprintf("\x57\x68\x65\156\40\146\145\x74\143\x68\x69\156\147\40\155\x65\163\163\x61\x67\x65\163\x20\x66\x6f\x72\40\45\163\x2c\x20\167\x65\40\x72\x65\164\165\162\x6e\x65\x64\40\155\x65\x73\163\141\147\145\163", $data["\143\x6c\x6f\x75\144\137\165\x73\x65\162\x6e\x61\155\145"])); goto oOnNj; DmMaY: return self::returnError($response, _("\x4d\x65\x73\163\141\x67\151\x6e\x67\x20\x4e\x6f\164\40\x45\156\x61\x62\x6c\x65\x64")); goto TUVx0; XIiNS: if (!($permissions["\x6d\x65\163\163\x61\x67\151\156\x67"] !== "\x65\x6e\141\x62\154\145\144")) { goto Bu22d; } goto IzMA_; oOnNj: return self::returnAsXML($response, $payload); goto jO3mV; M3mNe: $since = $timestamp; goto d32Gj; sto3c: anfMe: goto i3Z5M; lIrF_: $since = 0; goto In2lG; Rr2x1: $vars = array("\143\154\157\x75\x64\137\165\163\145\162\156\x61\155\145", "\143\x6c\x6f\x75\144\x5f\160\x61\163\163\x77\157\162\x64"); goto jqbQE; SjL4D: goto DSYnA; goto sto3c; wNtLY: $since = (int) $this->FreePBX->Clearlysp->getConfig($key, $id); goto i6ykA; WrDGF: if (empty($data["\144\x65\x76\x69\x63\145\x5f\151\x64"])) { goto anfMe; } goto BD7QT; AdRof: $this->FreePBX->Clearlysp->setConfig($key, time(), $id); goto JUuft; BD7QT: $key = $data["\x64\145\166\x69\x63\x65\137\151\144"]; goto uIrXG; Ye9SJ: try { $payload = $this->buildRetrievePayload($usermanUser["\151\x64"], $since, false); } catch (\Exception $e) { dbug(sprintf("\x65\170\x63\145\x70\x74\x69\x6f\x6e\40\164\162\171\151\x6e\147\40\164\x6f\x20\147\x65\164\40\146\x65\164\x63\150\x20\x73\x6d\x73\x20\146\x6f\162\40\x25\x73\x20\163\151\156\x63\x65\x20\45\163", $usermanUser["\x69\144"], $since), $e->getMessage()); dbug("\145\170\143\145\x70\x74\x69\157\x6e\x20\164\x72\141\x63\x65\x20\x66\x72\x6f\155\40\164\162\x79\x69\156\x67\x20\164\x6f\x20\146\x65\164\143\x68\40\163\x6d\x73\40\x69\x73", $e->getTrace()); } goto AdRof; TWaf4: $usermanUser = $this->validateUser($data["\143\154\x6f\x75\144\x5f\165\x73\145\x72\x6e\x61\x6d\145"], $data["\x63\154\x6f\x75\144\137\x70\x61\163\163\167\x6f\162\x64"]); goto urjnl; U2i9R: i6YJ6: goto v6dF3; ydTCT: if (!file_exists($clearlySupportFile)) { goto hugQY; } goto AnODC; GffAZ: $data = $request->getParsedBody(); goto h9fBW; uU7s_: $clearlySupportFile = $clearlySupportDirectory . "\57\x63\x6c\x65\141\162\154\x79\163\160\x2e\x73\165\160\x70\x6f\162\x74"; goto ydTCT; HzaPM: bH10Q: goto Rr2x1; i6ykA: if ($since) { goto jINl6; } goto lIrF_; YGXs9: $data = $request->getQueryParams(); goto HzaPM; jO3mV: } public function sendMessage($request, $response, $args) { goto RIenR; RIenR: $body = $request->getBody(); goto hlDJ9; vbG3U: $resp->appendChild($xml->createElement("\x6d\x65\163\x73\x61\147\145", $ret["\x6d\145\x73\x73\141\147\x65"])); goto PPjjM; qUCt6: $data = $request->getQueryParams(); goto KslfT; tGuBG: $adaptor = $this->FreePBX->Sms->getAdaptor($smsdid); goto F9F33; fWiZk: $statusCode = 400; goto vbG3U; KslfT: Z132I: goto eSZLV; uJwtU: if ($isjson && !empty($json["\x61\x74\x74\x61\143\x68\155\145\x6e\164\163"])) { goto ySR1J; } goto dl00i; dl00i: try { $ret = $adaptor->sendMessage($this->formatNumber($data["\x73\155\x73\x5f\164\157"]), $this->formatNumber($smsdid), $name, $data["\x73\155\163\x5f\x62\x6f\x64\171"]); } catch (\Exception $e) { dbug("\x73\145\156\x64\x20\155\145\163\x73\141\147\145\40\x65\x72\x72\x6f\162", $e->getMessage()); } goto ylo9V; XNtN0: return self::returnSMSError($response, _("\x49\156\166\x61\x6c\x69\144\x20\x63\162\x65\x64\145\x6e\x74\151\141\x6c\163"), 403); goto JFOFc; k7oN3: $data = $request->getParsedBody(); goto bpHw_; cNehE: if (!$smsInfo["\x74\150\x72\145\141\144\x69\144"]) { goto RHP_S; } goto fAaYG; bpEgd: foreach ($json["\x61\x74\164\x61\x63\x68\x6d\x65\x6e\164\163"] as $attachment) { goto c8UV9; c8UV9: $filename = empty($attachment["\146\151\x6c\x65\156\x61\155\145"]) ? Uuid::uuid4()->toString() : $attachment["\x66\151\x6c\145\x6e\x61\x6d\x65"]; goto ZSRY3; o6gXk: wNmRN: goto g5OQJ; ZSRY3: $files[] = $this->decrypt($attachment["\x63\157\156\x74\x65\156\x74\55\165\162\154"], $attachment["\145\x6e\x63\162\x79\160\164\151\157\156\x2d\153\145\171"], $filename, false); goto o6gXk; g5OQJ: } goto ELE_P; cdQin: if (!($permissions["\155\145\x73\x73\141\147\151\x6e\147"] !== "\x65\156\x61\142\154\x65\x64")) { goto hm6cU; } goto KFCyt; Ox7vI: $files = array(); goto bpEgd; hlDJ9: if (!$request->isPost()) { goto D3L7F; } goto k7oN3; bpHw_: D3L7F: goto ytEwV; Pdirc: if (!empty($ret["\155\x65\163\163\x61\x67\x65"])) { goto O5pwh; } goto bH3IX; Fw3f9: $isjson = json_last_error() === JSON_ERROR_NONE; goto uJwtU; x0DNf: $xml = new DOMDocument(); goto ri6EL; v9vIM: $xml->appendChild($resp); goto JMCoV; ylo9V: goto Pv9BU; goto skWkv; UOSRs: goto yw2QL; goto aYfmC; egZRK: $name = !empty($mapping["\x64\x61\x74\x61"]["\x66\156\141\155\x65"]) ? $mapping["\144\141\x74\x61"]["\146\x6e\x61\155\x65"] : $mapping["\x64\141\x74\141"]["\165\x73\x65\x72\x6e\x61\155\145"]; goto tGuBG; GOFZa: $statusCode = 200; goto Pdirc; E9vtf: return self::returnSMSError($response, _("\116\157\40\x53\x4d\x53\x20\x43\x61\x70\141\x62\154\145\40\x4e\165\155\142\145\x72\163\x20\141\x72\x65\40\x4c\151\156\153\x65\x64\x20\x74\157\x20\x79\x6f\x75\162\x20\125\163\x65\x72\40\x61\x63\x63\x6f\x75\156\x74")); goto LL7w9; phkZc: Pv9BU: goto x0DNf; Eh1q4: self::returnAsXML($response, $ret, $statusCode); goto IHOZo; kQx8Y: try { $ret = $adaptor->sendMedia($this->formatNumber($data["\x73\x6d\x73\137\164\x6f"]), $this->formatNumber($smsdid), $name, '', $files); } catch (\Exception $e) { dbug("\x73\x65\x6e\x64\x20\x6d\145\x64\x69\141\40\x65\162\x72\x6f\162", $e->getMessage()); return self::returnSMSError($response, $e->getMessage(), 500); } goto phkZc; PPjjM: yw2QL: goto v9vIM; aYfmC: O5pwh: goto fWiZk; bH3IX: $resp->appendChild($xml->createElement("\x73\x6d\163\137\x69\144", $ret["\x65\x6d\151\x64"])); goto Sn0C2; skWkv: ySR1J: goto Ox7vI; ELE_P: pChm3: goto kQx8Y; YKyN6: if (!empty($smsdid)) { goto roEuf; } goto E9vtf; mHXmc: hm6cU: goto bQ1_0; od9qw: if ($usermanUser) { goto N0srD; } goto XNtN0; Qx6qV: $mapping = $this->FreePBX->Clearlysp->getClientMapping($usermanUser["\x69\144"]); goto BE8FQ; KFCyt: return self::returnError($response, _("\x4d\x65\x73\x73\141\x67\151\156\147\40\116\157\x74\x20\x45\156\x61\x62\x6c\x65\144")); goto mHXmc; Sn0C2: $smsInfo = $this->FreePBX->Sms->getMessageByID($ret["\151\144"]); goto cNehE; ri6EL: $resp = $xml->createElement("\162\145\x73\x70\x6f\156\x73\x65"); goto GOFZa; JFOFc: N0srD: goto Qx6qV; F9F33: $json = json_decode($data["\163\155\x73\x5f\x62\157\x64\x79"], true); goto Fw3f9; bQ1_0: $smsdid = !empty($mapping["\x73\x6d\x73\144\x69\x64"]) ? $mapping["\x73\x6d\x73\144\x69\144"] : false; goto YKyN6; fAaYG: $resp->appendChild($xml->createElement("\x73\164\x72\x65\141\x6d\x5f\151\144", $smsInfo["\164\x68\x72\145\x61\x64\x69\144"])); goto YDXQo; LL7w9: roEuf: goto egZRK; ytEwV: if (!$request->isGet()) { goto Z132I; } goto qUCt6; BE8FQ: $permissions = $this->FreePBX->Clearlysp->isAllowed($usermanUser["\151\x64"]); goto cdQin; YDXQo: RHP_S: goto UOSRs; eSZLV: $usermanUser = $this->validateUser($data["\143\154\157\165\144\x5f\x75\x73\x65\162\156\141\x6d\x65"], $data["\x63\154\x6f\165\144\x5f\160\141\163\x73\167\x6f\x72\x64"]); goto od9qw; JMCoV: $ret = $xml->saveXML($xml->documentElement); goto Eh1q4; IHOZo: } public function buildRetrievePayload($uid, $since = 0, $json = false) { goto aulYt; pZnS8: $txsms = $xml->createElement("\x73\x65\x6e\x74\137\x73\155\163\163"); goto m5a2w; pOvaa: $xml->formatOutput = true; goto MVIms; m5a2w: $permissions = $this->FreePBX->Clearlysp->isAllowed($uid); goto LcVCW; jqNMi: $xml = simplexml_load_string($ret); goto TPClL; lMTmj: YK5yp: goto X98Ha; dMCb1: uPceM: goto hPt56; BkIta: $response->appendChild($txsms); goto xs4Y8; MVIms: $response = $xml->createElement("\162\145\x73\x70\157\156\x73\145"); goto BT3dq; fB4_Y: $rxsms = $xml->createElement("\162\145\143\145\151\x76\145\144\x5f\163\x6d\x73\163"); goto pZnS8; TFiWH: $xml = new DOMDocument(); goto S4f1R; X98Ha: $response->appendChild($rxsms); goto BkIta; wSBQV: foreach ($allitems as $item) { goto uVyBR; HyHqW: EFKaz: goto PsBlJ; JEJKc: $this->addItem($xml, $txsms, $arr); goto kDTFB; M_nrb: $item["\143\157\x6e\x74\145\156\164\137\164\171\160\x65"] = "\x61\160\160\x6c\x69\143\x61\x74\151\157\x6e\x2f\x78\55\x61\x63\x72\157\x2d\x66\x69\154\x65\x74\x72\141\156\163\146\x65\162\x2b\152\163\x6f\x6e"; goto KxW45; qxYGD: $mItem->setStreamId = $setStreamId; goto natc1; natc1: $arr = $mItem->getMutated(); goto wqehH; LI5YT: l2SsY: goto flEjn; KxW45: ngvy4: goto n1WdU; uVyBR: $mediaBody = $this->getMediaBody($item); goto v_AQT; ARTYi: $item["\x62\x6f\x64\171"] = $mediaBody; goto M_nrb; Wje3h: SpEC0: goto EV4Dz; kDTFB: K3GYu: goto H6nS6; n1WdU: $setStreamId = $this->FreePBX->Clearlysp->getConfig("\x73\x65\164\123\164\162\145\x61\155\111\144"); goto fVrEi; wqehH: if ($item["\144\x69\162\x65\x63\x74\x69\x6f\156"] === "\151\156" && $item["\x74\157"] === $permissions["\x73\x6d\x73\x64\x69\144"]) { goto l2SsY; } goto TuTEI; fVrEi: if (!empty($setStreamId)) { goto EFKaz; } goto BWAt0; BWAt0: $setStreamId = false; goto HyHqW; H6nS6: goto s6TRj; goto LI5YT; flEjn: $this->addItem($xml, $rxsms, $arr); goto DIwIw; DIwIw: s6TRj: goto Wje3h; PsBlJ: $mItem = new Message($item); goto qxYGD; TuTEI: if (!($item["\144\x69\162\145\x63\x74\151\157\x6e"] === "\x6f\x75\164" && $item["\x66\x72\x6f\x6d"] === $permissions["\163\155\x73\x64\151\x64"])) { goto K3GYu; } goto JEJKc; v_AQT: if (!$mediaBody) { goto ngvy4; } goto ARTYi; EV4Dz: } goto lMTmj; LcVCW: $allitems = $this->FreePBX->Clearlysp->getMessagesByUserAndDid($uid, $permissions["\163\x6d\x73\144\x69\144"], $since); goto wSBQV; hPt56: return $ret; goto o3LUh; BT3dq: $response->appendChild($xml->createElement("\x64\141\164\145", $datezulu)); goto fB4_Y; xs4Y8: $xml->appendChild($response); goto TK28z; dhIuo: if (!$json) { goto uPceM; } goto jqNMi; aulYt: $date = new DateTimeImmutable(); goto L0DOL; Yxwx8: $datezulu = $zulu->format("\x59\x2d\x6d\55\144\134\x54\x48\x3a\x69\72\163\x54"); goto TFiWH; TPClL: $ret = json_encode($xml); goto dMCb1; L0DOL: $zulu = $date->setTimeZone(new DateTimeZone("\x5a")); goto Yxwx8; S4f1R: $xml->preserveWhiteSpace = false; goto pOvaa; TK28z: $ret = $xml->saveXML($xml->documentElement); goto dhIuo; o3LUh: } public function addItem($xml, $smss, $data) { goto vXGM1; y37gC: dDPxM: goto dc6Yg; dc6Yg: $smss->appendChild($item); goto FMrkE; vXGM1: $item = $xml->createElement("\x69\164\145\155"); goto Q3yUx; Q3yUx: foreach ($data as $key => $value) { goto YlLFm; RQbx8: CpArc: goto yI2Nu; cIxcP: $item->appendChild($xml->createElement($key, $val)); goto RQbx8; YlLFm: $val = htmlentities($value, ENT_XML1); goto cIxcP; yI2Nu: } goto y37gC; FMrkE: return $this; goto ERcH3; ERcH3: } private function formatNumber($number) { goto PyUgX; PyUgX: if (!(strlen($number) == 10)) { goto QHCHl; } goto xAUQJ; WWg1K: if (!(strpos($number, "\x2b") === 0)) { goto KO8lj; } goto wuCUH; rVqL6: QHCHl: goto WWg1K; wuCUH: $number = substr($number, 1, strlen($number)); goto Gogoo; XDY0q: return $number; goto udu1y; xAUQJ: $number = "\x31" . $number; goto rVqL6; Gogoo: KO8lj: goto XDY0q; udu1y: } public function getMMSClient($replace = false) { goto ydouB; me2KD: return $this->mmsc; goto qcRuF; nzZLC: $this->mmsc = new MMSClient(); goto P2X_p; P2X_p: Y4_fN: goto me2KD; ydouB: if (!(!isset($this->mmsc) || $replace)) { goto Y4_fN; } goto nzZLC; qcRuF: } public function getMediaBody($message) { goto TFfOQ; dZBhL: if (!(empty($filename) || empty($file))) { goto ufoH7; } goto S99KV; PCX2_: $mmmsc = $this->getMMSClient(); goto Y9026; MRS1P: KAzwY: goto oJN1s; V4yn2: if (!is_array($messagecache)) { goto n512m; } goto AO9Rb; YyHy5: file_put_contents($outname, $file); goto creaf; uaLkO: $key = strtoupper(bin2hex($rawkey)); goto UeZzB; Y9026: $varlibdir = $this->FreePBX->Config->get("\101\x53\x54\123\120\x4f\117\114\x44\111\x52"); goto rVo4E; oavF9: if (!empty($media)) { goto Vvx8Y; } goto HROfU; lI1XC: $final["\141\164\x74\x61\143\150\x6d\145\156\164\163"] = array(array("\x63\x6f\156\x74\x65\156\164\55\x74\x79\160\x65" => mime_content_type($outname), "\143\157\x6e\164\145\156\x74\55\x73\151\172\x65" => filesize($outname), "\143\157\156\x74\x65\x6e\164\55\x75\162\154" => $resp["\x75\162\x6c"], "\146\x69\x6c\x65\156\141\x6d\145" => $filename, "\145\156\143\162\171\160\x74\151\x6f\x6e\x2d\x6b\x65\x79" => $key)); goto ZIjB_; creaf: $resp = $mmmsc->checkUpload($outname); goto v6A8R; jLY7u: $final = array("\x62\x6f\x64\x79" => $message["\142\157\144\171"]); goto lI1XC; oGCEn: $key = $mmmsc->pushUpload($outname, $resp["\x75\x72\x6c"], $encrypted, $key); goto jLY7u; UeZzB: @unlink($outname); goto YyHy5; ZzRBE: $filename = ''; goto rMzro; S99KV: return false; goto Kwu94; oRPHY: $rawkey = openssl_random_pseudo_bytes(16); goto uaLkO; rMzro: foreach ($media as $current) { goto bO8aO; ImS30: $filename = $current["\x6c\x69\156\x6b"]; goto bTaWd; h3MKJ: goto OgtG9; goto tjjKe; bO8aO: if ($current["\x74\x79\160\145"] === "\151\x6d\147") { goto akW4a; } goto vRrdT; sJmAq: akW4a: goto D6y9Q; PkX63: goto soOww; goto piQGT; zFJGD: Tgn6v: goto EQcqa; vRrdT: if ($current["\x74\171\160\145"] === "\x62\x69\156") { goto p1ZaF; } goto ulWBW; piQGT: p1ZaF: goto ImS30; OeMR_: goto soOww; goto sJmAq; bTaWd: $file = $current["\144\141\x74\141"]; goto h3MKJ; efXA2: goto OgtG9; goto PkX63; D6y9Q: $filename = $current["\154\151\156\153"]; goto k0sV9; tjjKe: soOww: goto zFJGD; ulWBW: dbug(sprintf("\x47\157\164\x20\x62\x61\x63\153\40\x75\156\x6b\x6e\x6f\167\x6e\x20\146\151\154\145\40\164\171\x70\x65\x20\x6f\x66\x20\x25\163\40\146\157\162\40\x6d\x65\x73\x73\141\x67\x65\40\151\x64\40\x6f\x66\x20\45\x73", $current["\154\x69\x6e\153"], $message["\x69\x64"])); goto OeMR_; k0sV9: $file = $current["\x64\141\164\141"]; goto efXA2; EQcqa: } goto c6Cnk; U8NOE: Vvx8Y: goto ZzRBE; c6Cnk: OgtG9: goto dZBhL; oJN1s: $encrypted = $this->encrypt($outname, $key); goto oGCEn; HROfU: return false; goto U8NOE; v6A8R: if (isset($resp["\165\162\154"])) { goto KAzwY; } goto TO4_A; TO4_A: return false; goto MRS1P; TFfOQ: $messagecache = $this->FreePBX->Clearlysp->getConfig($message["\151\x64"], "\x6d\x65\x73\163\141\x67\145\x63\x61\143\150\145"); goto V4yn2; Kwu94: ufoH7: goto PCX2_; ZwFv9: try { $media = $this->getMedia($message["\151\144"]); } catch (\Exception $e) { dbug("\x45\x78\x63\145\x70\x74\151\x6f\156\x20\x67\x65\164\164\x69\x6e\147\40\155\145\x64\151\x61\x20\x66\157\162\40\x6d\x65\x73\x73\x61\x67\x65\40\151\x64\x20\157\146\40" . $message["\x69\144"], $e->getMessage()); return false; } goto oavF9; ZIjB_: $this->FreePBX->Clearlysp->setConfig($message["\x69\x64"], $final, "\x6d\x65\163\163\x61\147\145\143\x61\143\x68\x65"); goto ZdjvE; AO9Rb: return json_encode($messagecache); goto vQqqR; rVo4E: $outname = $varlibdir . "\57\x74\x6d\x70\x2f" . $filename; goto oRPHY; vQqqR: n512m: goto ZwFv9; ZdjvE: return json_encode($final); goto lkWby; lkWby: } public function encrypt($path, $key) { goto elLHO; iITKq: $this->FreePBX->Clearlysp->setConfig(microtime(true), $tmpname, "\x67\x61\x72\142\x61\x67\x65\143\x6c\145\x61\156\x75\160"); goto BuR7q; GUExh: return false; goto iN24M; qlzi4: if (!($ret !== 0)) { goto ys8yn; } goto SZ8rm; iN24M: ys8yn: goto U2k5u; U2k5u: return $tmpname; goto MplQ_; Vtrob: $tmpname = $varlibdir . "\x2f\x74\155\x70\57" . Uuid::uuid4()->toString(); goto iITKq; BuR7q: $key = escapeshellarg($key); goto Gip8B; Gip8B: $command = sprintf("\157\160\x65\156\x73\x73\154\40\x65\156\143\40\x2d\x61\145\163\x2d\x31\62\70\x2d\x63\x74\x72\x20\40\x2d\x65\40\x20\x2d\x4b\x20\45\x73\x20\40\x2d\x69\x76\40\x30\x30\x30\60\60\x30\x30\60\60\60\x30\x30\x30\60\x30\x30\60\x30\60\x30\x30\x30\60\x30\60\x30\60\60\x30\60\60\x30\x20\55\x6e\x6f\160\x61\144\40\x2d\151\x6e\x20\x25\163\40\55\x6f\x75\x74\40\45\x73", $key, $path, $tmpname); goto axPQm; elLHO: $varlibdir = $this->FreePBX->Config->get("\101\123\124\123\x50\117\117\x4c\x44\x49\122"); goto Vtrob; SZ8rm: dbug("\x65\x6e\143\162\171\160\x74\151\157\x6e\x20\x66\141\151\x6c\165\162\145", $out); goto GUExh; axPQm: exec($command, $out, $ret); goto qlzi4; MplQ_: } public function decrypt($url, $key, $filename, $base64 = false) { goto Fegxv; sbbJa: $this->FreePBX->Clearlysp->setConfig(microtime(true), $tmpname, "\147\x61\162\142\141\147\145\143\154\x65\141\x6e\x75\x70"); goto fXbep; HcuHu: njb5i: goto Nf3Pg; ZThFa: $outname = $varlibdir . "\57\164\155\160\57" . $sanitizedFilename; goto SQwdm; b3729: $sanitizedFilename = $this->sanitizeFilename($filename); goto AEC68; AK24N: return $outname; goto RpRUb; JtUDG: if (!($ret !== 0)) { goto njb5i; } goto rfnF8; SQwdm: $this->FreePBX->Clearlysp->setConfig(microtime(true), $outname, "\147\141\162\x62\141\147\x65\143\x6c\x65\x61\156\x75\160"); goto sbbJa; g1aNw: return base64_encode(file_get_contents($outname)); goto dGwP7; dGwP7: h61D6: goto AK24N; xffBC: $command = sprintf("\x6f\160\x65\x6e\x73\163\154\x20\x65\156\143\x20\x2d\x61\x65\x73\x2d\61\62\x38\55\143\164\x72\x20\x20\x2d\x64\40\40\55\x4b\x20\x25\x73\x20\x20\x2d\x69\x76\40\x30\x30\60\x30\60\x30\x30\x30\60\60\60\60\x30\60\x30\60\x30\x30\x30\60\60\x30\x30\60\60\x30\60\x30\x30\x30\60\x30\40\55\x6e\x6f\160\141\144\40\x2d\x69\156\x20\45\163\x20\55\x6f\165\164\x20\45\x73", $key, $tmpname, $outname); goto Nek4u; fvqZC: return false; goto HcuHu; TUXCz: if (!$base64) { goto h61D6; } goto g1aNw; a0y3l: file_put_contents($tmpname, $data); goto MNn4y; AEC68: $tmpname = $varlibdir . "\57\x74\155\x70\x2f" . Uuid::uuid4()->toString(); goto ZThFa; Fegxv: $varlibdir = $this->FreePBX->Config->get("\101\123\x54\123\120\117\x4f\x4c\x44\x49\122"); goto b3729; Nek4u: exec($command, $out, $ret); goto JtUDG; Nf3Pg: $outname = $this->resizeImage($outname); goto TUXCz; fXbep: try { goto RRLBW; RRLBW: $client = new Client(); goto n75mO; n75mO: $response = $client->get($url); goto V2ZqO; V2ZqO: $data = $response->getBody()->getContents(); goto AYzJQ; AYzJQ: } catch (\Exception $e) { dbug("\125\x6e\141\142\154\145\x20\164\157\40\x67\145\164\40\x6d\x65\144\x69\141\x20\146\162\157\155\40\x75\160\x73\164\x72\145\141\x6d\x2c\40\147\x6f\x74\x20\x65\x72\162\157\162\40\x6f\146\x20", $e->getMessage()); throw $e; } goto a0y3l; MNn4y: $key = escapeshellarg($key); goto xffBC; rfnF8: dbug("\x64\145\x63\x72\171\x70\x74\x69\157\156\x20\x66\141\x69\154\165\x72\145", $out); goto fvqZC; RpRUb: } public function resizeImage($path, $quality = 75) { goto EQmFA; odLb2: $newFilename = sprintf("\x25\x73\57\45\163\56\152\160\x67", $finfo->getPath(), $finfo->getBasename("\x2e" . $extension)); goto RmUDu; hWevr: dUF_i: goto MDpqA; K_S_5: KMmNR: goto h9GgB; t4Lkm: QHq5i: goto Sw2W0; EQmFA: $info = getimagesize($path); goto dvs80; yaE47: return $newFilename; goto K_S_5; eO6fq: xfAVz: goto hWevr; dvs80: $finfo = new SplFileObject($path); goto cI5ET; MDpqA: if (!imagejpeg($image, $newFilename, $quality)) { goto KMmNR; } goto yaE47; w5QIs: if (!($info["\155\151\x6d\145"] == "\x69\x6d\x61\x67\x65\x2f\152\x70\x65\x67" && $filesize < 1000000)) { goto QHq5i; } goto S58V4; cI5ET: $extension = $finfo->getExtension(); goto odLb2; S58V4: return $path; goto t4Lkm; RmUDu: $filesize = $finfo->getSize(); goto w5QIs; Sw2W0: switch ($info["\155\151\x6d\145"]) { case "\x69\x6d\x61\147\145\57\152\x70\145\147": $image = imagecreatefromjpeg($path); goto dUF_i; case "\x69\x6d\x61\x67\145\x2f\147\x69\x66": $image = imagecreatefromgif($path); goto dUF_i; case "\x69\x6d\x61\147\x65\x2f\x70\156\147": $image = imagecreatefrompng($path); goto dUF_i; default: return $path; } goto eO6fq; h9GgB: } public function getMediaById($id) { goto KBKx0; KBKx0: $sql = "\123\x45\x4c\x45\x43\x54\40\52\40\x46\x52\117\x4d\x20\163\x6d\x73\137\x6d\x65\144\151\x61\40\x57\x48\105\122\x45\x20\140\x6d\x69\144\140\x20\75\x20\x3f"; goto EG4Mq; HomFS: $sth->execute(array($id)); goto ubTio; EG4Mq: $sth = $this->FreePBX->database->prepare($sql); goto HomFS; ubTio: return $sth->fetchAll(\PDO::FETCH_ASSOC); goto qwdGm; qwdGm: } public function getMedia($id) { goto iJeeT; ZCrpf: if (!empty($media)) { goto mCnpH; } goto LCMTz; iJeeT: $media = $this->getMediaById($id); goto ZCrpf; o1x67: $files = array(); goto L21f5; Xgylo: foreach ($media as $m) { goto BWvmW; YJGjr: $extension = pathinfo($m["\x6e\141\x6d\x65"], PATHINFO_EXTENSION); goto ZSpN4; FdI7a: $type = "\x69\155\x67"; goto ZJ3EE; ZJ3EE: NDrN_: goto YHGqN; Py8SU: QQNnn: goto gbFW8; YHGqN: $files[$m["\156\x61\155\x65"]] = array("\x74\171\x70\x65" => $type, "\x6c\151\x6e\153" => $m["\156\141\155\x65"], "\144\x61\164\141" => $m["\x72\141\167"]); goto Py8SU; ZSpN4: if (!in_array($extension, $imageFormats)) { goto NDrN_; } goto FdI7a; BWvmW: if (!preg_match("\57\x5e\50\x73\155\151\x6c\134\x2e\174\x2e\x2a\134\x2e\x73\x6d\151\154\x29\x2f", $m["\x6e\x61\x6d\x65"])) { goto lH1hI; } goto tMYMF; tMYMF: goto QQNnn; goto Uhzai; Uhzai: lH1hI: goto A0_EB; A0_EB: $type = "\142\151\156"; goto YJGjr; gbFW8: } goto KPkHG; KPkHG: D5c5L: goto gXxLY; LCMTz: return array(); goto fOkC6; gXxLY: return $files; goto oxn9J; fOkC6: mCnpH: goto o1x67; L21f5: $imageFormats = array("\160\156\x67", "\x6a\x70\147", "\x6a\160\x65\147", "\x67\151\x66", "\164\x69\x66\x66"); goto Xgylo; oxn9J: } private function sanitizeFilename($filename) { $replacedFilename = preg_replace("\x5b\x5e\x5c\167\x5c\x73\134\x64\x5c\x2e\x5c\55\137\176\x2c\x3b\x3a\x5c\133\134\135\x5c\x28\x5c\135\x5d", "\x5f", $filename); return str_replace("\40", "\137", $replacedFilename); } }

デコード(難読化解除)されたコード

<?php

/*   __________________________________________________
    |  Built by Clearly IP Inc.                        |
    |              on 2022-09-26 21:00:24              |
    |__________________________________________________|
*/
namespace FreePBX\modules\Clearlysp\CIP\Controllers\v1;

use DateTimeZone;
use DateTimeImmutable;
use DomDocument;
use FreePBX\modules\Clearlysp\CIP\Models\Message;
use FreePBX\modules\Clearlysp\CIP\Clients\MMSClient;
use Ramsey\Uuid\Uuid;
use SplFileObject;
use FreePBX\modules\Clearlysp\CIP\Controllers\Base;
use GuzzleHttp\Client;
class Sms extends Base
{
    public function fetchMessages($request, $response, $args)
    {
        if (!$request->isPost()) {
            goto FEUvE;
        }
        $data = $request->getParsedBody();
        FEUvE:
        if (!$request->isGet()) {
            goto bH10Q;
        }
        $data = $request->getQueryParams();
        bH10Q:
        $vars = array("cloud_username", "cloud_password");
        foreach ($vars as $var) {
            if (!(!isset($data[$var]) || empty($data[$var]))) {
            }
            return self::returnSMSError($response, _("Invalid request missing " . $var), 400);
        }
        dbug(sprintf("Attempting to fetch messages for %s", $data["cloud_username"]));
        $usermanUser = $this->validateUser($data["cloud_username"], $data["cloud_password"]);
        if ($usermanUser) {
            $permissions = $this->FreePBX->Clearlysp->isAllowed($usermanUser["id"]);
            if (!($permissions["messaging"] !== "enabled")) {
                if (empty($data["device_id"])) {
                    $key = $usermanUser["id"];
                    $id = "lastsmspoll";
                    goto Cwre9;
                }
                $key = $data["device_id"];
                $id = "lastsmspoll_" . $usermanUser["id"];
                Cwre9:
                $since = (int) $this->FreePBX->Clearlysp->getConfig($key, $id);
                if ($since) {
                    goto jINl6;
                }
                $since = 0;
                jINl6:
                $astetcdir = $this->FreePBX->Config->get("ASTETCDIR");
                $clearlySupportDirectory = !empty($astetcdir) ? $astetcdir : "/etc/asterisk";
                $clearlySupportFile = $clearlySupportDirectory . "/clearlysp.support";
                if (!file_exists($clearlySupportFile)) {
                    goto hugQY;
                }
                dbug("support override for fetch messages");
                $timestamp = trim(file_get_contents($clearlySupportFile));
                dbug("timestamp from support override file is", $timestamp);
                if (!($since < $timestamp)) {
                    goto xHmkh;
                }
                $since = $timestamp;
                dbug("overriding since for fetch messages with", $since);
                xHmkh:
                hugQY:
                try {
                    $payload = $this->buildRetrievePayload($usermanUser["id"], $since, false);
                } catch (\Exception $e) {
                    dbug(sprintf("exception trying to get fetch sms for %s since %s", $usermanUser["id"], $since), $e->getMessage());
                    dbug("exception trace from trying to fetch sms is", $e->getTrace());
                }
                $this->FreePBX->Clearlysp->setConfig($key, time(), $id);
                dbug(sprintf("When fetching messages for %s, we returned messages", $data["cloud_username"]));
                return self::returnAsXML($response, $payload);
            }
            dbug(sprintf("When fetching messages for %s, got messages not enabled", $data["cloud_username"]));
            return self::returnError($response, _("Messaging Not Enabled"));
        }
        dbug(sprintf("When fetching messages for %s, got invalid credentials", $data["cloud_username"]));
        return self::returnSMSError($response, _("Invalid credentials"), 403);
    }
    public function sendMessage($request, $response, $args)
    {
        $body = $request->getBody();
        if (!$request->isPost()) {
            goto D3L7F;
        }
        $data = $request->getParsedBody();
        D3L7F:
        if (!$request->isGet()) {
            goto Z132I;
        }
        $data = $request->getQueryParams();
        Z132I:
        $usermanUser = $this->validateUser($data["cloud_username"], $data["cloud_password"]);
        if ($usermanUser) {
            $mapping = $this->FreePBX->Clearlysp->getClientMapping($usermanUser["id"]);
            $permissions = $this->FreePBX->Clearlysp->isAllowed($usermanUser["id"]);
            if (!($permissions["messaging"] !== "enabled")) {
                $smsdid = !empty($mapping["smsdid"]) ? $mapping["smsdid"] : false;
                if (!empty($smsdid)) {
                    $name = !empty($mapping["data"]["fname"]) ? $mapping["data"]["fname"] : $mapping["data"]["username"];
                    $adaptor = $this->FreePBX->Sms->getAdaptor($smsdid);
                    $json = json_decode($data["sms_body"], true);
                    $isjson = json_last_error() === JSON_ERROR_NONE;
                    if ($isjson && !empty($json["attachments"])) {
                        $files = array();
                        foreach ($json["attachments"] as $attachment) {
                            $filename = empty($attachment["filename"]) ? Uuid::uuid4()->toString() : $attachment["filename"];
                            $files[] = $this->decrypt($attachment["content-url"], $attachment["encryption-key"], $filename, false);
                        }
                        try {
                            $ret = $adaptor->sendMedia($this->formatNumber($data["sms_to"]), $this->formatNumber($smsdid), $name, '', $files);
                        } catch (\Exception $e) {
                            dbug("send media error", $e->getMessage());
                            return self::returnSMSError($response, $e->getMessage(), 500);
                        }
                        goto phkZc;
                    }
                    try {
                        $ret = $adaptor->sendMessage($this->formatNumber($data["sms_to"]), $this->formatNumber($smsdid), $name, $data["sms_body"]);
                    } catch (\Exception $e) {
                        dbug("send message error", $e->getMessage());
                    }
                    phkZc:
                    $xml = new DOMDocument();
                    $resp = $xml->createElement("response");
                    $statusCode = 200;
                    if (!empty($ret["message"])) {
                        $statusCode = 400;
                        $resp->appendChild($xml->createElement("message", $ret["message"]));
                        goto PPjjM;
                    }
                    $resp->appendChild($xml->createElement("sms_id", $ret["emid"]));
                    $smsInfo = $this->FreePBX->Sms->getMessageByID($ret["id"]);
                    if (!$smsInfo["threadid"]) {
                        goto RHP_S;
                    }
                    $resp->appendChild($xml->createElement("stream_id", $smsInfo["threadid"]));
                    RHP_S:
                    PPjjM:
                    $xml->appendChild($resp);
                    $ret = $xml->saveXML($xml->documentElement);
                    self::returnAsXML($response, $ret, $statusCode);
                    // [PHPDeobfuscator] Implied return
                    return;
                }
                return self::returnSMSError($response, _("No SMS Capable Numbers are Linked to your User account"));
            }
            return self::returnError($response, _("Messaging Not Enabled"));
        }
        return self::returnSMSError($response, _("Invalid credentials"), 403);
    }
    public function buildRetrievePayload($uid, $since = 0, $json = false)
    {
        $date = new DateTimeImmutable();
        $zulu = $date->setTimeZone(new DateTimeZone("Z"));
        $datezulu = $zulu->format("Y-m-d\\TH:i:sT");
        $xml = new DOMDocument();
        $xml->preserveWhiteSpace = false;
        $xml->formatOutput = true;
        $response = $xml->createElement("response");
        $response->appendChild($xml->createElement("date", $datezulu));
        $rxsms = $xml->createElement("received_smss");
        $txsms = $xml->createElement("sent_smss");
        $permissions = $this->FreePBX->Clearlysp->isAllowed($uid);
        $allitems = $this->FreePBX->Clearlysp->getMessagesByUserAndDid($uid, $permissions["smsdid"], $since);
        foreach ($allitems as $item) {
            $mediaBody = $this->getMediaBody($item);
            if (!$mediaBody) {
                goto ngvy4;
            }
            $item["body"] = $mediaBody;
            $item["content_type"] = "application/x-acro-filetransfer+json";
            ngvy4:
            $setStreamId = $this->FreePBX->Clearlysp->getConfig("setStreamId");
            if (!empty($setStreamId)) {
                goto EFKaz;
            }
            $setStreamId = false;
            EFKaz:
            $mItem = new Message($item);
            $mItem->setStreamId = $setStreamId;
            $arr = $mItem->getMutated();
            if ($item["direction"] === "in" && $item["to"] === $permissions["smsdid"]) {
                $this->addItem($xml, $rxsms, $arr);
                goto DIwIw;
            }
            if (!($item["direction"] === "out" && $item["from"] === $permissions["smsdid"])) {
                goto K3GYu;
            }
            $this->addItem($xml, $txsms, $arr);
            K3GYu:
            DIwIw:
        }
        $response->appendChild($rxsms);
        $response->appendChild($txsms);
        $xml->appendChild($response);
        $ret = $xml->saveXML($xml->documentElement);
        if (!$json) {
            goto uPceM;
        }
        $xml = simplexml_load_string($ret);
        $ret = json_encode($xml);
        uPceM:
        return $ret;
    }
    public function addItem($xml, $smss, $data)
    {
        $item = $xml->createElement("item");
        foreach ($data as $key => $value) {
            $val = htmlentities($value, ENT_XML1);
            $item->appendChild($xml->createElement($key, $val));
        }
        $smss->appendChild($item);
        return $this;
    }
    private function formatNumber($number)
    {
        if (!(strlen($number) == 10)) {
            goto QHCHl;
        }
        $number = "1" . $number;
        QHCHl:
        if (!(strpos($number, "+") === 0)) {
            goto KO8lj;
        }
        $number = substr($number, 1, strlen($number));
        KO8lj:
        return $number;
    }
    public function getMMSClient($replace = false)
    {
        if (!(!isset($this->mmsc) || $replace)) {
            goto Y4_fN;
        }
        $this->mmsc = new MMSClient();
        Y4_fN:
        return $this->mmsc;
    }
    public function getMediaBody($message)
    {
        $messagecache = $this->FreePBX->Clearlysp->getConfig($message["id"], "messagecache");
        if (!is_array($messagecache)) {
            try {
                $media = $this->getMedia($message["id"]);
            } catch (\Exception $e) {
                dbug("Exception getting media for message id of " . $message["id"], $e->getMessage());
                return false;
            }
            if (!empty($media)) {
                $filename = '';
                foreach ($media as $current) {
                    if ($current["type"] === "img") {
                        $filename = $current["link"];
                        $file = $current["data"];
                        goto OgtG9;
                    }
                    if ($current["type"] === "bin") {
                        $filename = $current["link"];
                        $file = $current["data"];
                        goto OgtG9;
                    }
                    dbug(sprintf("Got back unknown file type of %s for message id of %s", $current["link"], $message["id"]));
                    soOww:
                }
                OgtG9:
                if (!(empty($filename) || empty($file))) {
                    $mmmsc = $this->getMMSClient();
                    $varlibdir = $this->FreePBX->Config->get("ASTSPOOLDIR");
                    $outname = $varlibdir . "/tmp/" . $filename;
                    $rawkey = openssl_random_pseudo_bytes(16);
                    $key = strtoupper(bin2hex($rawkey));
                    @unlink($outname);
                    file_put_contents($outname, $file);
                    $resp = $mmmsc->checkUpload($outname);
                    if (isset($resp["url"])) {
                        $encrypted = $this->encrypt($outname, $key);
                        $key = $mmmsc->pushUpload($outname, $resp["url"], $encrypted, $key);
                        $final = array("body" => $message["body"]);
                        $final["attachments"] = array(array("content-type" => mime_content_type($outname), "content-size" => filesize($outname), "content-url" => $resp["url"], "filename" => $filename, "encryption-key" => $key));
                        $this->FreePBX->Clearlysp->setConfig($message["id"], $final, "messagecache");
                        return json_encode($final);
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
        return json_encode($messagecache);
    }
    public function encrypt($path, $key)
    {
        $varlibdir = $this->FreePBX->Config->get("ASTSPOOLDIR");
        $tmpname = $varlibdir . "/tmp/" . Uuid::uuid4()->toString();
        $this->FreePBX->Clearlysp->setConfig(microtime(true), $tmpname, "garbagecleanup");
        $key = escapeshellarg($key);
        $command = sprintf("openssl enc -aes-128-ctr  -e  -K %s  -iv 00000000000000000000000000000000 -nopad -in %s -out %s", $key, $path, $tmpname);
        exec($command, $out, $ret);
        if (!($ret !== 0)) {
            return $tmpname;
        }
        dbug("encryption failure", $out);
        return false;
    }
    public function decrypt($url, $key, $filename, $base64 = false)
    {
        $varlibdir = $this->FreePBX->Config->get("ASTSPOOLDIR");
        $sanitizedFilename = $this->sanitizeFilename($filename);
        $tmpname = $varlibdir . "/tmp/" . Uuid::uuid4()->toString();
        $outname = $varlibdir . "/tmp/" . $sanitizedFilename;
        $this->FreePBX->Clearlysp->setConfig(microtime(true), $outname, "garbagecleanup");
        $this->FreePBX->Clearlysp->setConfig(microtime(true), $tmpname, "garbagecleanup");
        try {
            $client = new Client();
            $response = $client->get($url);
            $data = $response->getBody()->getContents();
        } catch (\Exception $e) {
            dbug("Unable to get media from upstream, got error of ", $e->getMessage());
            throw $e;
        }
        file_put_contents($tmpname, $data);
        $key = escapeshellarg($key);
        $command = sprintf("openssl enc -aes-128-ctr  -d  -K %s  -iv 00000000000000000000000000000000 -nopad -in %s -out %s", $key, $tmpname, $outname);
        exec($command, $out, $ret);
        if (!($ret !== 0)) {
            $outname = $this->resizeImage($outname);
            if (!$base64) {
                return $outname;
            }
            return base64_encode(file_get_contents($outname));
        }
        dbug("decryption failure", $out);
        return false;
    }
    public function resizeImage($path, $quality = 75)
    {
        $info = getimagesize($path);
        $finfo = new SplFileObject($path);
        $extension = $finfo->getExtension();
        $newFilename = sprintf("%s/%s.jpg", $finfo->getPath(), $finfo->getBasename("." . $extension));
        $filesize = $finfo->getSize();
        if (!($info["mime"] == "image/jpeg" && $filesize < 1000000)) {
            switch ($info["mime"]) {
                case "image/jpeg":
                    $image = imagecreatefromjpeg($path);
                    goto dUF_i;
                case "image/gif":
                    $image = imagecreatefromgif($path);
                    goto dUF_i;
                case "image/png":
                    $image = imagecreatefrompng($path);
                    goto dUF_i;
                default:
                    return $path;
            }
            dUF_i:
            if (!imagejpeg($image, $newFilename, $quality)) {
                // [PHPDeobfuscator] Implied return
                return;
            }
            return $newFilename;
        }
        return $path;
    }
    public function getMediaById($id)
    {
        $sql = "SELECT * FROM sms_media WHERE `mid` = ?";
        $sth = $this->FreePBX->database->prepare($sql);
        $sth->execute(array($id));
        return $sth->fetchAll(\PDO::FETCH_ASSOC);
    }
    public function getMedia($id)
    {
        $media = $this->getMediaById($id);
        if (!empty($media)) {
            $files = array();
            $imageFormats = array("png", "jpg", "jpeg", "gif", "tiff");
            foreach ($media as $m) {
                if (!preg_match("/^(smil\\.|.*\\.smil)/", $m["name"])) {
                    $type = "bin";
                    $extension = pathinfo($m["name"], PATHINFO_EXTENSION);
                    if (!in_array($extension, $imageFormats)) {
                        goto NDrN_;
                    }
                    $type = "img";
                    NDrN_:
                    $files[$m["name"]] = array("type" => $type, "link" => $m["name"], "data" => $m["raw"]);
                    goto Py8SU;
                }
                Py8SU:
            }
            return $files;
        }
        return array();
    }
    private function sanitizeFilename($filename)
    {
        $replacedFilename = preg_replace("[^\\w\\s\\d\\.\\-_~,;:\\[\\]\\(\\]]", "_", $filename);
        return str_replace(" ", "_", $replacedFilename);
    }
}


■【無料】ワードプレス:マルウェアスキャン&セキュリティープラグイン [マルウェア・ウィルス検出と駆除]

■WordPress のマルウェア駆除、セキュリティー対策 カスタマイズや修正、引っ越し・復旧のご依頼承ります

(C)2019 ワードプレス ドクター All rights reserved.