[정보보안] 오픈 포트(Open Port) 확인하는 방법- tcping & nmap 사용법
윈도우와 리눅스에는 특정 호스트의 특정 포트가 열려있는지 상태를 확인할 수 있는 명령어가 있습니다.
- 윈도우 : tcping
- 리눅스 : nmap
아래에서 tcping과 nmap 명령어 사용법을 알아보겠습니다.
윈도우 : tcping
- tcping 명령어는 디폴트로 설치되지 않기 때문에 다운로드해야 합니다.
- “cmd” 창을 열고, tcping명령어를 다운로드한 폴더로 이동하여 명령줄에서 실행합니다.
- tcping 명령어 사용 예제
Part 5)쉽고 완벽한 Weblogic과 Webtier 설치하기에서 사용하는 서버의 상태를 체크해 보겠습니다.[ 사용법 및 주요 옵션 ] tcping [-td46] [-i interval] [-n times] destination [port]
-t : ctrl+c를 만날 때까지 계속해서 수행 -d : 출력줄마다 날짜와 시간 출력 -4 : IPv4 환경 -6 : IPv6 환경 -i interval : ping 간격, default 1초 -n times : ping 횟수, default 4회 [port] : 포트를 지정하지 않으면 default 80 포트로 지정d:\>tcping -d 192.168.56.104 802023:10:19 11:47:58 Probing 192.168.56.104:80/tcp - Port is open - time=1.448ms 2023:10:19 11:47:59 Probing 192.168.56.104:80/tcp - Port is open - time=1.861ms 2023:10:19 11:48:00 Probing 192.168.56.104:80/tcp - Port is open - time=2.003ms 2023:10:19 11:48:01 Probing 192.168.56.104:80/tcp - Port is open - time=2.048ms Ping statistics for 192.168.56.104:80 4 probes sent. 4 successful, 0 failed. (0.00% fail) Approximate trip times in milli-seconds: Minimum = 1.448ms, Maximum = 2.048ms, Average = 1.840ms
리눅스 : nmap
- nmap 명령어 설치 여부 확인 및 설치
[root@centos8 ~]# which nmap/usr/bin/which: no nmap in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)[root@centos8 ~]# yum -y install nmap..... More ..... Upgraded: nmap-ncat-2:7.92-1.el8.x86_64 Installed: nmap-2:7.92-1.el8.x86_64 Complete![root@centos8 ~]# rpm -qa nmapnmap-7.92-1.el8.x86_64
- nmap 명령어 옵션 사용법
– TCP/IP 프로토콜 표준이 명시하지 않은 패킷 처리 기능의 운영체제별로 구현을 확인하여 운영체제를 판단하는데 이용
– Stealth Scan 중 TCP FIN스캔, XMAS스캔, NULL스캔을 실행했는데 결과가 없다면 Windows 계열의 시스템으로 판단[ 사용법 및 주요 옵션 ] nmap option destination [port] [option] -A: OS and version detection, script scanning, and traceroute, 모든 스캔 옵션 활성화 -F : 빠른 네트워크 스캐닝 -T4 : faster execution -sF : TCP FIN 스캔, "포트가 열려있으면 응답이 없고, 닫혀있으면 RST+ACT 수신" -sN : TCP Null 스캔, "포트가 열려있으면 응답이 없고, 닫혀있으면 RST+ACT 수신" -sO : IP Protocol 스캔 -sA : TCP ACK 스캔, "방화벽의 Rule Set(필터링 정책) 확인" -sP : ping 스캔, "호스트의 생존 여부를 확인" -sS : TCP SYN(Half Open) Scan, "더 비밀스럽고 호스트에 log가 남지 않는 방법" -sT : TCP 연결(Open) 스캔, "포트가 열려있으면 SYN+ACK가 수신되고, 닫혀 있으면 RST+ACK 수신" -sU : UDP 연결 스캔, "포트가 닫혀있으면 ICMP Unreachable 수신" -sX : FIN, URG, PSH 패킷을 전송, "포트가 열려있으면 응답이 없고, 닫혀있으면 RST+ACT 수신" -A : 모든 스캔 옵션 활성화 -O : 운영 체제 감지, TCP Fingerprinting -b : FTP bounce 스캔 -v : 스캔 결과를 상세하게 출력 -D {RND:숫자|IP,IP,IP} : Decoy 스캔, 실제 스캔너 주소 외의 다양한 위조된 주소로 스캔하는 방식 --script=
: Nmap Scripting Engine (NSE)을 사용, /usr/share/nmap/scripts/ 디렉터리에 저장된 스크립트 사용 -oN "파일명" : 일반 파일로 스캔 결과 저장 -oX "파일명" : xml 파일 형식으로 스캔 결과 저장 -oG "파일명" : grep, awk 등으로 분석하기 편한 grepable 파일 형식으로 저장, 파일명에 "-"는 표준 출력으로 보내라는 의미 [port] -p T:port1[,port2],port_fr-port_to U:port1[,port2],port_fr-port_to - nmap 명령어 사용 예제
- 먼저 Part 5)쉽고 완벽한 Weblogic과 Webtier 설치하기에서 사용하는 서버의 상태를 체크해 보겠습니다.
[root@centos8 ~]# nmap 192.168.56.104 -p T:80,7100-7102Starting Nmap 7.92 ( https://nmap.org ) at 2023-10-19 13:50 KST Nmap scan report for 192.168.56.104 Host is up (0.00039s latency). PORT STATE SERVICE 80/tcp open http 7100/tcp open font-service 7101/tcp open elcn 7102/tcp open unknown MAC Address: 08:00:27:1B:83:A5 (Oracle VirtualBox virtual NIC) Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds
- Decoy Scan(-D 옵션): 실제 스캔너 주소 외의 다양한 위조된 주소로 스캔하는 방식
# -D RND:숫자 : 무작위로 지정된 숫자의 가짜 IP 주소(디코이 IP 주소)로 디코이 포트 스캔 수행 # -D IP주소,IP주소: 콤마로 구분된 IP주소 목록을 사용하여 디코이 포트 스캔 수행
[root@rhel7u7 ~]# nmap -D RND:5 -p22,80,113,139 scanme.nmap.orgStarting Nmap 6.40 ( http://nmap.org ) at 2023-11-14 21:01 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.041s latency). PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 113/tcp filtered ident 139/tcp filtered netbios-ssn Nmap done: 1 IP address (1 host up) scanned in 1.95 seconds - Ping Sweep(-sn 옵션): 살아있는 장비들의 IP 주소 리스트 출력
– 네트워크 범위 내에서 모든 IP 주소에 대해 ICMP Echo Request를 보내고, 응답하는 호스트를 식별# -n : scanning 하는 IP에 대해 DNS 질문을 하지 않는다, 호스트들을 IP주소로 표시 # -vv : 명령어를 실행하는 동안 실시간으로 보고한다. # -sn : No port scan, 포트 스캔 없이 호스트의 생존 여부를 확인 # -oG - : 출력을 Grepable 형태로 나타낸다.(grep 명령어 사용) # | grep -i "up" : 상태가 up인 결과만 뽑아서 출력
[root@rhel7u7 ~]# nmap -n -vv -sn 192.168.56.1-255 -oG - | grep -i "up"Host: 192.168.56.1 () Status: Up Host: 192.168.56.100 () Status: Up Host: 192.168.56.101 () Status: Up - Ping Scan(-sP 옵션): TCP SYN Ping을 이용하여 Ping Sweep Filter를 우회하는 방법
– 특정 네트워크 범위 또는 개별 IP 주소에 대해 ICMP Echo Request를 보내고 응답하는 호스트를 식별, Ping Sweep 포함# -sP: Ping Scan, 호스트의 생존 여부를 확인 # -PS[portlist]: TCP SYN Ping, 특정 포트에 대한 응답을 확인 # nmap은 호스트 스캔을 시작하기 전에 ARP Ping을 사용하여 호스트의 존재 여부를 확인
[root@rhel7u7 ~]# nmap -sP -PS scanme.nmap.org --disable-arp-pingStarting Nmap 6.40 ( http://nmap.org ) at 2023-11-25 04:07 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.16s latency). Nmap done: 1 IP address (1 host up) scanned in 0.58 seconds - TCP Connection 스캔(-sT): TCP Open 스캔
– 잁반 사용자 권한으로 TCP 포트 오픈 여부를 확인하기 위해 connect 시스템 호출을 이용하는 방식입니다
– TCP 연결설정 과정(3way handshaking)을 완전하게 수행하여 타겟 호스트의 포트에 직접 연결하기 때문에 Open 스캔이라고 하며 타겟 호스트의 시스템 로그에 스캔한 흔적이 남는 특성이 있습니다.
– 오픈 포트를 확인한 다음에는 연결을 즉시 중단하기 위해 RSK+ACT 패킷을 타겟 호스트에 전송합니다.
Probe Response Assigned State TTCP SYN/ACK response open TCP RST/ACK response closed No response received (even after retransmissions) – iptables DROP 정책 filtered ICMP unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) – iptables REJECT 정책 filtered root@kali:~# nmap -p22,80,113,139 scanme.nmap.org -sTStarting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-29 15:27 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.036s latency). Other addresses for scanme.nmap.org (not scanned): 2600:3c01::f03c:91ff:fe18:bb2f PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 113/tcp filtered ident 139/tcp filtered netbios-ssn Nmap done: 1 IP address (1 host up) scanned in 2.61 seconds - TCP SYN 스캔(-sS): Half-Open 스캔, 스텔스 스캔방식
– SYN 스캔은 Default이자 가장 널리 사용되는 스캔 옵션으로 방화벽의 방해를 받지 않는 빠른 네트워크에서 초당 수천 개의 포트를 검색하여 빠르게 수행할 수 있습니다.
– SYN 스캔은 TCP 연결을 완료하지 않기 때문에 상대적으로 눈에 띄지 않고 은밀합니다.
– nmap의 FIN/NULL/Xmas, Maimon처럼 특정 플랫폼의 특이성에 의존하지 않고 모든 호환 TCP 스택에 대해 작동합니다.
– 또한 개방형, 폐쇄형 및 필터링된 상태를 명확하고 안정적으로 구분할 수 있습니다.
– 오픈 포트를 확인한 다음에는 연결을 완료하지 않고, 패킷 조작을 통해 즉시 중단하기 위해 RST 패킷을 타겟 호스트로 전송합니다.
Probe Response Assigned State TCP SYN/ACK response open TCP RST/ACK response closed No response received (even after retransmissions) – iptables DROP 정책 filtered ICMP unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) – iptables REJECT 정책 filtered root@kali:~# nmap -p22,80,113,139 scanme.nmap.org -sSStarting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-12 07:50 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.031s latency). Other addresses for scanme.nmap.org (not scanned): 2600:3c01::f03c:91ff:fe18:bb2f PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 113/tcp closed ident 139/tcp filtered netbios-ssn Nmap done: 1 IP address (1 host up) scanned in 1.98 seconds - TCP ACK 스캔(-sA)
– 포트의 개방 여부가 아닌 방화벽의 Rule Set(필터링 정책)을 테스트하기 위한 스캔
– 대상 방화벽이 상태기반 방화벽인지 여부, 포트들이 방화벽에 의해 필터링 되고 있는지를 확인하기 위해서 사용
– 필터링 시: 응답 없음 또는 ICMP 메세지 수신
– 필터링되지 않을 때: RST+ACK 수신
Probe Response Assigned State TCP RST response(open and closed ports) unfiltered No response received (even after retransmissions) – DROP Action filtered ICMP unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) – REJECT Action filtered root@kali:~# nmap -p22,80,113,139 scanme.nmap.org -sAStarting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-15 08:42 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.00092s latency). Other addresses for scanme.nmap.org (not scanned): 2600:3c01::f03c:91ff:fe18:bb2f PORT STATE SERVICE 22/tcp unfiltered ssh 80/tcp unfiltered http 113/tcp unfiltered ident 139/tcp filtered netbios-ssn Nmap done: 1 IP address (1 host up) scanned in 0.59 seconds - TCP FIN(-sF)/NULL(-sN)/XMAS(-sX) 스캔
– TCP 연결을 생성하지 않고 스캔하는 스텔스 스캔방식으로 TCP 패킷 헤더의 제어 비트(flags)를 비정상적으로 설정해서 스캔합니다.
– 닫힌 포트로 RST 패킷을 수신하면 응답하지 않고, RST 이외의 패킷을 수신한 경우 RSK+ACK 패킷으로 응답합니다.
– 오픈 포트로 SYN, ACK, RST 이외의 패킷을 수신한 경우 이를 폐기하고 응답하지 않습니다.
Probe Response Assigned State No response received Open TCP RST+ACK response(open and closed ports) Closed No response received (even after retransmissions) – iptables DROP 정책 filtered ICMP unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) – iptables REJECT 정책 filtered root@kali:~# nmap -p22,80,113,139 scanme.nmap.org {-sF|-sN|-sX}# nmap -p22,80,113,139 scanme.nmap.org -sF Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-29 16:13 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.0016s latency). Other addresses for scanme.nmap.org (not scanned): 2600:3c01::f03c:91ff:fe18:bb2f PORT STATE SERVICE 22/tcp closed ssh 80/tcp closed http 113/tcp closed ident 139/tcp closed netbios-ssn Nmap done: 1 IP address (1 host up) scanned in 1.31 seconds - UDP(-sU) 스캔
– 타겟 호스트의 UDP 포트 오픈 여부를 판단하는 스캔 방식
Probe Response Assigned State No response received / UDP response Open ICMP unreachable Close No response received (even after retransmissions) – iptables DROP 정책 filtered ICMP unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) – iptables REJECT 정책 filtered root@kali:~# nmap -p22,80,113,139 scanme.nmap.org -sUStarting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-29 16:17 KST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.00088s latency). Other addresses for scanme.nmap.org (not scanned): 2600:3c01::f03c:91ff:fe18:bb2f PORT STATE SERVICE 22/udp open|filtered ssh 80/udp open|filtered http 113/udp open|filtered auth 139/udp open|filtered netbios-ssn Nmap done: 1 IP address (1 host up) scanned in 2.02 seconds - NSE(–script 옵션) 사용
# --script=http-title : 지정된 호스트의 HTTP 타이틀 검색
[root@centos8 test]# nmap --script=http-title 8.8.8.8Starting Nmap 7.92 ( https://nmap.org ) at 2024-07-13 16:57 KST Nmap scan report for dns.google (8.8.8.8) Host is up (0.013s latency). Not shown: 998 filtered tcp ports (no-response) PORT STATE SERVICE 53/tcp open domain 443/tcp open https |_http-title: Google Public DNS Nmap done: 1 IP address (1 host up) scanned in 5.40 seconds
- 먼저 Part 5)쉽고 완벽한 Weblogic과 Webtier 설치하기에서 사용하는 서버의 상태를 체크해 보겠습니다.