Japanese English

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

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

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

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

<?php namespace PHPMailer\PHPMailer; class POP3 { const VERSION = '6.1.4'; const DEFAULT_PORT = 110; const DEFAULT_TIMEOUT = 30; public $do_debug = 0; public $host; public $port; public $tval; public $username; public $password; protected $pop_conn; protected $connected = false; protected $errors...



難読化されたPHPコード

<?php
 namespace PHPMailer\PHPMailer; class POP3 { const VERSION = '6.1.4'; const DEFAULT_PORT = 110; const DEFAULT_TIMEOUT = 30; public $do_debug = 0; public $host; public $port; public $tval; public $username; public $password; protected $pop_conn; protected $connected = false; protected $errors = []; const LE = "\r\n"; public static function popBeforeSmtp( $host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0 ) { $pop = new self(); return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level); } public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0) { $this->host = $host; if (false === $port) { $this->port = static::DEFAULT_PORT; } else { $this->port = (int) $port; } if (false === $timeout) { $this->tval = static::DEFAULT_TIMEOUT; } else { $this->tval = (int) $timeout; } $this->do_debug = $debug_level; $this->username = $username; $this->password = $password; $this->errors = []; $result = $this->connect($this->host, $this->port, $this->tval); if ($result) { $login_result = $this->login($this->username, $this->password); if ($login_result) { $this->disconnect(); return true; } } $this->disconnect(); return false; } public function connect($host, $port = false, $tval = 30) { if ($this->connected) { return true; } set_error_handler([$this, 'catchWarning']); if (false === $port) { $port = static::DEFAULT_PORT; } $this->pop_conn = fsockopen( $host, $port, $errno, $errstr, $tval ); restore_error_handler(); if (false === $this->pop_conn) { $this->setError( "Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr" ); return false; } stream_set_timeout($this->pop_conn, $tval, 0); $pop3_response = $this->getResponse(); if ($this->checkResponse($pop3_response)) { $this->connected = true; return true; } return false; } public function login($username = '', $password = '') { if (!$this->connected) { $this->setError('Not connected to POP3 server'); } if (empty($username)) { $username = $this->username; } if (empty($password)) { $password = $this->password; } $this->sendString("USER $username" . static::LE); $pop3_response = $this->getResponse(); if ($this->checkResponse($pop3_response)) { $this->sendString("PASS $password" . static::LE); $pop3_response = $this->getResponse(); if ($this->checkResponse($pop3_response)) { return true; } } return false; } public function disconnect() { $this->sendString('QUIT'); try { @fclose($this->pop_conn); } catch (Exception $e) { } } protected function getResponse($size = 128) { $response = fgets($this->pop_conn, $size); if ($this->do_debug >= 1) { echo 'Server -> Client: ', $response; } return $response; } protected function sendString($string) { if ($this->pop_conn) { if ($this->do_debug >= 2) { echo 'Client -> Server: ', $string; } return fwrite($this->pop_conn, $string, strlen($string)); } return 0; } protected function checkResponse($string) { if (strpos($string, '+OK') !== 0) { $this->setError("Server reported an error: $string"); return false; } return true; } protected function setError($error) { $this->errors[] = $error; if ($this->do_debug >= 1) { echo '<pre>'; foreach ($this->errors as $e) { print_r($e); } echo '</pre>'; } } public function getErrors() { return $this->errors; } protected function catchWarning($errno, $errstr, $errfile, $errline) { $this->setError( 'Connecting to the POP3 server raised a PHP warning:' . "errno: $errno errstr: $errstr; errfile: $errfile; errline: $errline" ); } }

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

<?php

namespace PHPMailer\PHPMailer;

class POP3
{
    const VERSION = '6.1.4';
    const DEFAULT_PORT = 110;
    const DEFAULT_TIMEOUT = 30;
    public $do_debug = 0;
    public $host;
    public $port;
    public $tval;
    public $username;
    public $password;
    protected $pop_conn;
    protected $connected = false;
    protected $errors = array();
    const LE = "\r\n";
    public static function popBeforeSmtp($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
    {
        $pop = new self();
        return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
    }
    public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
    {
        $this->host = $host;
        if (false === $port) {
            $this->port = static::DEFAULT_PORT;
        } else {
            $this->port = (int) $port;
        }
        if (false === $timeout) {
            $this->tval = static::DEFAULT_TIMEOUT;
        } else {
            $this->tval = (int) $timeout;
        }
        $this->do_debug = $debug_level;
        $this->username = $username;
        $this->password = $password;
        $this->errors = [];
        $result = $this->connect($this->host, $this->port, $this->tval);
        if ($result) {
            $login_result = $this->login($this->username, $this->password);
            if ($login_result) {
                $this->disconnect();
                return true;
            }
        }
        $this->disconnect();
        return false;
    }
    public function connect($host, $port = false, $tval = 30)
    {
        if ($this->connected) {
            return true;
        }
        set_error_handler([$this, 'catchWarning']);
        if (false === $port) {
            $port = static::DEFAULT_PORT;
        }
        $this->pop_conn = fsockopen($host, $port, $errno, $errstr, $tval);
        restore_error_handler();
        if (false === $this->pop_conn) {
            $this->setError("Failed to connect to server {$host} on port {$port}. errno: {$errno}; errstr: {$errstr}");
            return false;
        }
        stream_set_timeout($this->pop_conn, $tval, 0);
        $pop3_response = $this->getResponse();
        if ($this->checkResponse($pop3_response)) {
            $this->connected = true;
            return true;
        }
        return false;
    }
    public function login($username = '', $password = '')
    {
        if (!$this->connected) {
            $this->setError('Not connected to POP3 server');
        }
        if (empty($username)) {
            $username = $this->username;
        }
        if (empty($password)) {
            $password = $this->password;
        }
        $this->sendString("USER {$username}" . static::LE);
        $pop3_response = $this->getResponse();
        if ($this->checkResponse($pop3_response)) {
            $this->sendString("PASS {$password}" . static::LE);
            $pop3_response = $this->getResponse();
            if ($this->checkResponse($pop3_response)) {
                return true;
            }
        }
        return false;
    }
    public function disconnect()
    {
        $this->sendString('QUIT');
        try {
            @fclose($this->pop_conn);
        } catch (Exception $e) {
        }
    }
    protected function getResponse($size = 128)
    {
        $response = fgets($this->pop_conn, $size);
        if ($this->do_debug >= 1) {
            echo 'Server -> Client: ', $response;
        }
        return $response;
    }
    protected function sendString($string)
    {
        if ($this->pop_conn) {
            if ($this->do_debug >= 2) {
                echo 'Client -> Server: ', $string;
            }
            return fwrite($this->pop_conn, $string, strlen($string));
        }
        return 0;
    }
    protected function checkResponse($string)
    {
        if (strpos($string, '+OK') !== 0) {
            $this->setError("Server reported an error: {$string}");
            return false;
        }
        return true;
    }
    protected function setError($error)
    {
        $this->errors[] = $error;
        if ($this->do_debug >= 1) {
            echo '<pre>';
            foreach ($this->errors as $e) {
                print_r($e);
            }
            echo '</pre>';
        }
    }
    public function getErrors()
    {
        return $this->errors;
    }
    protected function catchWarning($errno, $errstr, $errfile, $errline)
    {
        $this->setError('Connecting to the POP3 server raised a PHP warning:' . "errno: {$errno} errstr: {$errstr}; errfile: {$errfile}; errline: {$errline}");
    }
}


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

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

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