hack the box shocker[linux]
shocker
今回は、hack the box(HTB)にあるOSCPlikeなマシーンをやっていきます。
下の表を参考にしながら、これからも進めていきたいと思います。
[追記] こちらの方が量多いですねIn the meantime for anyone that is on @hackthebox_eu I have created a list of OSCP-Like boxes you can try. Most of these are retired but if you have VIP access try them out! If you do not have VIP don't worry I recommend you check @ippsec channel as most of them are there. Enjoy! pic.twitter.com/HO5WprcFq0
— Tony (@TJ_Null) 2019年1月26日
nmap[ポートスキャン]
# Nmap 7.80 scan initiated Thu May 14 02:26:42 2020 as: nmap -A -oA 1 shocker.htb Nmap scan report for shocker.htb (10.10.10.56) Host is up (0.15s latency). Not shown: 998 closed ports PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.18 ((Ubuntu)) |_http-server-header: Apache/2.4.18 (Ubuntu) |_http-title: Site doesn't have a title (text/html). 2222/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA) | 256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA) |_ 256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Thu May 14 02:27:18 2020 -- 1 IP address (1 host up) scanned in 36.58 seconds
ssh:2222/tcp
先ず最初に2222ポートにあるsshを見てみました。
sshにuser enumrationのエクスプロイトコードがあるみたいなので、それを列挙してからhydra等で総当たり攻撃を試してみましたが無理そうでした。
一応プログラムは後ろで動かしながら次に移ります。
http:80/tcp
適当に接続してみても、画像とhtmlしか表示されませんでした。
dirb
cgi-binというフォルダを最初に見つけたが、それ以降そのディレクトリからファイルを見つけるのが一発で行けませんでした。cgiなので拡張子を, sh perl pl phpなどに設定してdirbを回しました。すると、無事にcgi-bin/user.shを見つけることができました。
user.shに接続すると、スクリプトが実行されていることがしっかりと確認できました。
cgiの脆弱性について調べるとshellshockというものが出てきました。 https://www.netagent.co.jp/study/blog/ganso/51996406.html
https://www.ne.jp/asahi/hishidama/home/tech/unix/vulnerability/bash_shellshock.html
名前もshockerということので、このシェルショックで攻撃してみることにしました。
参考は以下のサイト
今更なBashのShellShockを試してみた - Qiita
前回のoptimumで知ったippsecのOSコマンドインジェクションの動作確認方法を試してみる。
これは自分にpingを打つという方法であった。
確認コマンドは下記となります。
tcpdump -i tun0
絞り込んだ方がよかったですね。 その結果、自分のサーバにICMPパケットが飛んできて、自分のマシンがそれにレスポンスをしているパケットを確認することができました。
シェル獲得
任意のコマンドを利用できることを確認したので、ncやbashをつかってreverseshellを取っていきます!
下記のチートシートを上から順番に試してみます。
Reverse Shell Cheat Sheet
きちゃ!!
shelly@Shocker:/home/shelly$ cat user. cat user.txt <kotae>
enum for priv
shelly@Shocker:/home/shelly$ sudo -l sudo -l Matching Defaults entries for shelly on Shocker: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User shelly may run the following commands on Shocker: (root) NOPASSWD: /usr/bin/perl shelly@Shocker:/home/shelly$
とりあえず、find とsudo -l をしてからlinenum.sh使うのがいつもの流れなのですが、sudo -lで答えらしきものが出てきました。 パスなしでperlをroot権限で実行できるみたいなので、とりあえずコマンドを使うようなスクリプトを用意します。
#!/usr/bin/perl -w use strict; { system('cat /root/root.txt'); }
上のようなファイルを作り、python のsimplehttpserverを利用してファイルをvictim側に移します。
それを実行すると下のようになる。
shelly@Shocker:/home/shelly$ sudo perl evil2.pl sudo perl evil2.pl <kotae>
今回のBOXは権限昇格がだいぶ優しめだったと思います。
他の方のwriteupから
ippsecやほかの方のwriteup見てみたら、perl -e でスクリプトの実行を行っていましたね。だいぶ遠回りしていたようです。 あと、こんな便利なものもあるんですね 。 http-shellshock NSE Script