본문 바로가기

공부/리눅스

포트스캔 및 차단

반응형
Nmap (http://www.nmap.org)

특징

1. 호스트가 존재하는지 검사
2. 어떤 서비스가 실행중인지 검사
3. 운영체제 검사

scan 유형

connect scan : connect 함수의 에러값을 검사해서 포트가 닫혔는지 열렸는지 검사한다.
패킷을 변경하지 않으므로 일반 사용자도 사용가능

장점 : 빠르고 정확하며 특별한 권한이 필요없다.
단점 : 쉽게 탐지되고 기록된다.

1. 포트가 열려 있는경우.
Client -> SYN
Server -> SYN|ACK
Client -> ACK

2. 포트가 닫혀 있는경우
Client -> SYN
Server -> RST|ACK
Client -> RST

RST|ACK flag 는 클라이언트의 연결 요청을 취소
즉 포트는 lisening 상태가 아니며 닫혀 있음을 의미.

half open
syn scan : syn 패킷을 보내면 Three way handshaking 때문에 상대편에서 오는 syn 패킷의 내용을
보고 포트가 닫혔는지 열렸는지 검사한다.

Client -> SYN
Server -> SYN|ACK
Client -> RST

시스템의 포트가 열려 있으면, SYN|ACK flag로 답한다. RST flag는 커널의 tcp/ip 스택코드에서
자동으로 보내므로 클라이언트에서는 RST 패킷을 보낼필요가 없다.
닫힌 포트에서는 RST|ACK 로 응답한다.


stealth
FIN scan : FIN 패킷을 보내면 포트가 닫혀 있을경우,RST 패킷을 보내는 Unix 서버들의 특징을 이용해서
포트가 닫혔는지 열렸는지 검사한다.
Null scan : 어떤 flag도 없는 패킷을 보내 되돌아오는 RST 값을 검사한다.
Xmas scan : 모든 flag 를 세팅한 패킷을 보내 RST 값을 검사한다.
ACK scan : 포트에 ACK 패킷을 보내 RST 응답을 받으면 그 포트는 unfilterd 이며 아무런 응답이 없으면
filterd 이다.
Fragment scan : 패킷을 2개로 쪼개어 보낸다.
Window scan : ACK 패킷을 보내어 TCP window 크기의 변화를 살핀다.

기타
ping scan : icmp 의 echo 기능을 이용한다.
TCP ping scan : 80 포트에 syn 패킷을 보낸다.

*. nmap 사용옵션 예제

nmap -sT localhost
nmap abc.co.kr/24 192.168.10/24 192.168.100.0-255 192.168.1.*

usage : nmap
 nmap [Scan Type...] [Options] {target specification}

[root@centos1 /]# nmap -sT localhost

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-02-09 15:28 KST
Interesting ports on centos1 (127.0.0.1):
Not shown: 1668 closed ports
PORT    STATE SERVICE
21/tcp  open  ftp
22/tcp  open  ssh
23/tcp  open  telnet
25/tcp  open  smtp
53/tcp  open  domain
80/tcp  open  http
111/tcp  open  rpcbind
443/tcp  open  https
631/tcp  open  ipp
672/tcp  open  unknown
953/tcp  open  rndc
3306/tcp open  mysql

Nmap finished: 1 IP address (1 host up) scanned in 0.700 seconds


-sT :

[root@centos1 /]# nmap -sS client

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-02-09 15:44 KST
Interesting ports on centos100 (192.168.100.100):
Not shown: 1676 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
23/tcp  open  telnet
111/tcp open  rpcbind
669/tcp open  unknown
MAC Address: 00:0C:29:C7:CA:72 (VMware)

Nmap finished: 1 IP address (1 host up) scanned in 1.590 seconds
[root@centos1 /]# nmap client

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-02-09 15:46 KST
Interesting ports on centos100 (192.168.100.100):
Not shown: 1676 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
23/tcp  open  telnet
111/tcp open  rpcbind
669/tcp open  unknown
MAC Address: 00:0C:29:C7:CA:72 (VMware)

Nmap finished: 1 IP address (1 host up) scanned in 1.437 seconds
[root@centos1 /]# nmap -sT client

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-02-09 15:46 KST
Interesting ports on centos100 (192.168.100.100):
Not shown: 1676 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
23/tcp  open  telnet
111/tcp open  rpcbind
669/tcp open  unknown
MAC Address: 00:0C:29:C7:CA:72 (VMware)

Nmap finished: 1 IP address (1 host up) scanned in 3.296 seconds

[root@centos1 ~]# nmap -A redhat

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-03-22 05:48 KST
Interesting ports on redhat (192.168.203.3):
Not shown: 1674 closed ports
PORT    STATE SERVICE VERSION
21/tcp  open  ftp    vsftpd 1.1.3
22/tcp  open  ssh    OpenSSH 3.5p1 (protocol 1.99)
23/tcp  open  telnet  Linux telnetd
53/tcp  open  domain  ISC Bind 9.2.1
80/tcp  open  http    Apache httpd 2.0.40 ((Red Hat Linux))
111/tcp open  rpcbind  2 (rpc #100000)
MAC Address: 00:0C:29:85:50:D9 (VMware)
Device type: general purpose
Running: Linux 2.4.X|2.5.X|2.6.X
OS details: Linux 2.4.0 - 2.5.20, Linux 2.4.7 - 2.6.11
Service Info: OSs: Unix, Linux

Nmap finished: 1 IP address (1 host up)
 

portsentry
 
portsentry는 실시간으로 이런 portscan을 탐지하고 대응하기 위해 만들어진 프로그램.
 portsentry는 정상적인 스캔과 스탤스스캔 모두 탐지가능
(패키지에 포함되어 있는 README.install을 참조)
 
주요 옵션
 
-tcp - Basic port-bound TCP mode (기본 포트 제한 TCP 모드)
-udp - Basic port-bound UDP mode (기본 포트 제한 UDP 모드)
-stcp - Stealth TCP scan detection mode (스텔스 TCP 스캔 탐지 모드)
호스트로 들어오는 패킷이 감시되고 있는 포트로 향한다면, PortSentry는 호스트를 방어하기
위해 동작한다.
이 방법은 connect() 스캔과 SYN/half-open 스캔과 FIN 스캔을 탐지할 것이다.
UDP/스텔스 스캔 경고가 적용된다. (README.stealth파일 참조)

-sudp - "Stealth" UDP scan detection mode (스텔스 UDP 스캔 탐지 모드)
이것은 위의 TCP stealth mode와 작동방법은 동일하다. UDP 포트들을 나열하면, 그 포트들은
감시된다. 이것은 어떠한 소켓도 묶지 않으며, 실제 스텔스 스캔 탐지 모드가 아닌 중에도 거의
동일하게 동작한다.( 모든 UDP 패킷에 반응한다.)
UDP/스텔스 스캔 경고가 적용된다. (README.stealth파일 참조)

-atcp - Advanced TCP stealth scan detection mode (advanced TCP 스텔스 스캔 탐지 모드)
PortSentry는 ADVANCED_PORTS_TCP 옵션에 지정된 최상의 포트번호이하의 모든 열려진 포트에
대한 목록을 만들면서 시작하고, 이러한 포트들을 기초로 제외(exclusion)목록을 만들 것이다.
제외되지 않은( 예를 들어, [SMTP, HTTP, 등의] 열려진[listening] network daemon이 아닌, )
영역내의 임의의 포트에 연결된 호스트들은 접속이 금지된다.

-audp - Advanced UDP stealth scan detection mode (advanced UDP 스탤스 스캔 탐지 모드)
UDP 프로토콜을 사용한다는 점을 제외하고는 위와 같다. Advanced UDP stealth scan detection은
지원되지 않는 트래픽을 즉시 알 수 있기 때문에 강력하지만 부정확한 경보의 가능성이 높다.
 
실행하기
 
[root@centos100 portsentry]# portsentry -tcp
[root@centos100 portsentry]# portsentry -udp
[root@centos100 portsentry]# portsentry -stcp
[root@centos100 portsentry]# portsentry -sudp
[root@centos100 portsentry]# portsentry -atcp
[root@centos100 portsentry]#portsentry -audp

[root@chtla portsentry]# pgrep -fl portsentry
303 portsentry -tcp
32671 /usr/sbin/portsentry -atcp
32673 /usr/sbin/portsentry -audp
[root@centos100 portsentry]#

*. rpm 패키지를 설치할 경우 설정파일이 저장되는 디렉토리는
/etc/portsentry 이다.

[root@centos100 portsentry]# ls
portsentry.blocked.atcp  portsentry.conf      portsentry.history  portsentry.modes
portsentry.blocked.audp  portsentry.ignore

*. portsentry.conf ; 주 설정 파일
*. portsentry.ignore ; 차단하지 않을 주소 지정.

반응형