labunix's blog

labunixのラボUnix

kalilinux(2018.2)とMetasploitable2-Linuxを偵察してみる。

■kalilinux(2018.2)とMetasploitable2-Linuxを偵察してみる。
 攻撃手口としては、「偵察・攻撃準備」->「マルウエア感染」->「人が行う不正アクセス」の3段階を想定。

# host debian stretch
$ lsb_release -d
Description:	Debian GNU/Linux 9.4 (stretch)
$ ip a | awk '/inet 192/{print $2}'
192.168.0.5/24

# guest debian stretch
$ lsb_release -d
Description:	Debian GNU/Linux 9.4 (stretch)
$ ip a | awk '/inet 192/{print $2}'
192.168.0.4/24

# kalilinux-2018.2
$ lsb_release -d
Description:	Kali GNU/Linux Rolling
$ ip a | awk '/inet 192/{print $2}'
192.168.0.3/24

# Metasploitable2-Linux
$ lsb_release -d
Description:	Ubuntu 8.04
$ ip a | awk '/inet 192/{print $2}'
192.168.0.2/24

■まずはホストのstretchから偵察を行う準備
 許可されていない対象には使用しないこと。

 penetration.sh 
 https://raw.githubusercontent.com/labunix/penetration/master/penetration.sh

$ sudo ./myscripts/penetration.sh 192.168.0.4
Warning: The -P0 option is deprecated. Please use -Pn
...

$ wget https://raw.githubusercontent.com/labunix/penetration/master/penetration.sh
$ mv penetration.sh myscripts/
$ chmod +x myscripts/penetration.sh 
$ sed -i -e 's/P0/Pn/' myscripts/penetration.sh 

■ホストを含めて偵察
 基本的に非破壊型なので、自分で管理しているか、許可された対象のみを客観的に評価する目的で行う。
 許可されていない対象には行わないこと。

$ seq 5 -1 2 | awk '{print "sudo ./myscripts/penetration.sh 192.168.0."$1" 2>&1 | tee -a 192.168.0."$1"_penetration.log"}' | sh

■当たり前ながら、0ホップである自身のレポートにはTRACEROUTE結果は含まれない。
 また、公開ポートが少ないほどテスト時間は少なくて済む。
 Metasploitable2-Linuxはやられサーバなので最も待受ポートが多い。
 
 無用な対策検討をする前に、Linuxなら不要なIPアドレス側で待ち受けないように、各サービスのIP制限で対処しましょう。。。
 Webやプロキシ、メールの待ち受けポート制限は当然ながら、xrdpの待ち受けポートも制限出来る。
 SSHは今回リモート制御のために開けているが、「virsh console」によるコンソール使用にして閉じるか、待ち受けIPを制限するべき。
 外部公開しないにしても、内部対策としてこのネットワークに対する従来型のペネトレーションテスト結果から、
 レポートに対処するだけでも対策出来ることは結構多かったりする。

Nmap scan report for 192.168.0.5
Host is up (0.000016s latency).
Not shown: 65532 closed ports
PORT     STATE SERVICE       VERSION
22/tcp   open  ssh           OpenSSH 7.4p1 Debian 10+deb9u3 (protocol 2.0)
| ssh-hostkey: 
|   2048 77:5d:ec:99:83:18:6e:8a:8d:ad:7e:55:be:39:9e:3c (RSA)
|_  256 5b:15:a5:1e:68:d9:51:4e:24:b6:e2:a0:68:c6:15:f7 (ECDSA)
3389/tcp open  ms-wbt-server Microsoft Terminal Service
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.8 - 4.6
Uptime guess: 3.519 days (since Tue May  1 16:06:38 2018)
Network Distance: 0 hops
TCP Sequence Prediction: Difficulty=262 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OSs: Linux, Windows; CPE: cpe:/o:linux:linux_kernel, cpe:/o:microsoft:windows

Nmap scan report for 192.168.0.4
Host is up (0.00025s latency).
Not shown: 65532 closed ports
PORT     STATE SERVICE    VERSION
22/tcp   open  ssh        OpenSSH 7.4p1 Debian 10+deb9u3 (protocol 2.0)
| ssh-hostkey: 
|   2048 b3:e1:f1:57:35:b3:b9:9b:7a:e5:0c:b7:ea:56:67:cb (RSA)
|_  256 cf:35:a6:63:81:11:5e:f7:a7:f0:53:89:50:03:68:ca (ECDSA)
MAC Address: 52:54:00:XX:XX:5A (QEMU virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.6
Uptime guess: 2.367 days (since Wed May  2 20:19:22 2018)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=265 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.25 ms 192.168.0.4

Nmap scan report for 192.168.0.3
Host is up (0.00028s latency).
Not shown: 65534 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.7p1 Debian 2 (protocol 2.0)
| ssh-hostkey: 
|   2048 2a:5c:a4:ff:1b:93:a5:15:82:3f:a4:0a:44:89:3c:4a (RSA)
|_  256 4c:b0:6e:c3:29:2e:9e:49:db:e3:5b:dd:bf:f8:8e:b1 (ECDSA)
MAC Address: 52:54:00:XX:XX:F4 (QEMU virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.6
Uptime guess: 42.172 days (since Sat Mar 24 00:50:14 2018)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=255 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.28 ms 192.168.0.3

Nmap scan report for 192.168.0.2
Host is up (0.029s latency).
Not shown: 65337 filtered ports, 190 closed ports
PORT    STATE SERVICE    VERSION
21/tcp  open  tcpwrapped
|_ftp-anon: ERROR: Script execution failed (use -d to debug)
22/tcp  open  tcpwrapped
23/tcp  open  tcpwrapped
25/tcp  open  tcpwrapped
|_smtp-commands: Couldn't establish connection on port 25
53/tcp  open  tcpwrapped
80/tcp  open  tcpwrapped
111/tcp open  tcpwrapped
139/tcp open  tcpwrapped
MAC Address: 00:0C:29:XX:XX:34 (VMware)
Device type: firewall
Running (JUST GUESSING): Fortinet embedded (87%)
OS CPE: cpe:/h:fortinet:fortigate_100d
Aggressive OS guesses: Fortinet FortiGate 100D firewall (87%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 1 hop

TRACEROUTE
HOP RTT      ADDRESS
1   28.93 ms 192.168.0.2