🪄HTB Walkthrough – making a magical walkthrough with Magic

🧠 TL;DR

  • SQLi login bypass

  • Upload bypass via magic bytes

  • Reverse shell via Python

  • Credentials leakage → Privilege escalation

  • .htaccess blocks direct access to malicious files

  • Custom binary sysinfo used for final foothold


🧩 Step 1 – Login Bypass

Classic SQL injection:

Logged in as admin, because who needs credentials when you've got logic flaws?

🎭 Step 2 – File Upload Bypass via Magic Bytes

Bypass the upload filter expecting valid PNG/JPG magic bytes:

Append web shell payload:

Uploaded as shell.php.png, slipped past MIME and magic number check.


📞 Step 3 – Reverse Shell

Tried bash reverse shells → ❌ Checked for Python → ✅

Crafted Python3 reverse shell:

🔐 Step 4 – Credential Discovery

Found in db.php5:

🔎 Step 5 – Enumerating MySQL Binaries

mysql client missing? No problem.

Used mysqldump to extract all DBs:

found password

🧗‍♂️ Step 6 – Privilege Escalation

Switched user:

Checked for custom binaries: (i did look through the walkthrough, i did get it in ,Linpease but i skipped it while reading through it)

  • a did a strings and got it know it was using a couple of binaries with a full path not set

  • Spun an nc listen on my machine on port 80 and got root

🛑 Post-Root Notes

❌ Couldn't download SQL backup via browser?

Blocked by .htaccess:

📂 Upload Filter Breakdown (PHP Logic)

🔎 $allowed = array('2', '3'); — What does it mean?

This line is checking magic numbers (also called image type constants) returned by PHP’s exif_imagetype() function.

🧬 exif_imagetype() returns an integer, not a string.

Here’s what those numbers mean:

Return Value
Image Type

1

GIF

2

JPEG

3

PNG

4

SWF

5

PSD

6

BMP

7

TIFF (Intel)

8

TIFF (Motorola)

9

JPC

...

etc.

🧠 Final Thoughts

This box covers:

  • Basic SQLi

  • Image upload filtering bypass

  • Manual reverse shell crafting

  • Hunting binaries for data extraction

  • Blocking mechanisms using .htaccess

Great blend of web exploitation and privilege escalation.

Last updated