<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ethereum &#8211; @Forensicxs</title>
	<atom:link href="https://www.forensicxs.com/tag/ethereum/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.forensicxs.com</link>
	<description>Ethical Hacking &#124; Cybersecurity</description>
	<lastBuildDate>Sun, 20 Oct 2024 19:56:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Blockchain hacking : Ethernaut</title>
		<link>https://www.forensicxs.com/blockchain-hacking-ethernaut/</link>
					<comments>https://www.forensicxs.com/blockchain-hacking-ethernaut/#respond</comments>
		
		<dc:creator><![CDATA[Forensicxs]]></dc:creator>
		<pubDate>Sun, 20 Oct 2024 16:19:06 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[blockchain hacking]]></category>
		<category><![CDATA[ethereum]]></category>
		<category><![CDATA[ethernaut]]></category>
		<category><![CDATA[OpenZeppelin]]></category>
		<guid isPermaLink="false">https://www.forensicxs.com/?p=2922</guid>

					<description><![CDATA[In this article, I propose a few solutions to the Ethernaut challenge : https://ethernaut.openzeppelin.com/. I will release more solutions progressively It is an initiative from OpenZeppelin, which is a well known library for secure smart contract development. It proposes Ethereum based, open source challenges, written by several contributors There are already several solutions available. My &#8230; <p class="link-more"><a href="https://www.forensicxs.com/blockchain-hacking-ethernaut/" class="more-link">Continue reading<span class="screen-reader-text"> "Blockchain hacking : Ethernaut"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>In this article, I propose a few solutions to the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Ethernaut</mark></strong> challenge : <a href="https://ethernaut.openzeppelin.com/">https://ethernaut.openzeppelin.com/</a>. I will release more solutions progressively</p>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" width="1024" height="544" src="https://www.forensicxs.com/wp-content/uploads/2024/08/Capture-1-1024x544.jpg" alt="" class="wp-image-3262" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/Capture-1-1024x544.jpg 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/Capture-1-300x160.jpg 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/Capture-1-768x408.jpg 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/Capture-1.jpg 1373w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption class="wp-element-caption">Run the challenge at : <a href="https://ethernaut.openzeppelin.com/">https://ethernaut.openzeppelin.com/</a></figcaption></figure>



<p>It is an initiative from <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">OpenZeppelin</mark></strong>, which is a well known <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">library</mark></strong> for secure smart contract development. It proposes <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Ethereum</mark></strong> based, open source challenges, written by several contributors</p>



<p>There are already several solutions available. My goal in this article is to provide a step by step walkthrough, that should help the most beginners among us. Please note that I have done the challenge using <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Google Chrome</mark></strong></p>



<p>Before starting, it is usefull to have an overview about the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Web3</mark></strong> process, in comparison to the usual Web2, as it will help understand why we use <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Javascript</mark></strong>, <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Metamask</mark></strong>, <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Solidity</mark></strong> and other such features</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="734" height="493" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-8.png" alt="" class="wp-image-2937" style="width:598px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-8.png 734w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-8-300x201.png 300w" sizes="(max-width: 734px) 100vw, 734px" /><figcaption class="wp-element-caption"><a href="https://bit.ly/3PphGCC" target="_blank" rel="noreferrer noopener">https://bit.ly/3PphGCC</a></figcaption></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">Level 0 : Hello Ethernaut</mark></strong></p>



<p>In this chapter, which is an introduction, we will set up MetaMask, get test Ether, and start our first interactions with the smart contract</p>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Set up MetaMask</mark></strong></p>



<p>First of all, we need to install the Metamask browser extension : <a href="https://metamask.io/" target="_blank" rel="noreferrer noopener">https://metamask.io/</a>, and then create a password and a <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">wallet key</mark></strong>. We need to select the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Sepolia test network</mark></strong>, which we will use for our hacking scenarios</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="330" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-87-1024x330.png" alt="" class="wp-image-3263" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-87-1024x330.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-87-300x97.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-87-768x247.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-87.png 1174w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Open the browser&#8217;s console</mark></strong></p>



<p>The modern browsers provide hands-on tools for the web developers, such as the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">console</mark></strong>, in which one can input &#8220;live&#8221; Javascript instructions, check the data in memory, explore available functions and variables</p>



<p>In the Ethernaut browser session, let&#8217;s go in Tools -&gt; Developer tools (or just press F12). In the console view, we find the following informations</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="132" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-89-1024x132.png" alt="" class="wp-image-3265" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-89-1024x132.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-89-300x39.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-89-768x99.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-89.png 1123w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>You may get some errors, so please make sure to solve them before continuing. If needed, you may check the following actions :</p>



<ul class="wp-block-list">
<li>use Chrome</li>



<li>install Metamask after you reached the challenge page</li>



<li>select the Sepolia test network</li>



<li>refresh the page as per the need</li>
</ul>



<p>We get an Ethernaut address : <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">0xa3e7317E591D5A0F1c605be1b3aC4D2ae56104d6</mark></strong></p>



<p>My player number is : <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">0xe62f9927b2198669b5988993E52d3093854898b0</mark></strong>. In fact, this is my Metamask public address</p>



<p>You can check mine here in Etherscan, the well known ethereum blockchain explorer : <a rel="noreferrer noopener" href="https://bit.ly/3aP37JO" target="_blank">https://bit.ly/3aP37JO</a>. It corresponds, in my specific case, to the Ethereum Name Service &#8220;forensicxs.eth&#8221;</p>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">Level 0 : Hello Ethernaut</mark></strong></p>



<p>We click on the level &#8220;00&#8221; box</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="608" height="493" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-90.png" alt="" class="wp-image-3266" style="width:340px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-90.png 608w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-90-300x243.png 300w" sizes="(max-width: 608px) 100vw, 608px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Use the console helpers</mark></strong></p>



<p>We are invited to type the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">help()</mark></strong> command in the console. Here is the output :</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="306" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-91-1024x306.png" alt="" class="wp-image-3267" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-91-1024x306.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-91-300x90.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-91-768x229.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-91.png 1078w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>We can check the balance of our account, with the function <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">getBalance(address)</mark></strong>. We need to input our actual address</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="509" height="83" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-6.png" alt="" class="wp-image-2934" style="width:424px;height:69px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-6.png 509w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-6-300x49.png 300w" sizes="(max-width: 509px) 100vw, 509px" /></figure>



<p>We see that the &#8220;Promise&#8221; has been fulfilled, and that our <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">balance is at zero</mark></strong>, as expected. You can find informations about Promises here : <a rel="noreferrer noopener" href="https://javascript.info/promise-basics" target="_blank">https://javascript.info/promise-basics</a></p>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">The ethernaut contract</mark></strong></p>



<p>Let&#8217;s look into the smart contrat. The <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">ethernaut</mark></strong> command provides a lot of informations about the contract itself</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1021" height="466" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-92.png" alt="" class="wp-image-3269" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-92.png 1021w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-92-300x137.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-92-768x351.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>We can see the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">public methods</mark></strong> available, such as <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">owner</mark></strong></p>



<p>We can see that the smart contract has an abi connector at the following address : <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">0xa3e7317E591D5A0F1c605be1b3aC4D2ae56104d6</mark></strong></p>



<p>The <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">abi, or Application Binary Interface</mark></strong>, gives a contract the ability to communicate and interact with external applications and other smart contracts. Here is the overall mechanism</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="586" height="342" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-9.png" alt="" class="wp-image-2938" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-9.png 586w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-9-300x175.png 300w" sizes="(max-width: 586px) 100vw, 586px" /><figcaption class="wp-element-caption"><a href="https://bit.ly/3zkRymT" target="_blank" rel="noreferrer noopener">https://bit.ly/3zkRymT</a></figcaption></figure>



<p>Here we are more interested in reading contracts FROM the Ethereum blockchain, but you can check the following link to get an overview how to <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">deploy a contrat</mark></strong> TO the blockchain : <a rel="noreferrer noopener" href="https://bit.ly/3OlkD5V" target="_blank">https://bit.ly/3OlkD5V</a></p>



<p>If we try to check the ethernaut owner, the query to the blockchain will need some <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">gas</mark></strong> to be able to run. In my case, the Metamask wallet balance is not sufficient, so I get an error message</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="776" height="322" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-10.png" alt="" class="wp-image-2939" style="width:405px;height:168px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-10.png 776w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-10-300x124.png 300w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-10-768x319.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Get test ether</mark></strong></p>



<p>You can request test Ether with a Google account : <a href="https://tinyurl.com/5xe8r23z">https://tinyurl.com/5xe8r23z</a></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="975" height="415" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-88.png" alt="" class="wp-image-3264" style="width:551px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-88.png 975w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-88-300x128.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-88-768x327.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>This method is limited to 0.05 ETH per day, so it&#8217;s not quite enough to get started with the Ethernaut challenge</p>



<p>You can get more token on <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Alchemy</mark></strong> (requires a login and a small amount of real ETH on your metamask wallet)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="1024" height="529" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-93-1024x529.png" alt="" class="wp-image-3270" style="width:480px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-93-1024x529.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-93-300x155.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-93-768x397.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-93.png 1159w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption class="wp-element-caption"><a href="https://www.alchemy.com/faucets/ethereum-sepolia">https://www.alchemy.com/faucets/ethereum-sepolia</a></figcaption></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Getting a level instance</mark></strong></p>



<p>As indicated by the guide, let&#8217;s request our level instance, by pressing the &#8220;Get new instance&#8221; button. We are prompted by Metamask to authorize the transaction. In my case, the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">gas fee</mark></strong> to pay is 0.0228 Sepolia ETH (= test ETH)</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="338" height="574" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-94.png" alt="" class="wp-image-3271" style="width:282px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-94.png 338w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-94-177x300.png 177w" sizes="(max-width: 338px) 100vw, 338px" /></figure>



<p>The transaction is duly handled, and my instance is created, with a smart contract at the address <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">0x3A99561FA3026041B8647bdae4E7339c2Ebc45E9</mark></strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="189" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-95-1024x189.png" alt="" class="wp-image-3272" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-95-1024x189.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-95-300x55.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-95-768x142.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-95.png 1077w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Inspecting the contract</mark></strong></p>



<p>Let&#8217;s inspect briefly this contract instanciation, using the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract</mark></strong> command</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1024" height="452" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-97.png" alt="" class="wp-image-3275" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-97.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-97-300x132.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-97-768x339.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>We have access to several <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">public functions</mark></strong>, including several ones that look interesting : info, info1, info2, info42, password. Let&#8217;s try to find additional informations about these functions</p>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Interact with the contract to complete the level</mark></strong></p>



<p>In this paragraph, we take advantage of Solidity being an <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">OOP language</mark></strong> (object oriented programming), so that we can get informations about the functions by calling them, with their respective methods and arguments</p>



<p>Let&#8217;s run the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.info()</mark></strong> command. We find a valuable text information &#8220;You will find what you need in info()&#8221;</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="546" height="230" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-21.png" alt="" class="wp-image-2952" style="width:385px;height:162px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-21.png 546w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-21-300x126.png 300w" sizes="(max-width: 546px) 100vw, 546px" /></figure>



<p>We continue with the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.info1()</mark></strong> command. We find another text information &#8220;Try info2(), but with \&#8221;hello\&#8221; as a parameter.&#8221;</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="523" height="229" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-20.png" alt="" class="wp-image-2951" style="width:383px;height:168px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-20.png 523w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-20-300x131.png 300w" sizes="(max-width: 523px) 100vw, 523px" /></figure>



<p>Therefore, we continue with the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.info2(&#8220;hello&#8221;)</mark></strong> command. </p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="693" height="229" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-22.png" alt="" class="wp-image-2953" style="width:475px;height:156px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-22.png 693w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-22-300x99.png 300w" sizes="(max-width: 693px) 100vw, 693px" /></figure>



<p>You get the idea. We have to follow a chain of information&#8230;let&#8217;s continue with the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">infoNum()</mark></strong> method. We see in the PromiseResult, the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">word 42</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="456" height="375" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-23.png" alt="" class="wp-image-2954" style="width:344px;height:283px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-23.png 456w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-23-300x247.png 300w" sizes="(max-width: 456px) 100vw, 456px" /></figure>



<p>Let&#8217;s look for <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.info42()</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="535" height="230" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-24.png" alt="" class="wp-image-2955" style="width:393px;height:169px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-24.png 535w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-24-300x129.png 300w" sizes="(max-width: 535px) 100vw, 535px" /></figure>



<p>We have to look for &#8220;theMethodeName&#8221; as a method</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="506" height="229" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-25.png" alt="" class="wp-image-2956" style="width:403px;height:182px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-25.png 506w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-25-300x136.png 300w" sizes="(max-width: 506px) 100vw, 506px" /></figure>



<p>Let&#8217;s look into <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.method7123949</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="546" height="229" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-26.png" alt="" class="wp-image-2957" style="width:415px;height:174px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-26.png 546w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-26-300x126.png 300w" sizes="(max-width: 546px) 100vw, 546px" /></figure>



<p>We are invited to find the password. We have noticed the function &#8220;password&#8221; in the contract. Let&#8217;s check it in <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.password()</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="446" height="230" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-27.png" alt="" class="wp-image-2958" style="width:371px;height:191px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-27.png 446w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-27-300x155.png 300w" sizes="(max-width: 446px) 100vw, 446px" /></figure>



<p>We get the password &#8220;<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">ethernaut0</mark></strong>&#8220;. Now, we can authenticate. We are prompted to accept the transaction by Metamask, a <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">gas fee</mark></strong> of 0.023 Sepolia ETH is applied</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="326" height="489" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-98.png" alt="" class="wp-image-3276" style="width:240px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-98.png 326w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-98-200x300.png 200w" sizes="(max-width: 326px) 100vw, 326px" /></figure>



<p>The transaction is successfull, we can check it on <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Etherscan</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="985" height="620" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-99.png" alt="" class="wp-image-3277" style="width:566px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-99.png 985w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-99-300x189.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-99-768x483.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>To complete the level, you need to press &#8220;<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">submit instance</mark></strong>&#8220;. Metamask prompts you to accept again the transaction as the blockchain consumes gas for any request</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="337" height="464" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-100.png" alt="" class="wp-image-3278" style="width:263px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-100.png 337w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-100-218x300.png 218w" sizes="(max-width: 337px) 100vw, 337px" /></figure>



<p>Our transaction is approved, we get a very graphic confirmation <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="1024" height="564" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-101-1024x564.png" alt="" class="wp-image-3279" style="width:558px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-101-1024x564.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-101-300x165.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-101-768x423.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-101.png 1062w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>We get a notification on the Ethernaut <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">website</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="766" height="252" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-102.png" alt="" class="wp-image-3280" style="width:521px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-102.png 766w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-102-300x99.png 300w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>Just below, OpenZeppelin provides the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract code</mark></strong> we just interacted with, where we can confirm the steps and logic we just followed above</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="493" height="886" src="https://www.forensicxs.com/wp-content/uploads/2022/07/image-34.png" alt="" class="wp-image-2965" style="width:381px;height:684px" srcset="https://www.forensicxs.com/wp-content/uploads/2022/07/image-34.png 493w, https://www.forensicxs.com/wp-content/uploads/2022/07/image-34-167x300.png 167w" sizes="(max-width: 493px) 100vw, 493px" /></figure>



<p>This level is finished, let&#8217;s move to the next one</p>



<p>From now on, we will come closer to a <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">realistic hacking</mark></strong> environment</p>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">Level 1 : Fallback</mark></strong></p>



<p>We are requested to inpect a smart contract code (here below), take ownership of it, and withdraw the available balance </p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="760" height="716" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-103.png" alt="" class="wp-image-3284" style="width:487px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-103.png 760w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-103-300x283.png 300w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>In Solidity, a <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">fallback</mark></strong> function does not take arguments and does not return any value. But a fallback function can receive ether and therefore be &#8220;payable&#8221;</p>



<p>Let&#8217;s get the instance of the contract by clicking &#8220;Get new instance&#8221;. We need to pay some gas</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="341" height="468" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-104.png" alt="" class="wp-image-3285" style="width:239px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-104.png 341w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-104-219x300.png 219w" sizes="(max-width: 341px) 100vw, 341px" /></figure>



<p>Our instance address is <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">0xB386A21D3aAe67a9dAe0144aF2226b86c8EB6960</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="548" height="44" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-4.png" alt="" class="wp-image-3305" style="width:482px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-4.png 548w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-4-300x24.png 300w" sizes="(max-width: 548px) 100vw, 548px" /></figure>



<p>We can analyse the contract code. The first <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">flaw</mark></strong> is in this code, as anyone can :</p>



<ul class="wp-block-list">
<li>call this function</li>



<li>send Ether</li>



<li>if the contribution gets higher than the one of the contract owner, take ownership of the contract</li>
</ul>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="418" height="137" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-106.png" alt="" class="wp-image-3287" style="width:337px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-106.png 418w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-106-300x98.png 300w" sizes="(max-width: 418px) 100vw, 418px" /></figure>



<p>Then, the &#8220;owner&#8221; can withdraw the funds </p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="395" height="65" src="https://www.forensicxs.com/wp-content/uploads/2024/08/image-107.png" alt="" class="wp-image-3289" style="width:340px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/08/image-107.png 395w, https://www.forensicxs.com/wp-content/uploads/2024/08/image-107-300x49.png 300w" sizes="(max-width: 395px) 100vw, 395px" /></figure>



<p>Therefore, the fallback contract allows users to contribute small amounts of Ether, and the maximum contributor becomes the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">owner</mark></strong> of the contract</p>



<p>But to take ownership of the contract, you would need to get more than 1000 ETH, as per the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">constructor</mark></strong>, because the owner has an initial contribution of 1000 ETH</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="412" height="86" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-6.png" alt="" class="wp-image-3307" style="width:343px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-6.png 412w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-6-300x63.png 300w" sizes="(max-width: 412px) 100vw, 412px" /></figure>



<p>Fortunately for us, there is a second <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">flaw</mark></strong> to take ownership of the contract, whereby any sender can become the owner if :</p>



<ul class="wp-block-list">
<li>he sends a positive value of Ether (<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">msg.value &gt; 0</mark></strong>)</li>



<li>he has already contributed (<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contributions[msg.sender] &gt; 0</mark></strong>)</li>
</ul>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="453" height="85" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-7.png" alt="" class="wp-image-3308" style="width:354px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-7.png 453w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-7-300x56.png 300w" sizes="(max-width: 453px) 100vw, 453px" /></figure>



<p>We can deposit Ether on the contract by using the necessary <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">arguments</mark></strong> of the function <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.contribute()</mark></strong></p>



<p>We have to deposit less than 0.001 ETH, so we can choose 0.0009 ETH, just a decimal below. The help() function provides us some guidance about the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">method</mark></strong> to use, to send our transaction to the contract</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="756" height="21" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-2.png" alt="" class="wp-image-3300" style="width:735px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-2.png 756w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-2-300x8.png 300w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>We also need to send our transaction in <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Wei</mark></strong> (see here a converter, for information -&gt; <a href="https://eth-converter.com/">https://eth-converter.com/</a>), as generally required by smart contracts</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="811" height="22" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-3.png" alt="" class="wp-image-3301" style="width:737px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-3.png 811w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-3-300x8.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-3-768x21.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>So in summary, the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">arguments</mark></strong> to provide to the contract.contribute() function are :</p>



<ul class="wp-block-list">
<li>from : our address is given automatically by our player address </li>



<li>value : the value of our deposit in Wei</li>
</ul>



<p>Here is the full transaction. It gets <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">fullfilled</mark></strong>, after we paid some smart contract gas fee</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="742" height="262" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-1.png" alt="" class="wp-image-3299" style="width:531px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-1.png 742w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-1-300x106.png 300w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>We can check our ether balance with the function <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">getBalance</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="440" height="103" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-5.png" alt="" class="wp-image-3306" style="width:327px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-5.png 440w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-5-300x70.png 300w" sizes="(max-width: 440px) 100vw, 440px" /></figure>



<p>Then, as we have already contributed to the contract, we can take <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">ownership</mark></strong> by sending a positive deposit</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="661" height="187" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-8.png" alt="" class="wp-image-3309" style="width:481px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-8.png 661w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-8-300x85.png 300w" sizes="(max-width: 661px) 100vw, 661px" /></figure>



<p>We can check the contract owner. This is <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">my player</mark></strong> address, so I have claimed ownership</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="570" height="259" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-9.png" alt="" class="wp-image-3310" style="width:402px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-9.png 570w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-9-300x136.png 300w" sizes="(max-width: 570px) 100vw, 570px" /></figure>



<p>Then we can drain the funds with the function <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.withdraw()</mark></strong></p>



<p>We need to press the &#8220;<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">submit instance</mark></strong>&#8221; button to validate this level. We get to this screen, we can press the &#8220;Go to the next level&#8221; button</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="703" height="567" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-10.png" alt="" class="wp-image-3311" style="width:402px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-10.png 703w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-10-300x242.png 300w" sizes="(max-width: 703px) 100vw, 703px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">Level 2 : Fallout</mark></strong></p>



<p>The full smart contract code is below</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="763" height="737" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-14.png" alt="" class="wp-image-3320" style="width:508px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-14.png 763w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-14-300x290.png 300w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>To start with a quick analysis, I notice that the contract owner has a <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">null value</mark></strong>, which is the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">default</mark></strong> address</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="543" height="259" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-11.png" alt="" class="wp-image-3314" style="width:372px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-11.png 543w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-11-300x143.png 300w" sizes="(max-width: 543px) 100vw, 543px" /></figure>



<p>At the same time, this address has a huge amount of <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">ETH</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="497" height="101" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-12.png" alt="" class="wp-image-3316" style="width:374px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-12.png 497w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-12-300x61.png 300w" sizes="(max-width: 497px) 100vw, 497px" /></figure>



<p>I notice also a discrepancy between the contract name <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Fallout</mark></strong> and the constructor <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Fal1out</mark></strong>, which means that the owner is not initiated properly (leading to the owner being the null address)</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="451" height="208" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-13.png" alt="" class="wp-image-3318" style="width:379px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-13.png 451w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-13-300x138.png 300w" sizes="(max-width: 451px) 100vw, 451px" /></figure>



<p>So anyone can claim ownership of the contract. I just call the contract with <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract.Fal1out()</mark></strong> and here we go !</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="522" height="223" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-17.png" alt="" class="wp-image-3326" style="width:388px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-17.png 522w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-17-300x128.png 300w" sizes="(max-width: 522px) 100vw, 522px" /></figure>



<p>We can check that I&#8217;m now the contract owner. The Promise result confirms this is my <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">player</mark></strong> address </p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="581" height="259" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-16.png" alt="" class="wp-image-3325" style="width:457px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-16.png 581w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-16-300x134.png 300w" sizes="(max-width: 581px) 100vw, 581px" /></figure>



<p>I submit the instance. Level is completed</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="671" height="568" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-18.png" alt="" class="wp-image-3327" style="width:460px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-18.png 671w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-18-300x254.png 300w" sizes="(max-width: 671px) 100vw, 671px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">Level 3 : Coin Flip</mark></strong></p>



<p>As per the description, this is a coin flipping game where we need to guess the outcome of a coin flip. To complete the level we need to guess the correct outcome <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">10 times in a row</mark></strong></p>



<p>The full code is provided here below</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="764" height="610" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-19.png" alt="" class="wp-image-3328" style="width:562px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-19.png 764w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-19-300x240.png 300w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>This code leverages the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">randomness of the blockchain&#8217;s state</mark></strong> (specifically, the last block&#8217;s hash of Ethereum) to simulate a coin flip</p>



<p>By dividing a large pseudo-random value (the block hash) by a large constant and interpreting the outcome, the contract creates an <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">unpredictable result</mark></strong> for the two possible outcomes of a coin flip (true or false)</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="348" height="68" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image.png" alt="" class="wp-image-3331" style="width:314px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image.png 348w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-300x59.png 300w" sizes="(max-width: 348px) 100vw, 348px" /></figure>



<p>It is usefull to read this article about <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Ethereum</mark></strong>, and get to understand block <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">number</mark></strong>, block <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">hash</mark></strong> : <a href="https://bit.ly/3U878Mu">https://bit.ly/3U878Mu</a></p>



<p>In the code, <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">blockhash</mark></strong> is a global variable that takes block.number and returns the hash of the given block</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="444" height="46" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-5.png" alt="" class="wp-image-3342" style="width:371px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-5.png 444w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-5-300x31.png 300w" sizes="(max-width: 444px) 100vw, 444px" /></figure>



<p>block.number -1 returns the block number of the previous block, as the current block is <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">not yet mined</mark></strong></p>



<p>On Ethereum, the block hash changes every <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">12 seconds or so</mark></strong>, as shown on this chart</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" width="1024" height="464" src="https://www.forensicxs.com/wp-content/uploads/2024/10/Capture-1024x464.jpg" alt="" class="wp-image-3334" style="width:612px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/Capture-1024x464.jpg 1024w, https://www.forensicxs.com/wp-content/uploads/2024/10/Capture-300x136.jpg 300w, https://www.forensicxs.com/wp-content/uploads/2024/10/Capture-768x348.jpg 768w, https://www.forensicxs.com/wp-content/uploads/2024/10/Capture.jpg 1192w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption class="wp-element-caption"><a href="https://ycharts.com/indicators/ethereum_average_block_time">https://ycharts.com/indicators/ethereum_average_block_time</a></figcaption></figure>



<p>It means that within these 12 seconds, the blockhash <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">will not change</mark></strong> and the coinFlip will not be random at all. So we can somehow repeat the flip without any change to the result. However, there&#8217;s a protection against re-using the same blockhash several times, so we need to find another way</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="264" height="67" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-1.png" alt="" class="wp-image-3336" style="width:210px;height:auto"/></figure>



<p>We need the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">consecutiveWins</mark></strong> to reach 10. At the moment, it is stuck to zero</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="460" height="101" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-2.png" alt="" class="wp-image-3337" style="width:352px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-2.png 460w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-2-300x66.png 300w" sizes="(max-width: 460px) 100vw, 460px" /></figure>



<p>We can perform a <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Coin flip</mark></strong> by first getting the contract address</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="385" height="48" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-15.png" alt="" class="wp-image-3358" style="width:352px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-15.png 385w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-15-300x37.png 300w" sizes="(max-width: 385px) 100vw, 385px" /></figure>



<p>Then we can flip the Coin, but it does not get fulfilled as the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">revert()</mark></strong> function cancels it</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="478" height="246" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-16.png" alt="" class="wp-image-3359" style="width:356px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-16.png 478w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-16-300x154.png 300w" sizes="(max-width: 478px) 100vw, 478px" /></figure>



<p>We can use another contract to hack the CoinFlip code, that we are going to call <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">HackCoinFlip</mark></strong></p>



<p>We can <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">guess</mark></strong> the calculation of the hash of the CoinFlip contract, to generate the random number that we know this function is using. We can &#8220;<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">intercept</mark></strong>&#8221; this result and pass it on to our HackCoinFlip contract. The code of this other contract is below</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="845" height="488" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-6.png" alt="" class="wp-image-3343" style="width:482px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-6.png 845w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-6-300x173.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-6-768x444.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>The contract calls the flip function of the CoinFlip contract with the calculated <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">guess</mark></strong></p>



<p>The <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">constructor</mark></strong> initializes the coinFlipContract instance with the address of the deployed CoinFlip contract, to intercept the result</p>



<p>The CoinFlip contract’s outcome is determined by the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">block hash</mark></strong> of the last block when it is mined. So, by accessing the same block hash used by the CoinFlip, the HackCoinFlip contract can precisely calculate what the coin flip result will be</p>



<p>Because the hash of the last block is used to generate the random outcome and is <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">publicly available</mark></strong> as part of the Ethereum blockchain, this contract can effectively &#8220;guess&#8221; the flip outcome before it happens</p>



<p>We need to deploy our code in our environnement. For that, we are going to use the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Remix IDE</mark></strong> : <a href="https://remix.ethereum.org/">https://remix.ethereum.org/</a></p>



<p>In Remix, we need to copy the code of our two contracts : <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract HackCoinFlip</mark></strong>, <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">contract CoinFlip</mark></strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="591" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-7-1024x591.png" alt="" class="wp-image-3349" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-7-1024x591.png 1024w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-7-300x173.png 300w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-7-768x443.png 768w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-7.png 1530w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>Then we can <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">compile</mark></strong> the code, correct any issues (with the help of the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">built-in AI</mark></strong>)</p>



<p>Afterwards, we deploy the code by selecting the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Metamask environnement</mark></strong> and our <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">instance adress 0x2B483868AD9862d8ab1EdE67BC2f3f4A4962C7f9</mark></strong></p>



<p>First, we deploy the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">HackCoinFlip</mark></strong> contract</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="352" height="719" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-19.png" alt="" class="wp-image-3362" style="width:264px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-19.png 352w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-19-147x300.png 147w" sizes="(max-width: 352px) 100vw, 352px" /></figure>



<p>By pressing the Deploy button, we need to pay some <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">gas in Metamask</mark></strong></p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="428" height="747" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-11.png" alt="" class="wp-image-3353" style="width:264px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-11.png 428w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-11-172x300.png 172w" sizes="(max-width: 428px) 100vw, 428px" /></figure>



<p>Then we deploy the CoinFlip contract (we need to pay gas again)</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="348" height="754" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-18.png" alt="" class="wp-image-3361" style="width:279px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-18.png 348w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-18-138x300.png 138w" sizes="(max-width: 348px) 100vw, 348px" /></figure>



<p>Then we can use our contracts to &#8220;flip and guess&#8221;. At the beginning, <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">ConsecutiveWins</mark></strong> is set to zero</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="287" height="542" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-20.png" alt="" class="wp-image-3363" style="width:230px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-20.png 287w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-20-159x300.png 159w" sizes="(max-width: 287px) 100vw, 287px" /></figure>



<p>We need to execute <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">makeGuess</mark></strong> for 10 times, and check the consecutiveWins counter going to 10</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="289" height="530" src="https://www.forensicxs.com/wp-content/uploads/2024/10/image-21.png" alt="" class="wp-image-3364" style="width:235px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/10/image-21.png 289w, https://www.forensicxs.com/wp-content/uploads/2024/10/image-21-164x300.png 164w" sizes="(max-width: 289px) 100vw, 289px" /></figure>



<p>Then we can press the <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Submit instance</mark></strong> button, and we pass the level</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="671" height="568" src="https://www.forensicxs.com/wp-content/uploads/2024/09/image-18.png" alt="" class="wp-image-3327" style="width:460px;height:auto" srcset="https://www.forensicxs.com/wp-content/uploads/2024/09/image-18.png 671w, https://www.forensicxs.com/wp-content/uploads/2024/09/image-18-300x254.png 300w" sizes="(max-width: 671px) 100vw, 671px" /></figure>



<p><strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">Lessons learned</mark></strong> : this example highlights the importance of proper <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">random number generation</mark></strong> within smart contracts, as relying on block hashes for randomness can be easily exploited. In production, developers should use reliable sources of randomness, such as <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Oracles</mark></strong> or other decentralized solutions (like <strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Chainlink VRF</mark></strong> : <a href="https://chain.link/vrf">https://chain.link/vrf</a>)</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.forensicxs.com/blockchain-hacking-ethernaut/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Database Caching 1/48 queries in 0.041 seconds using Disk

Served from: www.forensicxs.com @ 2026-01-02 09:10:08 by W3 Total Cache
-->