题目
看起来像一个论坛,可以注册,登录
详解
我们随便打开一个
尝试注入
并没有发现可以注入
注册发现,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}