Dissecting an Ethereum Honey Pot

Alex Sherbuck
Coinmonks
5 min readFeb 16, 2018

--

Disclaimer: By the end of this article you will have access to code and know how to deploy a honey pot to the Ethereum network. This is not offered in malice but as education. The motivation being the bad actors already know this information and use it. Making the information freely available gives good actors access to this information in hopes it may be mitigated in the future.

I’ve taken time to compile all known Solidity exploits and hacks into a small manual.

I’ll be releasing each article every week for 21+ weeks. Some examples of what I’ll be covering:

  • Re-Entrancy
  • Denial of Service — Gas
  • Denial of Service — Revert
  • Force Ether — selfdestruct
  • Force Ether — Predestination
  • Storage Allocation Exploit
  • Underflow / Overflow
  • Re-Entrancy Honey Pot
  • Function Call Honey Pot

Earlier this week a post on /r/ethdev /u/CurrencyTycoon shared their attempts at exploiting the re-entrancy bug in what they believed at the time was an insecure contract.

Instead they found that the Ether they sent to the contract in order to obtain a balance was locked. They could not withdraw. See if you spot exploit in this honeypot:

It’s really very clever and relies on a few assumptions on the would-be hacker’s part.

The exploit is here:

In the constructor an address is cast to a Log. This is the important part, the Log contract defined in the code is used like an interface for the address. This line of code essentially says “You can call this API at this contract address.”

The assumption is that the provided code is what is run. That’s not true. The contract is free to implement any logic it wants per standard Object Oriented inheritance.

In the Honey Pot’s logger, there is likely a revert or throw when the withdraw is called but the address does not match some allowed value. That is why the re-entrancy attack will successfully execute. However, after the attacker drains the funds, the logger contract code reverts the entire transaction.

BUT! Our would-be attacker has already made their minimum deposit to the contract in order to have some amount to withdraw in the exploit.

So to set this trap the honey pot first deployed the fake logger with the hacker logic. You can view that contract address on Etherscan by looking at the constructor arguments:

Ethereum’s word size is 32 bytes. Address are only 20. That makes our address:

View that on Etherscan

If we take the Honey Pot Logger code and run that through solc we get:

Here is the diff check between the bytecode in the Honey Pot and the code that has actually been deployed on the network.

(Left is the bytecode from above, Right is the main network code)

It contains almost three times as much logic. So what else is going on?

Well, to remain innocuous the contract can’t have any management functionality. Right? So the big question is:

How does the Honey Pot owner get their money out?

Simple, they exploit their contract’s re-entrancy bug! But they’ve essentially made themselves the only address allowed to execute that exploit.

It’s an amazing exploit hiding in plain sight. The attacker immediately assumes their victim does not know the re-entrancy exploit but the Honey Pot owner is literally saying “Oh yes I do.” before the would-be hacker first sees the code.

A full working example of this bug with unit tests exists at the following repo:

https://github.com/tenthirtyone/ethereum_better_honey_pot

In my repo I’ve souped it up a bit:

And here is the trap:

Functionally, it appears to work identical to the Honey Pot code. You can interact with the TrustFund contract and view the history log even.

I’ve even added a whitelist address for withdrawals because, hey, let’s get our friends in on this! If everyone is depositing and it looks like an active contract it’s likely to attract even more attention from thebad guys!

Get Best Software Deals Directly In Your Inbox

Go forth and catch some newbie hackers. Return their Ether after you’ve tasked them with cryptographically verifiable charitable giving with I Gave

--

--