MevSec writeup Introduction
Introduction
MevSec is a community focused on web3 security. To ensure the people has the require knowledge and permits to have a healthy community, we decided to create a CTF (Capture the Flag). The goal is to flag the challenges on the ctf.mevsec.com to have at least 300 points. Once you get the 300 score points, you can join the community π
Today, we will solve the first challenge together to show you how it works π
The challenge statement is as follows:
Challenge will be solved when there is no funds left inside the wallet. Hope you will join us !
1. Introduction
MevSec is a community focused on web3 security. To ensure the people has the require knowledge and permits to have a healthy community, we decided to create a CTF (Capture the Flag). The goal is to flag the challenges on the ctf.mevsec.com to have at least 300 points. Once you get the 300 score points, you can join the community π
2. Solidity challenge
Today, we will solve the first challenge together to show you how it works.
The challenge statement is as follows:
Challenge will be solved when there is no funds left inside the wallet. Hope you will join us !
First, we need to download the challenge, and open it our favorite text editor.
The setup.sol
is the contract that will initialized the contract (this contract is used by the team to generate the challenge and showing what is necessary to solve the challenge).
|
|
The setup will create the challenge by creating the contract VideoChallengeIntro
in the line:
|
|
If we are looking closely the function isSolved()
This function will return true
, if the balance of the challenge is set to 0.
We can directly see that the goal of the challenge is to empty the balance of contract
VCI
.
Now, the file VideoChallengeIntro.sol
this file contains the contract VideoChallengeIntro
:
|
|
We can clearly see that the function withdraw()
will transfer all the funds (the 100 ether inside in the contract). However, this function is protected by the modifier onlyOwner()
meaning only the owner of the contract can call this function…
Here, this our lucky day because the contract implement a function setOwner()
not protected.. Meaning anyone can call the function and take the owner of the current contract.
So to exploit the contract we can do the following steps:
Become
owner
by calling the functionSetOwner()
.Steal the ALL the ether from the contract by calling the function
withdraw()
.
Now how to do it using the infrastructure of MevSec and flag the challenge?
To start the challenge we need to use curl
:
|
|
Then, we will all the necessary informations to solve the challenge.
Parameters | |
---|---|
RPC link created for the challenges. | http://ctf.mevsec.com:50323/ |
Setup Address contract | The address of the Setup contract, if you need the address of the real challenge contract just check the storage or call the variable vci() (we will do later on this demo) |
Contract Address Ethereum (20 bytes) of the challenger | 0x133756e1688E475c401d1569565e8E16E65B1337 |
Private key of the challenger to sign transaction and discuss with the blockchain | 0xedbc6d1a8360d0c02d4063cdd0a23b55c469c90d3cfbc2c88a015f9dd92d22b3 |
UniqueID The unique instance that will be created for you and will be running for 20 minutes. | d3e87459ba9a4e54b6b74b2946dfb3f133fafdc4dcd715ebd2024642117e076a |
3. Process to flag.
- Using
cast
we can get the contract vci by using theRPC
and theContract Address
using the signaturevci()
.
- Using
cast
we get the balance using the using theRPC
and the address of the challenge.
- Using
cast
we can send a transaction to the address of the challenge and calling the functionsetOwner()
usingRPC
and thePrivate Key
- Using
cast
we can send a transaction to the address of the challenge and calling the functionwithdraw()
usingRPC
and thePrivate Key
- Using the curl on the
curl 'http://5.196.27.132:8080/
we can see all the possible options.
- To flag the challenge because we have call
withdraw()
and we steal all the funds we need to usecurl
with the/get_flag
on ourUniqueID
.
Reminder the instances will be destroy after 20 minutes, donβt hesitate to recreate a instance.
Voila! Now You got the flag! π Now it’s your turn starting to flag challenge the others to join us and also create new challenges for the new comers! π₯
Good luck!
4. Socials.
Discord (Join us!) | Github | |
---|---|---|
https://discord.gg/54Q9pnpQcV | https://github.com/Ethnical/Swek3 | https://twitter.com/EthnicalInfo |