Skip to main content
Rollback to Revision 3 Please don't edit the question to include the answer given and then ask another question :) Use a new question if needed. Previous was meant to rollback to version4, not version5. This version3 is ok too. (comment edited Aug 15, 2016 at 0:00)
Source Link
eth
  • 86.5k
  • 53
  • 287
  • 411

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract B {
    uint public stateVar;
    function foo(Abstract someAddress){
        someAddress.foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foofoobar() {
        Abstract victim =//What Abstract(msg.sender);
do I need to put here to make victim**B.bar(255);** possible?
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call B.foo('maliciousContractAddress');
  • ...

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract B {
    uint public stateVar;
    function foo(Abstract someAddress){
        someAddress.foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foo() {
        Abstract victim = Abstract(msg.sender);
        victim.bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call B.foo('maliciousContractAddress');
  • ...

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract B {
    uint stateVar;
    function foo(Abstract someAddress){
        someAddress.foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract MaliciousContract {
    function foobar() {
        //What do I need to put here to make **B.bar(255)** possible?
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call B.foo('maliciousContractAddress');
  • ...
Rollback to Revision 5. Please don't edit the question to include the answer given and then ask another question :) Use a new question if needed (comment edited Aug 14, 2016 at 23:55)
Source Link
eth
  • 86.5k
  • 53
  • 287
  • 411

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract VictimB {
    uint public stateVar;
    function foo(addressAbstract maliciousContractAddresssomeAddress){
        Abstract(maliciousContractAddress)someAddress.foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foobarfoo() {
        Abstract victim = Abstract(msg.sender);
        victim.bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call VictimB.foo('maliciousContractAddress');
  • ...

EDIT:

I've added missing pieces to the code. Contract B renamed to Victim. Now Victim.foo(maliciousContractAddress) calls the malicous contract which in turn recursively calls function bar on Victim contract. It's supposed to work, but I get out of gas exception for some reason. Why is that?

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract Victim {
    uint public stateVar;
    function foo(address maliciousContractAddress){
        Abstract(maliciousContractAddress).foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foobar() {
        Abstract(msg.sender).bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call Victim.foo('maliciousContractAddress');
  • ...

EDIT:

I've added missing pieces to the code. Contract B renamed to Victim. Now Victim.foo(maliciousContractAddress) calls the malicous contract which in turn recursively calls function bar on Victim contract. It's supposed to work, but I get out of gas exception for some reason. Why is that?

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract B {
    uint public stateVar;
    function foo(Abstract someAddress){
        someAddress.foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foo() {
        Abstract victim = Abstract(msg.sender);
        victim.bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call B.foo('maliciousContractAddress');
  • ...
added 4 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract Victim {
    uint public stateVar;
    function foo(address maliciousContractAddress){
        Abstract(maliciousContractAddress).foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foobar() {
        Abstract(msg.sender).bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call Victim.foo('maliciousContractAddress');
  • ...

EDIT:

I've added missing pieces to the code. Contract B renamed to Victim. Now Victim.foo(maliciousContractAddress) will callcalls the malicous contract which in turn recursively callcalls function bar on Victim contract. It's supposed to work, but I get out of gas exception for some reason. So, it doesn't work. Why Why is that?

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract Victim {
    uint public stateVar;
    function foo(address maliciousContractAddress){
        Abstract(maliciousContractAddress).foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foobar() {
        Abstract(msg.sender).bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call Victim.foo('maliciousContractAddress');
  • ...

EDIT:

I've added missing pieces to the code. Contract B renamed to Victim. Now Victim.foo(maliciousContractAddress) will call the malicous contract which in turn recursively call function bar on Victim contract. It's supposed to work, but I get out of gas exception for some reason. So, it doesn't work. Why is that?

Here's a contract that I want to attack using recursive call:

contract Abstract {
    function foobar();
}

contract Victim {
    uint public stateVar;
    function foo(address maliciousContractAddress){
        Abstract(maliciousContractAddress).foobar();
    }
    function bar(uint x) {
        stateVar = x;
    } 
}

Here's a malicious contract deployed at some other address:

contract Abstract {
    function bar(uint x);
}

contract MaliciousContract {
    function foobar() {
        Abstract(msg.sender).bar(255);
    }
} 

From solidity docs:

Any interaction with another contract imposes a potential danger, especially if the source code of the contract is not known in advance. The current contract hands over control to the called contract and that may potentially do just about anything. Even if the called contract inherits from a known parent contract, the inheriting contract is only required to have a correct interface. The implementation of the contract, however, can be completely arbitrary and thus, pose a danger. In addition, be prepared in case it calls into other contracts of your system or even back into the calling contract before the first call returns. This means that the called contract can change state variables of the calling contract via its functions. Write your functions in a way that, for example, calls to external functions happen after any changes to state variables in your contract so your contract is not vulnerable to a recursive call exploit.

What I'm trying to achieve is:

This means that the called contract can change state variables of the calling contract via its functions.

So, my actions are:

  • I call Victim.foo('maliciousContractAddress');
  • ...

EDIT:

I've added missing pieces to the code. Contract B renamed to Victim. Now Victim.foo(maliciousContractAddress) calls the malicous contract which in turn recursively calls function bar on Victim contract. It's supposed to work, but I get out of gas exception for some reason. Why is that?

added 4 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
deleted 9 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
Grammar; deleted 33 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
added 13 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
added code to my question to make it complete
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
added 70 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
added 7 characters in body
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
edited tags; edited title
Link
eth
  • 86.5k
  • 53
  • 287
  • 411
Loading
Added some info from docs
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading
Source Link
manidos
  • 4.3k
  • 3
  • 31
  • 55
Loading