# VPC 로그 쿼리

이 페이지에는 VPC Flow 로그 및 VPC DNS 로그에 대한 예제가 포함되어 있습니다.

## VPC Flow Logs 쿼리

### SSH 및 RDP에 대한 VPC Flowlog 활동 표시

원격 셸에는 일반적으로 한쪽 끝에 사람이 있습니다. 조사 중에는 SSH 및 RDP 세션을 분리하는 것이 특정 행위자 활동을 식별하기 위한 표준 절차인 경우가 많습니다.

```sql
SELECT
 *
FROM panther_logs.public.aws_vpcflow
WHERE
  p_occurs_between('2021-01-01', '2021-01-02')
  AND
  (srcport IN (22, 3389) OR dstport IN (22, 3389))
ORDER BY p_event_time ASC
LIMIT 100
```

### IP 주소에 대한 VPC Flowlog 활동 표시

조사 중에는 종종 특정 IP 주소가 관심 대상으로 식별됩니다(예: 알려진 명령 및 제어 노드). IP 주소의 역할이 식별되면 해당 활동을 분리하고 설명하는 것이 중요합니다. 이를 통해 어떤 리소스가 침해되었을 가능성이 있는지 파악할 수 있습니다.

```sql
SELECT
 *
FROM panther_logs.public.aws_vpcflow
WHERE p_occurs_between('2021-01-01', '2021-01-02')
     AND array_contains('1.2.3.4'::variant, p_any_ip_addresses)
ORDER BY p_event_time ASC
LIMIT 100
```

### 콘솔 로그인 수행과 관련된 CloudTrail sourceIPAddresses에 대한 VPC Flowlog 활동 표시

자격 증명 유출이 우려되는 경우 모든 AWS 콘솔 활동을 파악하는 것이 매우 중요합니다. 이 쿼리는 콘솔 로그인에 관련된 모든 CloudTrail sourceIPaddresses를 찾은 다음, 관련된 모든 VPC Flow 활동을 반환합니다. 이를 통해 공통 IP 주소가 있는지 확인할 수 있습니다. 특히 관심 대상은 다음과 같은 IP 주소입니다. **조직 외부에서** 인스턴스와 통신하는 동시에 콘솔에 로그인하는 경우입니다. 이는 승인되지 않은 행위자가 계정 리소스에 접근하고 있음을 의미하는 침해일 수 있습니다.

```sql
WITH cloudTrailIPs as
(SELECT
  DISTINCT sourceIPAddress AS ip
 FROM panther_logs.public.aws_cloudtrail
 WHERE
    p_occurs_between('2021-01-01', '2021-01-02')
    AND
    eventtype = 'AwsConsoleSignIn'
)
SELECT
 *
FROM  cloudTrailIPs ips JOIN panther_logs.public.aws_vpcflow flow ON (ips.ip = flow.srcaddr OR ips.ip = flow.dstaddr)
WHERE
  p_occurs_between('2021-01-01', '2021-01-02')
ORDER BY p_event_time ASC
LIMIT 100
```

## **VPC DNS 쿼리 예제**

{% hint style="info" %}
아래 쿼리는 [VPC DNS 로그](/ko/data-onboarding/supported-logs/aws/vpc.md#vpc-dns-logging)용이지만, 다른 DNS 로그에도 적용할 수 있습니다.
{% endhint %}

### **지난 1주일 동안 쿼리가 가장 많은 소스**

{% code overflow="wrap" %}

```sql
SELECT 
    srcids:instance, COUNT(*) 
FROM 
    panther_logs.public.aws_vpcdns 
WHERE 
    p_occurs_since(1w) 
GROUP BY 1 
LIMIT 100
```

{% endcode %}

### **지난 4주 동안의 희귀 쿼리**

{% code overflow="wrap" %}

```sql
-- 지난 4주 동안의 희귀 쿼리
SELECT 
    query_name, COUNT(*) as total
FROM  
    panther_logs.public.aws_vpcdns
WHERE 
    p_occurs_since(4w)
GROUP BY 1
ORDER BY 2
LIMIT 100
```

{% endcode %}

### **쿼리 목록 표시, AWS 내부 쿼리 제거**

```sql
-- 쿼리 목록
SELECT
    p_event_time, srcids, query_name, query_type, rcode
FROM
    panther_logs.public.aws_vpcdns
WHERE 
    -- AWS 내부 쿼리 제거
    not query_name LIKE ANY ('%amazonaws.com.', '%.compute.internal.')
LIMIT 10

```

### **상위 10개 TLD를 분리하여 나열**

```sql
-- 상위 10개 최상위 도메인 집계
SELECT
    split_part(query_name, '.', -2) as TLD, count(*) as total
FROM
    panther_logs.public.aws_vpcdns
GROUP by 1
ORDER BY 2 desc
LIMIT 10
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.panther.com/ko/search/data-explorer/example-queries/vpc-flow-logs-queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
