ctfshow Unzip(2023ciscn国赛)

随便上传一个木马文件

上传后就会跳出源码
**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">finfo_open(FILEINFO_MIME_TYPE);</font>**创建一个**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">finfo</font>**对象,用于获取文件的 MIME 类型。**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">FILEINFO_MIME_TYPE</font>**是一个常量,表示返回文件的 MIME 类型(如**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">text/plain</font>**、**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">application/zip</font>**等)。**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">finfo_file($finfo, $_FILES["file"]["tmp_name"])</font>**用于获取上传文件的 MIME 类型。**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">$_FILES["file"]["tmp_name"]</font>**是 PHP 中用于存储上传文件的临时路径的变量。**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">"file"</font>**是文件上传表单中的字段名。
**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">=== 'application/zip'</font>**检查文件的 MIME 类型是否为**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">application/zip</font>**(即 ZIP 文件)。- 如果条件成立(文件是 ZIP 文件),则执行
**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">if</font>**语句块中的代码。 **<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">unzip -o</font>**是解压 ZIP 文件的命令,**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">-o</font>**表示覆盖已存在的文件而不提示。
综上我们即可得知源码为先检测上传文件的MIME类型,如果是压缩文件就会执行先转移到/tmp目录,然后解压文件(会覆盖已经上传的文件)
由于会转移到/tmp目录,我们直接上传一句话木马的会无法起到控制靶机的效果,有没有什么办法可以使其指向当前网页目录(/var/www/html)呢
这里我想到之前清华的老师给我们上课时讲到的一个软连接的方法,软连接指的就是就是可以将某个目录连接到另一个目录或者文件下,那么我们以后对这个目录的任何操作,都会作用到另一个目录或者文件下。
这样我们就可以得到解题思路,创造一个含有含有指向/var/www/html的压缩包,再创建一个含有一句话木马(link1.zip)的压缩包,先上传含有软连接的压缩包(link.zip),再上传含有木马的压缩包(link1.zip)我们将link.zip 和link1.zip 依次 上传,压缩包会被解压,当我们上传第二个压缩包时会覆盖上一个link目录,但是
link目录软链接指向/var/www/html解压的时候会把shell.php放在/var/www/html下,此时我们就达到了getsehll的目的。

:::info
zip --symlinks,是在zip压缩文件中,包含符号链接
本身,而不是它们指向的实际文件或目录,也就是说当
解压缩这个zip文件,将得到符号链接,而不是它们指向
的实际文件
:::




上传完成以后访问网页url+shell.php,如果页面空白说明上传成功,可以getshell获取flag了

浙公网安备 33010602011771号