{"id":1590,"date":"2024-04-06T14:07:58","date_gmt":"2024-04-06T18:07:58","guid":{"rendered":"https:\/\/www.peteonsoftware.com\/?p=1590"},"modified":"2024-07-22T14:35:31","modified_gmt":"2024-07-22T18:35:31","slug":"vulnhub-walkthrough-the-planets-mercury","status":"publish","type":"post","link":"https:\/\/www.peteonsoftware.com\/index.php\/2024\/04\/06\/vulnhub-walkthrough-the-planets-mercury\/","title":{"rendered":"VulnHub Walkthrough &#8211; The Planets: Mercury"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/planet_mercury.png\" alt=\"An image of the planet Mercury, from Pixabay\" title=\"An image of the planet Mercury, from Pixabay\" style=\"float:left;margin:.5rem;\" \/>In this post, I want to take you through a walkthrough of how to hack your way into an intentionally vulnerable VM provided by <a href=\"https:\/\/www.vulnhub.com\/\">VulnHub<\/a> and created by user <a href=\"https:\/\/www.vulnhub.com\/author\/sirflash,731\/\">SirFlash<\/a>.  You can see more about this exercise and download your own copy of the .ova file to follow along <a href=\"https:\/\/www.vulnhub.com\/entry\/the-planets-mercury,544\/\">here<\/a>.  I&#8217;ve found that the easiest way to run this VM is with <a href=\"https:\/\/www.virtualbox.org\/\">VirtualBox<\/a>, but you do have to do some specific setup\/configuration for the machine to work like we want it to.  Because we can&#8217;t get into the machine, we can&#8217;t really configure very much, so the VirtualBox settings are key.<\/p>\n<p>In addition to VirtualBox, you need a machine to do the penetration test from.  <a href=\"https:\/\/www.kali.org\/\">Kali Linux<\/a> is very popular, though I have worked through several of these kinds of exercises with <a href=\"https:\/\/linuxmint.com\/\">Linux Mint<\/a>.  Kali isn&#8217;t meant to be a &#8220;daily driver&#8221; OS and is just a version of Linux with a lot of tools preinstalled.  You can install your favorite tools yourself on any distro that you&#8217;d like, or even use another preconfigured one (like <a href=\"https:\/\/www.parrotsec.org\/\">Parrot<\/a>, <a href=\"https:\/\/blackarch.org\/\">Black Arch<\/a>, etc).  Many tools are also available on Windows, especially if you have Windows Subsystem for Linux installed and configured.  However, if you are ever working through tutorials, walkthroughs, books, videos, or forums, Linux is almost always assumed.  There are a lot of resources to get started with Linux and it isn&#8217;t nearly as daunting as you&#8217;d think.  <\/p>\n<p>Just as a note, this machine is in a category called &#8220;Capture the Flag&#8221; (CTF).  This is a fun style of game where you can practice certain skills, techniques, and problem solving abilities.  It, however, isn&#8217;t necessarily indicative of &#8220;real world&#8221; penetration tests.  My goal is to talk through my thought process as we walk through so you can see how I&#8217;m using some of the techniques I&#8217;ve learned to operate within the guidelines that CTFs often have.  Feel free to just read this through as information, but it is also very fun and beneficial if you can follow along.<\/p>\n<p>I&#8217;m starting from the assumption that you&#8217;ve already installed VirtualBox, downloaded the Mercury.ova file, and have a machine to attack from.<\/p>\n<h3>Getting Started<\/h3>\n<p>After you download the Mercury.ova file, open VirtualBox.  Click the File menu, and then select Import Appliance<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/virtualbox_file_import_appliance.png\" alt=\"VirtualBox File Import Appliance\" title=\"VirtualBox File Import Appliance\" \/><\/p>\n<p>Next, you will be prompted to locate the file to import.  Make sure your source is &#8220;Local File System&#8221; and then use the file selector to navigate to where you downloaded the .ova file.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/virtualbox_import_step_two.png\" alt=\"VirtualBox File Import Step Two\" title=\"VirtualBox File Import Step Two\" \/><\/p>\n<p>Then, you&#8217;ll be shown a summary of settings.  I was fine with what was here and I clicked Finish.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/virtualbox_import_step_three.png\" alt=\"VirtualBox File Import Step Three\" title=\"VirtualBox File Import Step Three\" \/><\/p>\n<p>It will do its thing and when it is done, you will see the Mercury VM show up in your list of VMs on the left hand side.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/virtualbox_fully_imported.png\" alt=\"VirtualBox Mercury Fully Imported\" title=\"VirtualBox Mercury Fully Imported\" \/><\/p>\n<p>Next, with the virtual machine selected, you&#8217;ll want to click the orange Settings Gear (1), then select the Network menu (2), choose Host-only Adapter from the Attached to: drop down (3), and click OK (4).  This will close the dialog box.  Then click the green Start button (5) to start the VM.  It is possible that you may not have a Host-only Adapter properly configured.  If not &#8211; and because these details have changed in the past &#8211; just work through <a href=\"https:\/\/www.google.com\/search?q=configure+host+only+network+virtualbox\">this Google Search<\/a>.  We&#8217;re doing this as a good way to allow VM to VM communication and that&#8217;s all.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/virtualbox_host_only_adapter.png\" alt=\"Setting the VirtualBox Host Only Adapter\" title=\"Setting the VirtualBox Host Only Adapter\" \/><\/p>\n<p>Once you&#8217;ve hit the play button, the machine will start up and you&#8217;ll see some Linux OS information go by and then the box will finally get to a login prompt.  This means you&#8217;re ready to go.  You can now minimize that window and get ready to work.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_virtual_box_running.png\" alt=\"Mercury VM Login Prompt\" title=\"Mercury VM Login Prompt\" \/><\/p>\n<p>For my environment, I have another VirtualBox VM of Kali that I changed the network adapter to Host Only from its normal NAT setting to do this exercise.  I booted that up and logged in.  The first thing we need to do is make sure we have netdiscover on our box.  Kali is Debian based, so it uses apt to install things by default.  I opened a terminal and I issued the command <em>sudo apt install netdiscover<\/em>.  I had already entered my sudo password before this, so I wasn&#8217;t prompted, but you might be.  I also already had this on my box, so your command window may look differently during and after the install.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/apt_install_netdiscover.png\" alt=\"apt install netdiscover\" title=\"apt install netdiscover\" \/><\/p>\n<p>Then, I ran an <em>ifconfig<\/em> to see what my available network interfaces were.  You can see that I have two network interfaces.  One is called eth0 and the other is lo.  lo is my local loopback interface, so eth0 is the one I want.  Yours may be called something different for many reasons, including how you configured your adapters within VirtualBox.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/kali_ifconfig.png\" alt=\"ifconfig results\" title=\"ifconfig results\" \/><\/p>\n<p>Next, I ran the command <em>sudo netdiscover -i eth0<\/em>.  That brought up an auto-updating table that scanned every possible network address connected through that interface (<em>-i eth0<\/em>).  Our goal here is to find out what IP Address the Mercury VM is at.  If you aren&#8217;t sure, you can scan each one, but in this case, I know it is the one located at 192.168.56.101.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/netdiscover_mercury_box.png\" alt=\"Netdiscover Results\" title=\"Netdiscover Results\" \/><\/p>\n<p>That means that it is now time to scan the box.  This is our first &#8220;this is a CTF, not real life&#8221; warning.  All of the scans I&#8217;m doing here are &#8220;noisy&#8221;.  What that means is that I&#8217;m not sneaking around.  I&#8217;m running these so they take less time from my perspective and are as instrusive as possible.  If I was really doing a penetration test on someone, their monitoring tools would light up.  It would be like a criminal pulling up to your house in a loud truck blaring music and wearing jingle bells as they used a battering ram on your front door.  <\/p>\n<p>Warning aside, I ran <em>nmap -sC -sV -p- -T4 &#8211;min-rate=9326 -vv -oN mercury_nmap.log 192.168.56.101<\/em>.  That command breaks down that I&#8217;m using default scripts (<em>-sC<\/em>) and I&#8217;m going to try to detect versions (<em>-sV<\/em>), I&#8217;m scanning all 65535 ports (<em>-p-<\/em>), I&#8217;m going super fast (<em>-T4<\/em>, where 5 is the highest\/fastest), I&#8217;m going at 9326 packets per second at least (<em>&#8211;min-rate=9326<\/em>), I want the outputs very verbose (<em>-vv<\/em>), I want the output to a file called mercury_nmap.log (<em>-oN mercury_nmap.log<\/em>) and lastly that we&#8217;re going to scan <em>192.168.56.101<\/em>.  Why 9326 packets per second?  No real reason that I&#8217;m aware of except that someone I was learning from used it once, so I do.<\/p>\n<p>That scan returned a lot of results, but the main things we learned from it are:<\/p>\n<pre>\r\nNmap scan report for 192.168.56.101\r\nHost is up, received conn-refused (0.00054s latency).\r\nScanned at 2024-03-22 16:11:14 EDT for 96s\r\nNot shown: 65533 closed tcp ports (conn-refused)\r\nPORT     STATE SERVICE    REASON  VERSION\r\n22\/tcp   open  ssh        syn-ack OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)\r\n8080\/tcp open  http-proxy syn-ack WSGIServer\/0.2 CPython\/3.8.2\r\n<\/pre>\n<p>So this machine exposes a web server and has secure shell (SSH) open.  My next step is also now built on CTF mentality.  I&#8217;m assuming that SSH is mid-game in our chess match.  I figure I&#8217;m supposed to learn something from the web server first that will make the SSH part a little easier.  So, I navigated to http:\/\/192.168.56.101:8080 and got this.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_default_webpage.png\" alt=\"Mercury's Default Webpage\" title=\"Mercury's Default Webpage\" \/><\/p>\n<p>Sometimes, in CTFs, the developers will leave clues in the Source.  In this case, that text is all there is.  It isn&#8217;t even HTML.  So my next step was to use a tool to enumerate the website to try to find directories that aren&#8217;t linked to by just &#8220;guessing&#8221; from curated wordlists and seeing what hits.  In this case, I used the command <em>gobuster dir -w \/usr\/share\/wordlists\/dirb\/common.txt -o mercury_gobuster.log -u http:\/\/192.168.56.101:8080<\/em>.  This just used the gobuster program in directory mode (<em>dir<\/em>) with the wordlist (<em>-w<\/em>) of common possibilities, outputting (<em>-o<\/em>) to a log file against the url (<em>-u<\/em>) of our website.  One of the benefits to using a box made for Offensive Security is that they often come with wordlists like this, though you can find them online, download them, and use them wherever you&#8217;re working from.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/gobuster_command.png\" alt=\"My gobuster results\" title=\"My gobuster results\" \/><\/p>\n<p>Well, the only thing we found is a robots.txt.  Because we didn&#8217;t find anything else, I did try some larger and larger lists, but they also returned only the robots.txt.  I guess that means we should check it out.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/default_mercury_robotstxt.png\" alt=\"Robots.txt Contents\" title=\"Robots.txt Contents\" \/><\/p>\n<p>Wow.  That&#8217;s almost amazing in its uselessness.   Now, we are at another point when I took a shot.  I know a few things.  1) This box is marked as &#8220;Easy&#8221; and 2) This is a CTF.  Some CTFs (especially harder ones) might have an open port with a trail for you to follow and even more work than this all for it to lead to nothing but a waste of time.  But, because this is Easy, I wanted to try to see if causing an error would give us information.  Maybe the error page would give us Server OS info and we could try an exploit, or reveal something else entirely.  So, I navigated to http:\/\/192.168.56.101:8080\/showmea404 in an attempt to see the 404 page.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_404_page.png\" alt=\"The Mercury 404 Page\" title=\"The Mercury 404 Page\" \/><\/p>\n<p>Jackpot.  This server is using Django (useful), but even more useful is that it tried to resolve my URL by checking the index (we know about that), the robots.txt (ditto), and in a directory called mercuryfacts.  Hmmmmm, that sounds promising.  Let&#8217;s navigate to http:\/\/192.168.56.101:8080\/mercuryfacts<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_facts_home.png\" alt=\"The Mercury Facts Home Page\" title=\"The Mercury Facts Home Page\" \/><\/p>\n<p>Here we go!  We can load a fact and we can see their Todo List.  (The Todo List is the sort of thing that is often left in HTML comments in these).  So, I checked the Todo link first and found this<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_facts_todo.png\" alt=\"Mercury Facts Todo\" title=\"Mercury Facts Todo\" \/><\/p>\n<p>Okay, information!  We know there is either a users table that exists or they are using some (probably poor) other means of authentication in the interim.  Also, they are making direct mysql calls (I&#8217;m smelling some possible SQL Injection!).  What about that other link?  I clicked it and it took me to fact 1.  I went back and clicked it again and again and the fact isn&#8217;t random, this is all get and there is no navigation.  So, I started just changing the number.  First I went to 2 and got another fact, then to 999 and got no fact.  Lastly, I tried a fact id of &#8220;pete&#8221; and that got me an error page (see how we love error pages that leak information!?)<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_facts_enumerated.png\" alt=\"Mercury Facts Enumeration\" title=\"Mercury Facts Enumeration\" \/><\/p>\n<p>What we see in that error is that they are just taking the value from the url and just sticking it into a SQL query.  Because we had a word and not a number, mysql thought I was trying to address a column in the where clause.  I don&#8217;t need to go any further, I&#8217;m going to jump right into sqlmap to try to exploit this.  sqlmap is a tool that attempts sql injection several different ways.  When it works, you can dump databases, get table data, and all kinds of good stuff.<\/p>\n<p>The first thing I tested was whether or not this would actually work.  So, I issued the command <em>sqlmap -u &#8220;http:\/\/192.168.56.101:8080\/mercuryfacts\/1&#8221; &#8211;dbms=mysql &#8211;risk=3 &#8211;level=5 &#8211;technique=U<\/em>.  In this case, the <em>-u<\/em> is our URL, the <em>&#8211;dbms<\/em> is telling it which database product to try to hit.  We know mysql from the todos, but sqlmap can also guess if you don&#8217;t provide that.  The risk and level values are just about the noise we&#8217;re willing to make and how hard we want the tool to try.  Lastly, the <em>&#8211;technique=U<\/em> is telling it to do SQL UNIONS in an attempt to exfiltrate the data.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_facts_sqlmap_initial.png\" alt=\"sqlmap initial results\" title=\"sqlmap initial results\" \/><\/p>\n<p>We see that this comes back and the parameter is injectable.  This means we can try something else.  In this case, I issued the command <em>sqlmap -u http:\/\/192.168.56.101:8080\/mercuryfacts\/1 &#8211;dbms=mysql &#8211;risk=3 &#8211;level=5 &#8211;technique=U &#8211;tables<\/em>.  That&#8217;s very similar except that I added <em>&#8211;tables<\/em> so it would dump the tables.  We got this<\/p>\n<pre>\r\nsqlmap identified the following injection point(s) with a total of 119 HTTP(s) requests:\r\n---\r\nParameter: #1* (URI)\r\n    Type: UNION query\r\n    Title: Generic UNION query (NULL) - 1 column\r\n    Payload: http:\/\/192.168.56.101:8080\/mercuryfacts\/1 UNION ALL SELECT CONCAT(0x7178717071,0x53574a6856587464485476465941597769575a5a41555270716d78656c466949645264726352434f,0x71766b7171)-- -\r\n---\r\nback-end DBMS: MySQL >= 8.0.0\r\nsqlmap resumed the following injection point(s) from stored session:\r\n---\r\nParameter: #1* (URI)\r\n    Type: UNION query\r\n    Title: Generic UNION query (NULL) - 1 column\r\n    Payload: http:\/\/192.168.56.101:8080\/mercuryfacts\/1 UNION ALL SELECT CONCAT(0x7178717071,0x53574a6856587464485476465941597769575a5a41555270716d78656c466949645264726352434f,0x71766b7171)-- -\r\n---\r\nback-end DBMS: MySQL >= 8.0.0\r\nDatabase: information_schema\r\n[78 tables]\r\n+---------------------------------------+\r\n| ADMINISTRABLE_ROLE_AUTHORIZATIONS     |\r\n| APPLICABLE_ROLES                      |\r\n| CHARACTER_SETS                        |\r\n              -- SNIP -- \r\n| PROCESSLIST                           |\r\n| TABLES                                |\r\n| TRIGGERS                              |\r\n+---------------------------------------+\r\n\r\nDatabase: mercury\r\n[2 tables]\r\n+---------------------------------------+\r\n| facts                                 |\r\n| users                                 |\r\n+---------------------------------------+\r\n<\/pre>\n<p>Okay, the first information_schema db is just something that is a feature of the dbms.  I &#8211;SNIP&#8211;&#8216;ed a lot of that out of there so you could see it, but let&#8217;s not have it clog us up.  We care about the mercury db and its two tables: facts and users.  If we remember, the Todo list wanted to start using the users table, so we&#8217;re very interested.  Let&#8217;s dump it.  <em>sqlmap -u http:\/\/192.168.56.101:8080\/mercuryfacts\/1 &#8211;dbms=mysql -D mercury -T users &#8211;dump &#8211;batch &#8211;technique=U &#8211;level=5 &#8211;risk=3<\/em>.  Our only change this time is to remove the request to list the tables and instead specify the database name (<em>-D mercury<\/em>) and the table name (<em>-T users<\/em>) and tell it to <em>&#8211;dump<\/em> it in a <em>&#8211;batch<\/em>.<\/p>\n<pre>\r\nsqlmap identified the following injection point(s) with a total of 49 HTTP(s) requests:\r\n---\r\nParameter: #1* (URI)\r\n    Type: UNION query\r\n    Title: Generic UNION query (NULL) - 1 column\r\n    Payload: http:\/\/192.168.56.101:8080\/mercuryfacts\/1 UNION ALL SELECT CONCAT(0x7162707a71,0x71554a4b637448434261574e63514344716a56734371626a667a586a62507555586a635a4b717549,0x7176786a71)-- -\r\n---\r\nback-end DBMS: MySQL >= 8.0.0\r\nDatabase: mercury\r\nTable: users\r\n[4 entries]\r\n+----+-------------------------------+-----------+\r\n| id | password                      | username  |\r\n+----+-------------------------------+-----------+\r\n| 1  | johnny1987                    | john      |\r\n| 2  | lovemykids111                 | laura     |\r\n| 3  | lovemybeer111                 | sam       |\r\n| 4  | mercuryisthesizeof0.056Earths | webmaster |\r\n+----+-------------------------------+-----------+\r\n<\/pre>\n<p>Here we go!  We have some usernames and plain text passwords.  Now we can try to see what that SSH has got going on!  Incidentally, if you examine the results of these scans, it took the tool 119 requests to dump the databases and tables and 49 requests to just get these 4 rows of one table.  See what I mean about noisy?<\/p>\n<p>Let&#8217;s use the webmaster account to get into the box.  It seems like the ranking account.  In addition, it has the best password, so I&#8217;m guessing it has the juicy stuff.  So now we issue the command <em>ssh webmaster@192.168.56.101<\/em> and then hit enter.  Enter the password and accept the fingerprint as you&#8217;re asked and we&#8217;re in.  The first thing I did was an <em>ls<\/em> to list the contents of the directory and there is a user_flag.txt right there.  I issued a <em>cat user_flag.txt<\/em> command and we have our user flag!<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/ssh_into_mercury.png\" alt=\"SSH into Mercury\" title=\"SSH into Mercury\" \/><\/p>\n<p>The thing about CTF boxes is that there is often a User flag and then a Root (or Admin) flag.  We&#8217;re only half done.  Might as well keep exploring.  What&#8217;s in this mercury_proj directory?  To find out, I typed <em>cd mercury_proj\/ &#038;&#038; ls<\/em> and saw a notes.txt file.  I called <em>cat notes.txt<\/em> and got 2 users and 2 passwords of some sort.  So, we know the webmaster password, so if we can work out the encoding or hashing, we might have a shot.  At a minimum, this looks like Base64 encoding (the == padding at the end of the linuxmaster user&#8217;s password is often a giveaway as = is used as padding in base64).  But just because it is base64 doesn&#8217;t mean that&#8217;s the answer, encryption will often use base64 as the final step so all of the characters are printable.  But, I use the echo command to echo each value and then pipe (|) it into the <em>base64<\/em> utility, asking it to <em>&#8211;decode<\/em>.  We see that the webmaster password is the one we know, so we can trust that this linuxmaster password is probably their password value.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_uncover_other_password.png\" alt=\"Base64 Encoded Passwords\" title=\"Base64 Encoded Passwords\" \/><\/p>\n<p>We can check that immediately by calling <em>su linuxmaster<\/em> and providing that password.  It is accepted and a <em>whoami<\/em> tells me that I&#8217;m now linuxmaster.  Is this over now?  Is it this easy?  We wish!  I dug around but didn&#8217;t find any other flags, so I&#8217;ll spare you those searches.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_become_linuxmaster.png\" alt=\"Changing to Linuxmaster user\" title=\"Changing to Linuxmaster user\" \/><\/p>\n<p>That means that our next step is likely privilege escalation.  There are a few ways to go, but one of the easiest is to look and see what applications that the user might be able to call <em>sudo<\/em> on and act as root.  Issuing the command <em>sudo -l<\/em> will tell you just that.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_linuxmaster_sudo_permissions.png\" alt=\"Finding Linuxmaster sudo Permissions\" title=\"Finding Linuxmaster sudo Permissions\" \/><\/p>\n<p>Okay, so we can run a specific bash script as sudo.  Oh, that&#8217;s good news.  Sometimes, we can edit what&#8217;s in the file and just do whatever we want.  Other times, we can take advantage of what&#8217;s in the file and take advantage of the command another way.  Let&#8217;s see what we&#8217;ve got.  In the image above, you can see that I followed that up with <em>cat \/usr\/bin\/check_syslog.sh<\/em> to see what&#8217;s in the file.  It just calls the Linux <em>tail<\/em> program to get the last 10 lines out of the <em>\/var\/log\/syslog<\/em> file.  This is actually a common kind of misconfiguration.  The \/var\/log\/syslog file needs elevated permissions or at least very specific permissions in order to read it.  Instead of creating a group and giving that group permission to the file or using access control lists (ACLs), the admin figured he could give this user (and perhaps others) sudo permission on this script that only did one simple thing.  But, they weren&#8217;t expecting this.<\/p>\n<p>Linux (as well as many operating systems) store files in directory structures.  The correct way to call every single program is to give its full path every time.  We don&#8217;t do that.  We just want to type <em>ls<\/em> or <em>cat<\/em>, not <em>\/bin\/ls<\/em> and <em>\/bin\/cat<\/em> or <em>\/usr\/bin\/ls<\/em> and <em>\/usr\/bin\/cat<\/em>.  That&#8217;s where the path variable comes in.  It defines a bunch of places\/directories (in order) that the operating system is going to look for the thing you asked for.  We can see what that should have been above.  When using sudo, it is supposed to ignore your normal PATH and use the secure_path, which in this case for this user was declared as \/usr\/local\/sbin, \/usr\/local\/bin, \/usr\/sbin, \/usr\/bin, \/sbin, \/bin, and \/snap\/bin.  <\/p>\n<p>We&#8217;re going to take advantage of this because you also see that we have the <em>env_reset<\/em> permission when using sudo.  That lets us CHANGE where all it is willing to look for commands.  So, what we&#8217;re going to do is create a symlink (think shortcut, of sorts) in our current directory called tail that actually points to \/bin\/vi.  That means whenever the current directory is in the path and someone calls <em>tail<\/em>, <em>vi<\/em> will run instead.  Some of you who are familiar with vi or vim will know that it can basically run like its own little operating system.  So, if I can run get this bash script to run as sudo and then open vi, I can then do things within vi as root.  Here are the steps:<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_privesc.png\" alt=\"We actually take advantage of the flaw\" title=\"We actually take advantage of the flaw\" \/><\/p>\n<p>In this case, the first thing I do is make sure I&#8217;m in my home directory, somewhere I have full permissions, just in case (<em>cd ~<\/em>).  Then I create a symlink (<em>ln -s<\/em>) pointing to <em>\/bin\/vi<\/em> whenever someone calls the command <em>tail<\/em> (which is called from within that script).  So, I update my own PATH variable to be my current directory plus the existing path variable.  <em>export PATH<\/em> means I&#8217;m making that environment variable, the equals sign means I&#8217;m assigning whatever is on the right hand side to the variable. The <em>.<\/em> is my current directory (where I put the symlink), the <em>:<\/em> is concatenating these values, and <em>$PATH<\/em> is the current PATH environment variable.  So in one sentence, I updated my local PATH environment variable to include what it already had, but putting my current directory in first position so it is checked for a command match there first.<\/p>\n<p>The next line is me doing a typo, you can ignore it.  I left it in to show that I&#8217;m human, too \ud83d\ude09  But the right version of the command says <em>sudo &#8211;preserve-env=PATH \/usr\/bin\/check_syslog.sh<\/em>.  I&#8217;m calling for the elevated permissions, but then I&#8217;m using &#8211;preserve-env (because we have the <em>env_reset<\/em> permission) to use my new PATH environment variable (which includes my local directory) instead of the one carefully defined for me in secure_path.  When I hit enter, vi automatically opens.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_launch_vim.png\" alt=\"Our VI Window\" title=\"Our VI Window\" \/><\/p>\n<p>If I type <em>:<\/em>, I&#8217;m automatically popped into command mode and typing <em>shell<\/em> and hitting enter opens a shell in my current context, which thanks to the sudo call on the check_syslog.sh file, is root.  You can see here that I type <em>whoami<\/em> and I&#8217;m told that I&#8217;m root.  I issued a <em>cd ~ &#038;&#038; ls<\/em> command to change into root&#8217;s home directory and list out its contents.  I see that there is a root_flag.txt file and a quick <em>cat root_flag.txt<\/em> and we can see that file&#8217;s contents.<br \/>\n<img decoding=\"async\" src=\"https:\/\/peteonsoftware.com\/images\/202404\/mercury_root.png\" alt=\"We are root and showing the root flag\" title=\"We are root and showing the root flag\" \/><\/p>\n<p>That&#8217;s it.  In doing this box, we used the following skills:<\/p>\n<ul>\n<li>nmap scan<\/li>\n<li>gobuster scan (directory enumeration)<\/li>\n<li>Found Error Page misconfiguration<\/li>\n<li>Detected and exploited SQLi (SQL Injection)<\/li>\n<li>Luck (found additional credentials)<\/li>\n<li>symlinks<\/li>\n<li>Misconfigured permissions, specifically around sudo and the secure_path variable<\/li>\n<\/ul>\n<p>Not bad for a day&#8217;s work!  Next time, I&#8217;ll take off a Red Team hat and put on a Blue Team hat and explain how the Administrators could have better protected this file and the sudo permissions (if they used them anyway).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I want to take you through a walkthrough of how to hack your way into an intentionally vulnerable VM provided by VulnHub and created by user SirFlash. You can see more about &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[142,149,150,134],"class_list":["post-1590","post","type-post","status-publish","format-standard","hentry","category-capture-the-flag","tag-infosec","tag-offensive-security","tag-penetration-testing","tag-security"],"_links":{"self":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/1590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/comments?post=1590"}],"version-history":[{"count":0,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/posts\/1590\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/media?parent=1590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/categories?post=1590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peteonsoftware.com\/index.php\/wp-json\/wp\/v2\/tags?post=1590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}