攻防世界web进阶区wtf.sh-150详解

本文详细解析了攻防世界web进阶区wtf.sh-150题目的破解过程,通过代码审计发现源码泄露,利用目录穿越获取flag1,分析replay功能并构造恶意用户名获取flag2。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

攻防世界web进阶区wtf.sh-150详解

题目

在这里插入图片描述
在这里插入图片描述
看起来像一个论坛,可以注册,登录

详解

在这里插入图片描述
我们随便打开一个
尝试注入
在这里插入图片描述
并没有发现可以注入
在这里插入图片描述
注册发现,admin已经存在,
我们看看能不能二次注入
在这里插入图片描述
看来也不行
在这里插入图片描述
正常登录试试看看有没有其他漏洞
在这里插入图片描述
我们发送的时候,看到有个参数,我们试试目录穿越
使用…/

在这里插入图片描述
发现了源码泄露
在这里插入图片描述
发现有一个flag
那么我们代码审计

<html>
<head>
    <link rel="stylesheet" type="text/css" href="/css/std.css" >
</head>
$ if contains 'user' ${!URL_PARAMS[@]} && file_exists "users/${URL_PARAMS['user']}"
$ then
$   local username=$(head -n 1 users/${URL_PARAMS['user']});
$   echo "<h3>${username}'s posts:</h3>";
$   echo "<ol>";
$   get_users_posts "${username}" | while read -r post; do
$       post_slug=$(awk -F/ '{print $2 "#" $3}' <<< "${post}");
$       echo "<li><a href=\"/post.wtf?post=${post_slug}\">$(nth_line 2 "${post}" | htmlentities)</a></li>";
$   done 
$   echo "</ol>";
$   if is_logged_in && [[ "${COOKIES['USERNAME']}" = 'admin' ]] && [[ ${username} = 'admin' ]]
$   then
$       get_flag1
$   fi
$ fi
</html>

在这里插入图片描述
这里写的,如果我们登录时cookies是admin同时username=admin
我们即可获得flag

在这里插入图片描述
我们看到有一些user
同时他是users的目录
我们试试users
看看能不能进行读取
在这里插入图片描述

果然发现了加密信息之类的,我们怀疑他是token
在这里插入图片描述
果然他给我们赋值了,我们正常发东西即可,修改cookie即可
在这里插入图片描述
在返回包中因为有set cookie
所以我们直接修改
在这里插入图片描述
我们在profile处找到了前半个flag
我们继续分析之前泄露的源码
因为整个网站都是wtf的文件,所以我们看看

max_page_include_depth=64
page_include_depth=0
function include_page {
    # include_page pathname
    local pathname=$1
    local cmd=
    [[ ${pathname(-4)} = '.wtf' ]];
    local can_execute=$;
    page_include_depth=$(($page_include_depth+1))
    if [[ $page_include_depth -lt $max_page_include_depth ]]
    then
        local line;
        while read -r line; do
            # check if we're in a script line or not ($ at the beginning implies script line)
            # also, our extension needs to be .wtf
            [[ $ = ${line01} && ${can_execute} = 0 ]];
            is_script=$;
            # execute the line.
            if [[ $is_script = 0 ]]
            then
                cmd+=$'n'${line#$};
            else
                if [[ -n $cmd ]]
                then
                    eval $cmd  log Error during execution of ${cmd};
                    cmd=
                fi
                echo $line
            fi
        done  ${pathname}
    else
        echo pMax include depth exceeded!p
    fi
}


这里有一个replay功能

function reply {
    local post_id=$1;
    local username=$2;
    local text=$3;
    local hashed=$(hash_username "${username}");
    curr_id=$(for d in posts/${post_id}/*; do basename $d; done | sort -n | tail -n 1);
    next_reply_id=$(awk '{print $1+1}' <<< "${curr_id}");
    next_file=(posts/${post_id}/${next_reply_id});
    echo "${username}" > "${next_file}";
    echo "RE: $(nth_line 2 < "posts/${post_id}/1")" >> "${next_file}";
    echo "${text}" >> "${next_file}";
    # add post this is in reply to to posts cache
    echo "${post_id}/${next_reply_id}" >> "users_lookup/${hashed}/posts";
}

这行代码把用户名写在了评论文件的内容中:

echo "${username}" > "${next_file}";

flag2太难搞了,我们只能抄师傅们作业了

如果用户名是一段可执行代码,而且写入的文件是 wtf 格式的,那么这个文件就能够执行我们想要的代码。 (而且wtf.sh只运行文件扩展名为.wtf的脚本和前缀为’$'的行)

${find,/,-iname,get_flag2}
这里前面加个$是wtf文件执行命令的写法
find 所有目录下 不分大小写, get_flag2的名字的文件

在这里插入图片描述
我们首先上传这样一个wtf文件
然后我们进行访问

在这里插入图片描述
%09是水平制表符,必须添加,不然后台会把我们的后门当做目录去解析。
获得 flag2 所在的路径。

继续构造用户名为恶意代码。$/usr/bin/get_flag2 写入后门:

访问后门,得到Flag: 149e5ec49d3c29ca} ļv’ RE: hello

拼接得到xctf{cb49256d1ab48803149e5ec49d3c29ca}

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值