Russian Roulette
Last updated
Last updated
Welcome to The Fray. This is a warm-up to test if you have what it takes to tackle the challenges of the realm. Are you brave enough?
First I started the target instance, I got a single target with two open ports. To what services run on these ports, I decided to run an nmap scan on the ports that are given.
From the results of nmap
, we can see that port 33484 is sandbox environment where the contract server is running.
On port 41124, the challenge handler which is a RPC service is running.
First I connected to the challenge handler, to get more information about the contract.
From the challenge handler, I got the following information:
Download the given file and extract it.
This file sets up the contract. To solve this challenge, we have to get the balance of the target wallet to 0. Initially we have around 10 ether we have to bring it to 0 ether.
This is the contract that we have to exploit. The code that we need to exploit is inside the pullTrigger()
function. The selfdestruct()
call will erase the code of the smart contract as well as send the all the ether that is left in the contract to the msg.sender
. You can learn more about the selfdestruct()
function here:
To invoke the selfdestruct()
function, the following condition has to be satisfied:
The above condition basically takes the previous blocks blockhash and converts it to uint256
form, then the resultant value undergoes a modulo 10 operation which should result in the value 7.
The above mentioned condition can be satisfied by calling the pullTrigger()
function repeatedly within a short amount of time, which satisfies the above condition.
For interacting with the contract sandbox running on port 33484 in my case, I used Foundry's cast utility. You can install this utility by refering the following docs:
The syntax for interacting with the sandbox environment is as follows. We are trying to invoke the pullTrigger()
function using the following command.
We can see that the above command executed successfully.
Now its time to call the pullTrigger()
function multiple times in a short amount of time. For that i have created a for loop with bash, to execute the above command multiple times.
After executing the above command, You can get the flag from the RPC service.
Flag: HTB{99%_0f_g4mbl3rs_quit_b4_bigwin}