新しいPHP Pharデシリアライゼーション攻撃がWordpressサイトを脆弱にする

2018.09.18

投稿者 :Justin Brunnette

カテゴリ: IT News

いつもブログ書いているジャスティンです。

Wordpressはネットのほとんどのサイトが使用してるらしいです。このサービスにセキュリティ穴があると大問題になると思います。
元の記事は:
https://thehackernews.com/2018/08/php-deserialization-wordpress.html

[日本語]


新しいPHP Pharデシリアライゼーション攻撃がWordpressサイトを脆弱にする
 
世界中の大企業のデータ侵害やサイバー攻撃のニュースは毎日出ているようです。 多くの攻撃は外国の政府だけでなく、盗賊の小集団やたった一人からの行為です。先月にもオーストラリアの学生さんがAppleのメインフレームにハックし、情報を盗んだケースもあります。 サイバー攻撃は、一般の人があんまり気付いてないみたいですが、パソコンの最新の脆弱性やウィルスを認識するべきだと思います。 PHPの最新の啓示はオブジェクトインジェクションの脆弱性が発見し、WordPressのサイトにリスクがあるのです。
 
Secarmaのセキュリティ研究者のサム・トーマス氏(Sam Thomas)は、PHPストリームラッパーの一種であるPharラッパーを使用する技術が、デシリアライゼーション(deserialization)を引き起こし、Webサーバーを悪意の入力に開放してしまう弱性を発見しました。 ストリームラッパーは、URL型プロトコルのストリームのようにデータを動作させるためにPHPで使用され、ストリームは一連のデータのことです。 ストリームを開くと基本的に機密データにアクセスできるようになります。 ftpの場合はtcpネットワーク接続で、ローカルファイルの場合はファイル記述子です。 リモートファイル包含攻撃の場合、「ftp://」と「http://」がよく使用されます。
 
"phar://"ラッパーの場合は、ローカルドライブ内のファイル、特にpharアーカイブにアクセスすることができます。 このアーカイブはJarアーカイブに似ていますが、PHPコードでメタデータを含む実行可能スタブを含む自己完結型アプリケーションなのです。 pharアーカイブが "fopen"、 "file_exists"、 "file_get_contents"などのファイルファンクションによってアクセスされると、メタデータはデシリアライズされます。
 
攻撃は比較的簡単で、悪意のペイロードを含む有効なPharアーカイブファイルをターゲットファイルシステムにアップロードし、ファイル操作機能を使用して「phar://」のストリームラッパーを使用してアーカイブにアクセスします。 トーマス氏は、この悪用はJPEG画像でも実行される事を証明しました。 最初の100バイトを変更してPharアーカイブをJPEGファイルに変換しましたら可能になります。
 
Wordpressの場合、ハッカーが "file_exists"を呼び出しを使用しますと、パラメータの制御権とアップロード権限を取得してシリアル化を解除することができます。 トーマス氏は、「コアの脆弱性は/wpincludes/post.phpのwp_get_attachment_thumb_file関数内にあります。」
 

 

 

上記のコードの実行と利用についての完全な説明は、Secarmaの報告書のリンクに記載されています。
https://blog.secarma.co.uk/labs/near-phar-dangerous-unserialization-wherever-you-are

この発見はWordPress Securityに報告されましたが、問題は最新のアップデートでは完全に解決されることができませんでした。

[English]


 

New PHP Phar Deserialization Attack Leaves Wordpress Sites Vulnerable

It seems almost every day we are hearing news of data breaches and cyber attacks of major corporations around the world despite their best efforts to keep ahead of the curve. Many times these attacks come not just from foreign governments but from small band of bandits or even single individuals. Just last month, we had the case of Apple’s mainframe hacked by a teenager in Australia. Cyber attacks are far more prevalent than most people realize and it behoves us to keep up to date on the latest vulnerabilities. One of the latest revelations is with PHP through an object injection vulnerability that poses a risk to WordPress websites.
 
Sam Thomas, a security researcher at Secarma, has revealed that a technique of using Phar wrappers, a type of PHP stream wrappers, can trigger a deserialization, leaving the web server open to malicious inputs. Stream wrappers are used in PHP to make data work like a stream in URL type protocols and a stream is no more complicated than a sequence of data. So opening a stream is basically gaining access to theat data. In a case of ftp, it is the tcp network connection and in the case of local files, it is a file descriptor. In the cases of remote file inclusion attacks, the “ftp://” and “http://” are often used.
 
In the case of the “phar://” wrapper, it allows access to files inside of a local drive, specifically phar archives. These archives are similar to Jar archives in which are self-contained applications which includes an executable stub that contains metadata in php code. When a phar archive is accessed by a file operation such as “fopen”, “file_exists” or “file_get_contents”, the metadata becomes deserialized.  
 
The attack is relatively simple, upload a valid Phar archive file that contains malicious payload into the target file system and access the archive through a “phar://” stream wrapper using a file operation function. Mr. Thomas has even shown that the exploit can be done with a JPEG image; a Phar archive converted into a JPEG file by modifying the first 100 bytes.
 
In the case with Wordpress, when a hacker uses the “file_exists” call, they are able to get control of parameters and upload privileges to cause an unserialization. Mr. Thomas describes, “ The core vulnerability is within the wp_get_attachment_thumb_file function in /wpincludes/post.php:”
 

The full explanation of the execution and exploitation of the above code is detailed in Secarma’s report, link provided here: https://blog.secarma.co.uk/labs/near-phar-dangerous-unserialization-wherever-you-are
 
The details of this finding was reported with WordPress Security but the problem was not fully addressed in their newest updates.