Windows Event Log

Download 0
Last updated Jun 13, 2024

윈도우 이벤트 로그 - 새로운 LISTEN 포트 생성

Windows 보안 이벤트 로그에서 서버가 최근 7일 동안 열지 않았던 포트로 접속 대기(LISTEN)를 시작한 경우를 탐지합니다.

Overview

Priority High
Type Batch
Schedule Every month/Every day/Every hour/Every 5 mins */5 * * * *
Message 새로운 LISTEN 포트 생성 : $host_ip
Output field order host_ip, computer, proto, port, listen_addr, process, pid, listen_count, first_time, last_time
MITRE Techniques T1571
MITRE tactics TA0011 Command and Control
Referenced objects Behavior profile 4d9cbd14-fc93-4ba3-ac98-5ccac81fbfa6 Not in catalog
Origin User proposal letsgo

Query

1table duration=20m TB_WIN_SECURITY 2| search event_id == "5154" 3| eval addr = lower(trim(nvl(SourceAddress, ""))), port = trim(string(SourcePort)), proto = case(trim(Protocol) == "6", "TCP", trim(Protocol) == "17", "UDP", trim(Protocol)) 4| search not(match(addr, "^(127\\.|::1$|0:0:0:0:0:0:0:1$|::ffff:127\\.)")) 5| search not(matchbehavior("4d9cbd14-fc93-4ba3-ac98-5ccac81fbfa6", host_ip, proto, port)) 6| eval proc = nvl(image, "-"), p = nvl(trim(ProcessId), "-") 7| stats count as listen_count, min(_time) as first_time, max(_time) as last_time, values(computer) as computer, values(addr) as listen_addr, values(proc) as process, values(p) as pid by host_ip, proto, port 8| eval computer = strjoin(", ", computer), listen_addr = strjoin(", ", listen_addr), process = strjoin(", ", process), pid = strjoin(", ", pid) 9| eval first_time = string(first_time, "yyyy-MM-dd HH:mm:ss"), last_time = string(last_time, "yyyy-MM-dd HH:mm:ss") 10| fields host_ip, computer, proto, port, listen_addr, process, pid, listen_count, first_time, last_time

5분마다 직전 20분의 Windows 보안 이벤트 로그를 조회하여 Windows 필터링 플랫폼의 접속 대기 허용 기록(5154)을 찾습니다. 대기 주소가 Loopback이면 제외하고, 서버 IP·프로토콜(TCP·UDP)·포트 조합이 행위 프로파일 'WIN 서버별 평소 LISTEN 포트'에 없으면 탐지합니다. 서버 IP·프로토콜·포트별로 집계하여 대기 주소(listen_addr), 포트를 연 프로세스(process)와 프로세스 ID를 제공합니다. 5154는 감사 정책의 '필터링 플랫폼 연결' 감사가 켜져 있어야 기록됩니다. 같은 서버·프로토콜·포트의 탐지는 1시간 동안 티켓 하나로 축약합니다.

참조 행위 프로파일 'WIN 서버별 평소 LISTEN 포트'(프로파일 ID 4d9cbd14-fc93-4ba3-ac98-5ccac81fbfa6, 키 필드 host_ip, proto, port)은 매일 0시 40분(40 0 * * *)에 아래 쿼리로 갱신합니다. 서버별로 최근 7일(오늘 제외) 동안 접속 대기(5154)가 기록된 프로토콜·포트를 모읍니다. Loopback 대기는 제외합니다. 쿼리의 프로파일 ID는 등록한 환경마다 달라지므로, 프로파일을 먼저 등록한 뒤 쿼리의 ID를 그 값으로 바꿉니다.

table duration=8d TB_WIN_SECURITY
| search event_id == "5154" and _time < datetrunc(now(), "1d")
| eval addr = lower(trim(nvl(SourceAddress, ""))), port = trim(string(SourcePort)), proto = case(trim(Protocol) == "6", "TCP", trim(Protocol) == "17", "UDP", trim(Protocol))
| search not(match(addr, "^(127\\.|::1$|0:0:0:0:0:0:0:1$|::ffff:127\\.)"))
| stats count as listens, max(_time) as last_seen, values(image) as images by host_ip, proto, port
| eval images = strjoin(", ", images)

Threat analysis

서버에 새 대기 포트가 열리는 것은 새 서비스가 설치됐거나 백도어·바인드 셸·터널 도구·프록시가 실행됐다는 뜻입니다. 서버는 용도가 정해져 있어 대기 포트 구성이 거의 바뀌지 않으므로, 기준선에 없는 포트는 무엇이 열었는지 확인할 가치가 있습니다. 포트를 연 프로세스가 임시 폴더나 사용자 폴더의 실행 파일이면 우선 조사합니다.

False positives

RPC 동적 포트처럼 실행할 때마다 포트 번호가 바뀌는 서비스, 새로 설치한 소프트웨어, 일시적으로 포트를 여는 관리 도구가 탐지됩니다. 임시 포트 대역(49152 이상)의 탐지가 많으면 프로세스 기준 예외 조건을 추가하거나 대상 포트 범위를 조정합니다. 프로파일이 7일분 쌓이기 전에는 탐지 건수가 많을 수 있습니다.

Response actions

포트를 연 프로세스의 실행 경로·서명·생성 시점을 확인합니다. 승인된 서비스가 아니면 프로세스를 종료하고 실행 파일을 확보하여 분석하며, 그 포트로 들어온 연결(5156)의 출발지를 조회합니다. 방화벽에서 해당 포트의 인바운드를 차단하고, 프로세스가 등록된 경위(서비스 설치, 예약 작업)를 조사합니다.

No comments yet.