|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "TryHackMe Light Walkthrough - SQL Injection Challenge" |
| 4 | +description: "Complete step-by-step walkthrough for TryHackMe's Light room featuring SQLite injection techniques, database enumeration, and admin credential extraction. Perfect for beginners learning SQL injection fundamentals." |
| 5 | +date: 2025-08-15 10:00:00 +0000 |
| 6 | +categories: [Cybersecurity, Writeups, Tryhackme] |
| 7 | +tags: [tryhackme, thm, sql-injection, sqlite, database, enumeration, ctf, beginner-friendly] |
| 8 | +image: https://tryhackme-images.s3.amazonaws.com/room-icons/618b3fa52f0acc0061fb0172-1737140605838 |
| 9 | +sitemap: |
| 10 | + priority: 0.8 |
| 11 | + changefreq: monthly |
| 12 | +--- |
| 13 | + |
| 14 | + |
| 15 | +# TryHackMe Light Walkthrough |
| 16 | +Link to the Room : https://tryhackme.com/room/lightroom |
| 17 | + |
| 18 | +``` |
| 19 | +I am working on a database application called Light! Would you like to try it out? |
| 20 | +If so, the application is running on **port 1337**. You can connect to it using `nc MACHINE-IP 1337` |
| 21 | +You can use the username `smokey` in order to get started. |
| 22 | +``` |
| 23 | +Lets start the machine and wait for 2-3 minutes, let the machine get fully functional. |
| 24 | + |
| 25 | +`Q1 What is the admin username?` |
| 26 | + |
| 27 | +As usual running a full port scan for identifying potential entry points. |
| 28 | +`nmap -p- -T4 MACHINE-IP -vv` |
| 29 | +![[Pasted image 20250816001828.png]] |
| 30 | + |
| 31 | +Meanwhile lets try connecting to the port 1337 |
| 32 | +`nc MACHINE-IP 1337` |
| 33 | +Lets try the username provided `smokey` |
| 34 | +![[Pasted image 20250816002133.png]] |
| 35 | +Alright! |
| 36 | + |
| 37 | +So, I guess we can try brute-forcing a wordlist of usernames, but we cannot use ffuf... |
| 38 | +So, |
| 39 | +I took this script from ChatGPT, and modified it little to make it work. |
| 40 | +```python |
| 41 | +import socket |
| 42 | + |
| 43 | +target_ip = "10.201.15.128" # change this |
| 44 | +target_port = 1337 |
| 45 | +wordlist = "SecLists/Usernames/cirt-default-usernames.txt" # your username list |
| 46 | + |
| 47 | +with open(wordlist, "r") as f: |
| 48 | + usernames = [u.strip() for u in f if u.strip()] |
| 49 | + |
| 50 | +for user in usernames: |
| 51 | + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 52 | + s.connect((target_ip, target_port)) |
| 53 | + |
| 54 | + # Receive initial banner / prompt |
| 55 | + banner = s.recv(1024).decode() |
| 56 | + print(banner.strip()) |
| 57 | + |
| 58 | + u = s.recv(1024).decode() |
| 59 | + print(u.strip()) |
| 60 | + |
| 61 | + # Send username |
| 62 | + s.send((user + "\n").encode()) |
| 63 | + |
| 64 | + # Receive response |
| 65 | + response = s.recv(1024).decode() |
| 66 | + print(f"[{user}] -> {response.strip()}") |
| 67 | + |
| 68 | + s.close() |
| 69 | + |
| 70 | +``` |
| 71 | + |
| 72 | +I tried few wordlists but didn't find anything. |
| 73 | + |
| 74 | +Got back to the nmap scan and LOL!, its gonna take forever so its not the way in for sure! |
| 75 | +![[Pasted image 20250816003201.png]] |
| 76 | + |
| 77 | +What else can we do? Found no `http` pages, where can we even use the credentials we've got earlier? |
| 78 | +Lets try to change the approach. |
| 79 | + |
| 80 | +Lets try putting in some random input, my mind is getting a little idea of where it is going _maybe_. |
| 81 | +![[Pasted image 20250816003925.png]] |
| 82 | +Its more of an Injection vulnerability I see |
| 83 | +Its been a long I have not dealt with a SQLi, now quickly digging through my notes for revising required methods. |
| 84 | + |
| 85 | +From the responses below |
| 86 | +![[Pasted image 20250816004841.png]] |
| 87 | +I can imagine of a SQL query |
| 88 | +`select pass from users where user='<input>' limit 30` |
| 89 | + |
| 90 | +Now we'll try creating some SQL payloads based on the payloads I already have in my notes. |
| 91 | +`'union select 1'` |
| 92 | +![[Pasted image 20250816005530.png]] |
| 93 | +Okhayy! |
| 94 | +They might be blocking some keywords most probably as an easy way out. |
| 95 | +Here might be a logic error lets try `'UnIOn sElecT 1'` |
| 96 | +![[Pasted image 20250816005739.png]] |
| 97 | +as a developer I would also blacklist these keywords as its an easy fix(not a fix really). Laziness is a problem frr. |
| 98 | +I love these kinda logic based errors! |
| 99 | + |
| 100 | +Lets start enumerating. |
| 101 | +`'Union Select @@version'` |
| 102 | +Didn't work maybe some other database! |
| 103 | + |
| 104 | +Refer this https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/SQLite%20Injection.md#sqlite-enumeration |
| 105 | + |
| 106 | +This one worked |
| 107 | +`'Union Select sqlite_version()'` |
| 108 | +Its sqlite database version: 3.31.1 |
| 109 | +![[Pasted image 20250816010644.png]] |
| 110 | + |
| 111 | +Using the [PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/SQLite%20Injection.md#sqlite-enumeration) Repository for reference! |
| 112 | + |
| 113 | +`'Union Select sql from sqlite_master'` |
| 114 | +![[Pasted image 20250816010906.png]] |
| 115 | + |
| 116 | +Now we know the table name, column names. |
| 117 | +Enough to craft useful payloads. |
| 118 | + |
| 119 | +> You can use [PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/SQL%20Injection/SQLite%20Injection.md#sqlite-enumeration)and suitable LLM for crafting payloads |
| 120 | +
|
| 121 | +`'Union Select username from admintable where id='1` |
| 122 | +![[Pasted image 20250816011619.png]] |
| 123 | +If needed we could've dumped all but in this case we don't need the whole database. |
| 124 | + |
| 125 | +![[Pasted image 20250816011809.png]] |
| 126 | + |
| 127 | +`Q2 What is the password to the username mentioned in question 1?` |
| 128 | +`'Union Select password from admintable where username='<admin-user>` |
| 129 | +![[Pasted image 20250816012001.png]] |
| 130 | + |
| 131 | +![[Pasted image 20250816012439.png]] |
| 132 | + |
| 133 | +`Q3 What is the flag?` |
| 134 | +Till now you could've figured it out, we have already got the id for the user flag, so most probably its password will be the final flag. |
| 135 | +Little modifications to the previous payload will get you the flag. |
| 136 | + |
| 137 | +![[Pasted image 20250816012516.png]] |
0 commit comments