Cover photo

RingDAO | Sending an arbitrary message without authorization of Dapps. Part-II

Protocol Overview:

RingDAO is a decentralized community focused on the latest innovations in the cross-chain field within the web3 world. Our mission is to empower existing and future applications to interact seamlessly with multiple blockchain networks.

Darwinia chain, is one of the project from RingDAO, It is a one of the earliest parachains in the Polkadot ecosystem, offering out-of-the-box cross-chain capabilities to exchange messages with other parachains and external Ethereum-compatible chains.

I have already found the similar critical bug on Darwinia project, you could read here:

https://mirror.xyz/0xBA23dfd7cCCD3587A1b8909dd5BcCfD92aCeAE6f/ngaKmRBIvhAsycYpXpbycoBuP-W4SbzHAQr6xqZrgEQ

So, this article will be describing Part-II of the Critical bug in RingDAO’s Darwinia contract.

This write-up focuses on vulnerability in the core component of Darwinia which isĀ MsgPort’s ORMPUpgradeablePort contract.

Target

https://etherscan.io/address/0x8d22f03a675064BFd7509c87206d33730f33e324#code

Description:

TheĀ ORMPUpgradeablePortĀ contract is used to do cross-chain messaging by Dapps to theĀ ORMPĀ contract. The flow:

L1 side: 
Dapp --> ORMP_Port::send() --> ORMP::send() 

L2 side:
ORMP::recv() --> ORMP_Port::recv() --> Dapp. 

ORMP_Port == ORMPUpgradeablePort

The bug relies on theĀ ORMPUpgradeablePort::recv()Ā where a malicious user could craft an arbitrary message and pass it toĀ ORMP::send()Ā by settingĀ ORMPĀ asĀ toDapp

The bug lies in theĀ ORMPUpgradeablePort::recv()Ā function where theĀ toDappĀ which is the destination address is not verified. The malicious user could set theĀ toDappĀ as anĀ ORMPĀ contract and pass any arbitrary message on behalf of any genuine Dapps.

    function _recv(bytes32 msgId, uint256 fromChainId, address fromDapp, address toDapp, bytes memory message)
        internal
    {
        (bool success, bytes memory returndata) =
            toDapp.call{value: msg.value}(abi.encodePacked(message, msgId, fromChainId, fromDapp));
        emit MessageRecv(msgId, success, returndata);
    }

Attack Vector II:

  1. As I said before, theĀ MessagePortĀ can callĀ ORMPĀ and misuse theĀ send()Ā function to send arbitrary messages on behalf of Dapps.

  2. But instead of callingĀ ORMP::send(), the attacker could craft a message to callĀ ORMP::setAppConfig().

  3. The attacker could set his own config on behalf of Darwinia MessagePort and change the oracle and relayer addresses of MessagePort.

  4. Hence, this issue has another impact onAttacker ability to set or modify Darwinia Msgport default settings for another UA.

  5. If the attacker could modify UA settings, the attacker could set this own address as a relayer and oracle, potentially call any contract byĀ ORMP:recv()Ā and steal the funds or compromise the UA or MessagePort.

Impact:

PassingĀ toDappĀ asĀ ORMPĀ contract can lead to arbitrary message passing on Behalf of other dapp/user and possibly cause exploits resulting in the permanent locking, loss, or theft of user funds.

Mitigation:

OnĀ ORMPUpgradeablePort::recv()Ā function revert ifĀ toDappĀ is anĀ ORMPĀ contract address.

  function recv(address fromDapp, address toDapp, bytes calldata message) {
            require(toDapp != ormp, "Not allowed");
    }

Proof of Concept

Usually I write Coded POC for all class of bugs, This one I actually left a theoretical POC, because of rush to submit this report to avoid duplicate status for my report.

  1. On the L1 side: The attacker callsĀ MessagePort::send()Ā which contains the custom message to callĀ ORMP::send()Ā on the L2 side.

  2. When the custom messages reachĀ MessagePortĀ on L2. TheĀ MessagePort::recv()Ā will callĀ ORMP::send()Ā with a crafted arbitrary malicious message.

  3. The crafted arbitrary message will pose as a genuine message sent by L2Ā MessagePort. The other encoded parts of this message contain to compromise the genuine Dapps.

  4. Then again, the message will reach L1 where theĀ ORMP::recv() will callĀ Message::recv()` and pass the malicious message to genuine Dapp to compromise Dapp in favour of the attacker.

Thanks for reading my bug write-ups, hope you could learn something.