CloudWatch Logs Insights를 사용하여 사용자 지정 Amazon VPC 흐름 로그를 분석하려면 어떻게 해야 합니까?

7분 분량
0

Amazon Virtual Private Cloud(Amazon VPC) 흐름 로그를 사용하여 사용자 지정 VPC 흐름 로그를 구성했습니다. Amazon CloudWatch 로그 Amazon CloudWatch Logs Insights를 사용하여 로그 내의 패턴과 추세를 알아보고 싶습니다.

간략한 설명

CloudWatch Logs Insights는 기본 형식의 흐름 로그는 자동으로 검색하지만 사용자 지정 형식의 흐름 로그는 자동으로 검색하지 않습니다.

사용자 지정 형식의 흐름 로그와 함께 CloudWatch Logs Insights를 사용하려면 쿼리를 수정해야 합니다.

다음은 사용자 지정 흐름 로그 형식의 예입니다.

${account-id} ${vpc-id} ${subnet-id} ${interface-id} ${instance-id} ${srcaddr} ${srcport} ${dstaddr} ${dstport} ${protocol} ${packets} ${bytes} ${action} ${log-status} ${start} ${end} ${flow-direction} ${traffic-path} ${tcp-flags} ${pkt-srcaddr} ${pkt-src-aws-service} ${pkt-dstaddr} ${pkt-dst-aws-service} ${region} ${az-id} ${sublocation-type} ${sublocation-id}

다음 쿼리는 사용 사례에 맞게 쿼리를 사용자 지정하고 확장하는 방법의 예입니다.

해결 방법

최신 흐름 로그 검색

로그 필드에서 데이터를 추출하려면 parse 키워드를 사용합니다. 예를 들어, 다음 쿼리의 출력은 흐름 로그 이벤트 시작 시간을 기준으로 정렬되며 가장 최근 로그 항목 두 개로 제한됩니다.

쿼리

#Retrieve latest custom VPC Flow Logs
parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| sort start desc
| limit 2

출력

account_idvpc_idsubnet_idinterface_idinstance_idsrcaddrsrcport
123456789012vpc-0b69ce8d04278dddsubnet-002bdfe1767d0ddb0eni-0435cbb62960f230e-172.31.0.10455125
123456789012vpc-0b69ce8d04278ddd1subnet-002bdfe1767d0ddb0eni-0435cbb62960f230e-91.240.118.8149422

소스 및 대상 IP 주소 쌍별 데이터 전송 요약

다음 쿼리를 사용하여 소스 및 대상 IP 주소 쌍별로 네트워크 트래픽을 요약할 수 있습니다. 예제 쿼리에서 합계 통계는 바이트 필드를 집계합니다. 합계 통계는 호스트 간에 전송된 데이터의 누적 합계를 계산하므로 flow_direction가 쿼리 및 출력에 포함됩니다. 집계 결과는 Data_Transferred 필드에 임시로 할당됩니다. 그런 다음 Data_Transferred를 기준으로 결과가 내림차순으로 정렬되고 가장 큰 두 쌍이 반환됩니다

쿼리

parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| stats sum(bytes) as Data_Transferred by srcaddr, dstaddr, flow_direction
| sort by Data_Transferred desc
| limit 2

출력

srcaddrdstaddrflow_directionData_Transferred
172.31.1.2473.230.172.154egress346952038
172.31.0.463.230.172.154egress343799447

Amazon EC2 인스턴스 ID별 데이터 전송 분석

사용자 지정 흐름 로그를 사용하여 Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스 ID별로 데이터 전송을 분석할 수 있습니다. 가장 활성 상태인 EC2 인스턴스를 확인하려면 쿼리에 instance_id 필드를 포함시킵니다.

쿼리

parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| stats sum(bytes) as Data_Transferred by instance_id
| sort by Data_Transferred desc
| limit 5

출력

