Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

4.4.2. Which Ports Are Listening 확인

가능한 공격을 피하기 위해 사용되지 않는 포트를 닫는 것이 중요합니다. 수신 대기 상태의 예기치 않은 포트의 경우 발생할 수 있는 침입에 대해 조사해야 합니다.

Open Ports Scan에 netstat 사용

다음 명령을 root 로 입력하여 네트워크에서 연결을 수신 대기 중인 포트를 확인합니다.
~]# netstat -pan -A inet,inet6 | grep -v ESTABLISHED
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address       Foreign Address    State     PID/Program name
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 192.168.124.1:53        0.0.0.0:*               LISTEN      1829/dnsmasq
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1176/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1177/cupsd
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1664/master
sctp              0.0.0.0:2500                                      LISTEN   20985/sctp_darn
udp        0      0 192.168.124.1:53        0.0.0.0:*                           1829/dnsmasq
udp        0      0 0.0.0.0:67              0.0.0.0:*                           977/dhclient
...
netstat 명령의 -l 옵션을 사용하여 수신 대기 중인 서버 소켓만 표시합니다.
~]# netstat -tlnw
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN
tcp        0      0 192.168.124.1:53        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp6       0      0 :::111                  :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 ::1:631                 :::*                    LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN
raw6       0      0 :::58                   :::*                    7

Open Ports Scan에 ss 사용

또는 ss 유틸리티를 사용하여 수신 대기 상태에 열려 있는 포트를 나열합니다. netstat 보다 많은 TCP 및 상태 정보를 표시할 수 있습니다.
~]# ss -tlw
etid State      Recv-Q Send-Q     Local Address:Port                      Peer Address:Port
udp   UNCONN     0      0                     :::ipv6-icmp                           :::*
tcp   LISTEN     0      128                    *:sunrpc                               *:*
tcp   LISTEN     0      5          192.168.124.1:domain                               *:*
tcp   LISTEN     0      128                    *:ssh                                  *:*
tcp   LISTEN     0      128            127.0.0.1:ipp                                  *:*
tcp   LISTEN     0      100            127.0.0.1:smtp                                 *:*
tcp   LISTEN     0      128                   :::sunrpc                              :::*
tcp   LISTEN     0      128                   :::ssh                                 :::*
tcp   LISTEN     0      128                  ::1:ipp                                 :::*
tcp   LISTEN     0      100                  ::1:smtp                                :::*
~]# ss -plno -A tcp,udp,sctp
Netid State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port
udp   UNCONN     0      0            192.168.124.1:53                                   *:*                   users:(("dnsmasq",pid=1829,fd=5))
udp   UNCONN     0      0                 *%virbr0:67                                   *:*                   users:(("dnsmasq",pid=1829,fd=3))
udp   UNCONN     0      0                        *:68                                   *:*                   users:(("dhclient",pid=977,fd=6))
...
tcp   LISTEN     0      5            192.168.124.1:53                                   *:*                   users:(("dnsmasq",pid=1829,fd=6))
tcp   LISTEN     0      128                      *:22                                   *:*                   users:(("sshd",pid=1176,fd=3))
tcp   LISTEN     0      128              127.0.0.1:631                                  *:*                   users:(("cupsd",pid=1177,fd=12))
tcp   LISTEN     0      100              127.0.0.1:25                                   *:*                   users:(("master",pid=1664,fd=13))
...
sctp  LISTEN     0      5                        *:2500                                 *:*                   users:(("sctp_darn",pid=20985,fd=3))
UNCONN 상태는 UDP 수신 대기 모드로 포트를 표시합니다.
외부 시스템에서 ss 출력에 표시된 모든 IP 주소( localhost 127.0.0.0 또는 ::1 범위를 제외)에 대해 검사를 수행합니다. IPv6 주소를 스캔하는 데 -6 옵션을 사용합니다.
그런 다음 네트워크를 통해 연결된 다른 원격 시스템의 nmap 도구를 첫 번째 시스템으로 사용하여 외부 검사를 수행합니다. firewalld 에서 규칙을 확인하는 데 사용할 수 있습니다. 다음은 TCP 연결을 수신 대기 중인 포트를 결정하는 예입니다.
~]# nmap -sT -O 192.168.122.65
    Starting Nmap 6.40 ( http://nmap.org ) at 2017-03-27 09:30 CEST
    Nmap scan report for 192.168.122.65
    Host is up (0.00032s latency).
    Not shown: 998 closed ports
    PORT    STATE SERVICE
    22/tcp  open  ssh
    111/tcp open  rpcbind
    Device type: general purpose
    Running: Linux 3.X
    OS CPE: cpe:/o:linux:linux_kernel:3
    OS details: Linux 3.7 - 3.9
    Network Distance: 0 hops

    OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
    Nmap done: 1 IP address (1 host up) scanned in 1.79 seconds
TCP 연결 검사 (-sT) 는 TCP SYN 검사 (-sS) 가 옵션이 아닌 경우 기본 TCP 검사 유형입니다. O 옵션은 호스트의 운영 체제를 감지합니다.

netstatss 를 사용하여 Open SCTP 포트 검사

netstat 유틸리티는 Linux 네트워킹 하위 시스템에 대한 정보를 출력합니다. Open Stream Control Transmission Protocol (SCTP) 포트에 대한 프로토콜 통계를 표시하려면 root 로 다음 명령을 입력합니다.
~]# netstat -plnS
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address  State    PID/Program name
sctp                127.0.0.1:250                    LISTEN   4125/sctp_darn
sctp       0      0 127.0.0.1:260   127.0.0.1:250    CLOSE    4250/sctp_darn
sctp       0      0 127.0.0.1:250   127.0.0.1:260    LISTEN   4125/sctp_darn
~]# netstat -nl -A inet,inet6 | grep 2500
sctp                0.0.0.0:2500                                    LISTEN
ss 유틸리티는 SCTP 오픈 포트를 표시할 수도 있습니다.
~]# ss -an | grep 2500
sctp   LISTEN     0      5         *:2500                  *:*
자세한 내용은 ss(8), netstat(8), nmap(1)services(5) 매뉴얼 페이지를 참조하십시오.