Ethernaut: Gatekeeper One
My take on CTFs
CTFs constitute a crucial part in the process of becoming a successful security researcher as they require from you an eye for details, a good understanding of solidity and great technical skills to perform the attack and capture the flag. The most talented security researchers are great at CTFs, at solving them of course and sometimes at designing them. CTFs will not turn you into a great web3 security researcher over night, but it will surely arm you with good enough technical skills to be able to write decent coded PoCs to have your finding validated and maybe get selected for report.
What is Ethernaut?
Ethernaut is a CTF(Capture The Flag) developed by the openzeppelin team that you most propbably already heard of. If you haven't, consider taking a look at this roadmap https://www.0xjarix.com/if-i-had-to-start-again/
This CTF gathers 31 challenges for the moment, this number keeps increasing so check their website every now and then: https://ethernaut.openzeppelin.com/
Maybe you'll design your challenge one day and send it to the openzeppelin team.
Also why you here?
Of all the kinds of articles I publish, CTF writeups are those I wish you read the least. I am a big advocate of giving everything the time it needs, if you cannot solve a challenge that you know for a contains an intentional bug in such a small codebase, do not expect to do really well in the contests. There are 2 reasons why someone can fail at solving a challenge, and when I say 'fail' I mean giving up and looking at the writeups, knowing damn well these CTFs are not time-bounded. So if you failed you either:
- aren't ready for this challenge yet and that is most probably due to the fact that you skipped some steps in the roadmap
- are lazy, you read the challenge, read the codebase, maybe not enough times, you had some assumptions maybe, you might have identified some entrypoints or some conditions to bypass or break, but you did not give it enough time, you did not allow yourself to succeed and that's a shame
Gatekeeper One
Make it past the gatekeeper and register as an entrant to pass this level.
Things that might help:
- Remember what you've learned from the Telephone and Token levels.
- You can learn more about the special function
gasleft()
, in Solidity's documentation (see Units and Global Variables and External Function Calls).
Goal
entrant = player
Reasoning
- The 1st modifier can be bypassed by applying what we learnt in the Telephone challenge i.e. creating a contract that we'll call so that it calls the GatekeeperOne contract, that way our address will be tx.origin and the contract we create will be msg.sender
- The 2nd modifier can be bypassed if we send a certain amount of gas such that gasleft() (the remaining gas in the transaction) when this modifier is called is a multiple of 8191 so 8191 * n, it's a CTF challenge we will not waste time trying to find how much gas does the call need to pass the first gate, we will brute force the solution, especially for the gas consumed before gasleft() is called (i)
- The 3rd modifier can be bypassed by choosing a _gatekey such that
- it's 8 bytes long: B8 B7 B6 B5 B4 B3 B2 B1
- B1 B2 == first 2 bytes of tx.origin (3rd require)
- B3 B4 == 0 (1st require)
- B8 B7 B6 B5 != 0 (2nd require)