instance_idData_Transferred
-1443477306
i-03205758c9203c979517558754
i-0ae33894105aa500c324629414
i-01506ab9e9e90749d198063232
i-0724007fef3cb06f354847643

거부된 SSH 트래픽 필터

보안 그룹 및 네트워크 액세스 제어 목록(네트워크 ACL)이 거부한 트래픽을 분석하려면 REJECT 필터 작업을 사용합니다. SSH 트래픽에서 거부된 호스트를 식별하려면 대상 포트가 22인 TCP 프로토콜 및 트래픽을 포함하도록 필터를 확장합니다. 다음 예제 쿼리에서는 TCP 프로토콜 6이 사용됩니다

쿼리

parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| filter action = "REJECT" and protocol = 6 and dstport = 22
| stats sum(bytes) as SSH_Traffic_Volume by srcaddr
| sort by SSH_Traffic_Volume desc
| limit 2

출력

srcaddrSSH_Traffic_Volume
23.95.222.129160
179.43.167.7480

특정 소스/대상 쌍에 대한 HTTP 데이터 스트림 분리

데이터의 추세를 분석하려면 CloudWatch Logs Insights를 사용하여 두 IP 주소 사이의 양방향 트래픽을 분리하세요. 다음 쿼리에서 **[“172.31.1.247”,“172.31.11.212”]**는 IP 주소를 소스 또는 대상 IP 주소로 사용하여 흐름 로그를 반환합니다. 필터 문은 VPC 흐름 로그 이벤트를 TCP 프로토콜 6 및 포트 80과 일치시켜 HTTP 트래픽을 격리합니다. 사용 가능한 모든 필드의 하위 집합을 반환하려면 display 키워드를 사용합니다

쿼리

다음 쿼리를 확인합니다.

#HTTP Data Stream for Specific Source/Destination Pair
parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| filter srcaddr in ["172.31.1.247","172.31.11.212"] and dstaddr in ["172.31.1.247","172.31.11.212"] and protocol = 6 and (dstport = 80 or srcport=80)
| display interface_id,srcaddr, srcport, dstaddr, dstport, protocol, bytes, action, log_status, start, end, flow_direction, tcp_flags
| sort by start desc
| limit 2

출력

interface_idsrcaddrsrcportdstaddrdstport프로토콜bytes동작log_status
eni-0b74120275654905e172.31.11.21280172.31.1.247293766.5160876ACCEPTOK
eni-0b74120275654905e172.31.1.24729376172.31.11.212806.97380ACCEPTOK

결과를 막대형 또는 원형 차트로 시각화

CloudWatch Logs Insights를 사용하여 결과를 막대형 또는 원형 차트로 시각화할 수 있습니다. 결과에 bin() 함수가 포함된 경우 쿼리 출력은 타임스탬프와 함께 반환됩니다. 그런 다음 선 또는 누적 영역 그래프로 시계열을 시각화할 수 있습니다.

1분 간격으로 전송된 누적 데이터를 계산하려면 **통계 합계(바이트)를 Data_Trasferred by bin(1m)**로 사용합니다. 이 시각화를 보려면 CloudWatch Logs Insights 콘솔에서 로그시각화 테이블 사이를 전환하세요.

쿼리

parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| filter srcaddr in ["172.31.1.247","172.31.11.212"] and dstaddr in ["172.31.1.247","172.31.11.212"] and protocol = 6 and (dstport = 80 or srcport=80)
| stats sum(bytes) as Data_Transferred by bin(1m)

출력

bin(1m)Data_Transferred
2022-04-01 15:23:00.00017225787
2022-04-01 15:21:00.00017724499
2022-04-01 15:20:00.0001125500
2022-04-01 15:19:00.000101525
2022-04-01 15:18:00.00081376

관련 정보

지원되는 로그 및 검색된 필드

CloudWatch Logs Insights 쿼리 구문

AWS 공식
AWS 공식업데이트됨 10달 전