An inconsistency in OperatorFuncNode can be exploited to hide the execution of untrusted operator.xxx methods. This can then be used in a code reuse attack to invoke seemingly safe functions and escalate to arbitrary code execution with minimal and misleading trusted types.
Note: This report focuses on operator.call as it appears to be the most interesting target, but the same technique applies to other operator methods. Moreover, focusing on a specific example is not necessary, the operator.call invocation was a zero-effort choice meant solely to demonstrate the issue. The key point is the inconsistency that allows a user to approve a type as trusted, while in reality enabling the execution of operator.xxx.
The OperatorFuncNode allows calling methods belonging to the operator module and included in a trusted list of methods. However, what is returned by get_untrusted_types and checked during the load call is not exactly the same as what is actually called. Instead, it is something partially controlled by the model author. This means that the user checking the untrusted types can be tricked into thinking something benign is being used, while in reality the operator.xxx method is executed.
Let’s look at the implementation of the OperatorFuncNode:
# from io/_general.py:618-633
class OperatorFuncNode(Node):
def __init__(
self,
state: dict[str, Any],
load_context: LoadContext,
trusted: Optional[Sequence[str]] = None,
) -> None:
super().__init__(state, load_context, trusted)
self.trusted = self._get_trusted(trusted, [])
self.children["attrs"] = get_tree(state["attrs"], load_context, trusted=trusted)
def _construct(self):
op = getattr(operator, self.class_name)
attrs = self.children["attrs"].construct()
return op(*attrs)
As you can see, what is called during construction is operator.class_name, where...
0.10.1.dev00.10.00.11.00.20.3.00.4.00.5.00.6.00.7.0+3 more0.12.0Exploitability
AV:LAC:LAT:PPR:NUI:AVulnerable System
VC:HVI:HVA:HSubsequent System
SC:HSI:HSA:HCVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:A/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H