<?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: Edoardo (chap)</title>
    <description>The latest articles on DEV Community by Edoardo (chap) (@edoardopigaiani).</description>
    <link>https://dev.to/edoardopigaiani</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%2F177331%2F24f3a3e6-7501-434c-a700-38e26aa3936b.jpg</url>
      <title>DEV Community: Edoardo (chap)</title>
      <link>https://dev.to/edoardopigaiani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/edoardopigaiani"/>
    <language>en</language>
    <item>
      <title>Snake by Hack the box - My writeup</title>
      <dc:creator>Edoardo (chap)</dc:creator>
      <pubDate>Sat, 08 Jun 2019 06:41:04 +0000</pubDate>
      <link>https://dev.to/edoardopigaiani/htb-s-snake-writeup-12b6</link>
      <guid>https://dev.to/edoardopigaiani/htb-s-snake-writeup-12b6</guid>
      <description>&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;If you're uncomfortable with spoilers stop reading now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenge
&lt;/h2&gt;

&lt;p&gt;While waiting for &lt;a href="https://www.hackthebox.eu/home/machines/profile/188" rel="noopener noreferrer"&gt;SwagShop&lt;/a&gt;'s takedown in order to publish my writeup, I took a chance to solve a couple of challenges available on HackTheBox, starting from Snake.&lt;/p&gt;

&lt;p&gt;Snake is a reversing challenge by 3XPL017, you can find it &lt;a href="https://www.hackthebox.eu/home/challenges/Reversing" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After downloading and unzipping the archive with the password provided we're presented with a Python script named &lt;em&gt;snake.py&lt;/em&gt;, we'll try and run it:&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%2Fimgur.com%2F07fOOYr.png" 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%2Fimgur.com%2F07fOOYr.png" alt="Script running"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After assigning us a random number is asks for a username and a password, we'll dig into that by taking a look at the code.&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%2Fimgur.com%2FrCzLtEc.png" 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%2Fimgur.com%2FrCzLtEc.png" alt="Script code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can notice that there are a lot of variables declared, the one which stands out is &lt;em&gt;slither&lt;/em&gt; since it seems to be the one required in order to be properly identified when prompted for the username.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if user_input == slither:
    pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore we can add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print slither
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to print the variable slither, which is the needed username. The script part will look like this:&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%2Fimgur.com%2FNqVSRMQ.png" 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%2Fimgur.com%2FNqVSRMQ.png" alt="Script code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we run it we get:&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%2Fimgur.com%2FJm9ktZt.png" 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%2Fimgur.com%2FJm9ktZt.png" alt="Script code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, &lt;em&gt;anaconda&lt;/em&gt; makes sense and it is indeed the needed username. &lt;/p&gt;

&lt;p&gt;Let's move on to the password, which is generated by this part of the script:&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%2Fimgur.com%2FPVqFSSa.png" 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%2Fimgur.com%2FPVqFSSa.png" alt="Script code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that &lt;em&gt;passes&lt;/em&gt; is compared to &lt;em&gt;(chr(char))&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;str()&lt;/em&gt; – returns a string&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;chr()&lt;/em&gt; – returns a character, after that takes in a parameter of a unicode digit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;char&lt;/em&gt; – one element in the array chars&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;chars&lt;/em&gt; – initialized as an empty array&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The array chars contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chars = []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for key in keys:
    keys_encrypt = lock ^ key
    chars.append(keys_encrypt)
for chain in chains:
    chains_encrypt = chain + 0xA
    chars.append(chains_encrypt)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is also a &lt;em&gt;break&lt;/em&gt; which terminates the loop even if a single character matches the user given input.&lt;/p&gt;

&lt;p&gt;The simplest way to solve this is to print the characters before being asked for the password, we can do this by modifying the script:&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%2Fimgur.com%2FPhNT3CP.png" 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%2Fimgur.com%2FPhNT3CP.png" alt="Script code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And, if we run it we get:&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%2Fimgur.com%2FcZLmLM2.png" 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%2Fimgur.com%2FcZLmLM2.png" alt="Script code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The password is working, and due to the fact that &lt;em&gt;keys&lt;/em&gt; contains the first 10 characters of the password, we can assume we need to enter them in order to properly solve the challenge.&lt;/p&gt;

&lt;p&gt;The flag format is &lt;em&gt;HTB{user:password}&lt;/em&gt;, so the proper way to enter it is &lt;em&gt;HTB{anaconda:udvvrjwa$$}&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Solved!&lt;/p&gt;

</description>
      <category>hackthebox</category>
    </item>
  </channel>
</rss>
