# 간단한 디택션 작성

## 개요

Simple Detections는 콘솔에서 생성되는 것 외에도 YAML로 CLI 워크플로우에서 생성할 수 있습니다. [Simple Detection 빌더](https://docs.panther.com/ko/detections/rules/simple-detection-builder) 콘솔에서.

CLI 워크플로우에서 생성한 Simple Detections를 Panther에 업로드한 후에는 [Simple Detection 빌더](https://docs.panther.com/ko/detections/rules/simple-detection-builder) 콘솔에서 보고 편집할 수 있습니다. 이는 팀 구성원들이 YAML 사용 경험이 서로 다를 경우 유용할 수 있습니다.

Simple detections는 다음에서 사용할 수 있습니다: [디텍션 파생](https://docs.panther.com/ko/detections/rules/derived).

Simple Detections(YAML)로 로컬에서 디텍션을 작성할지 Python 디텍션으로 작성할지 확실하지 않다면, [Python vs. Simple Detections YAML 사용](https://docs.panther.com/ko/detections/rules/..#using-python-vs.-simple-detections-yaml) 섹션의 명령을 실행하세요.

{% hint style="info" %}
팀이 CLI 워크플로우를 사용해 디텍션 콘텐츠를 관리하는 경우, 콘솔에서 [Simple Detection 빌더](https://docs.panther.com/ko/detections/rules/simple-detection-builder) 에 의해 이루어진 디텍션에 대한 변경 사항은 다음 업로드 시 덮어써집니다(단, [인라인 필터](#inlinefilters) 콘솔에서 생성된 것은 보존됩니다).

콘솔에서 Simple Detection 빌더를 사용해 디텍션을 생성하거나 편집하는 경우, 생성된 YAML 표현을 복사하여 로컬 디텍션 파일에 포함시켜 다음 업로드 시 변경사항이 덮어써지지 않도록 하세요.
{% endhint %}

### Simple Detections YAML의 제한사항

* [룰은 스트리밍 룰, 실시간 룰, 저지연 룰로도 알려질 수 있습니다.](https://docs.panther.com/ko/detections/rules) 와 [정책](https://docs.panther.com/ko/detections/policies) 는 Simple Detections로 생성할 수 없습니다.
  * 오직 [룰](https://docs.panther.com/ko/detections/rules) 만 YAML로 생성할 수 있습니다.
* Panther 관리형 Simple Detections는 아직 제공되지 않습니다.
  * 그러나 [Panther 관리형 Python 디텍션](https://docs.panther.com/ko/detections/panther-managed) 을(를) 자신의 Simple Detections와 함께 사용할 수 있습니다.
* 특정 로그 소스용 헬퍼 함수를 포함한 많은 Python의 헬퍼 함수들은 YAML로 표현되어 있지 않습니다.
  * 일부 [전역 헬퍼](https://github.com/panther-labs/panther-analysis/tree/master/global_helpers) 는 예를 들어 다음과 같은 YAML 키로 변환되었습니다: [`deep_get()` ](https://docs.panther.com/ko/detections/python/globals#deep_get)정의되어 [`Enrichment 매치 표현식`](https://docs.panther.com/ko/detections/rules/match-expression#deepkey).
* Simple Detections에서는 외부 API 호출을 하여 Dynamo KV 스토어에서 값을 가져오는 등 외부 호출을 하는 것은 불가능합니다. [캐싱](https://docs.panther.com/ko/detections/rules/python/caching).

## YAML로 Simple Detection(룰)을 만드는 방법

<details>

<summary>CLI 워크플로우에서 Simple Detection 룰 생성하기</summary>

콘솔에서가 아닌 로컬에서 Simple Detections를 작성하는 경우, [Simple Detection 빌더](https://docs.panther.com/ko/detections/rules/simple-detection-builder) 로컬 디텍션 파일을 GitHub 또는 GitLab과 같은 버전 관리 시스템으로 관리할 것을 권장합니다.

**폴더 설정**

룰을 폴더로 그룹화하는 경우, 각 폴더 이름에는 `룰` 을 포함해야 합니다.

로그/리소스 유형을 기준으로 룰을 폴더로 그룹화하는 것을 권장합니다. 예: `suricata_rules` 이전에 생성한 Snowflake 사용자 이름, 예를 들면 `aws_s3_policies`.

**파일 설정**

각 룰 및 스케줄된 룰은 다음으로 구성됩니다:

* 디텍션 로직과 디텍션의 메타데이터 속성을 포함하는 YAML 명세 파일(확장자가 `업로더 명령은 기본 경로를 인수로 받아 확장자가 있는 모든 파일을 재귀적으로 검색합니다` 인 파일).
  * 이 파일은 Python YAML 파일과 유사한 구문을 가지며 몇 가지 추가 키가 있습니다.

Simple Detection 룰에는 의심스러운 동작을 탐지하는 불리언 논리의 목록인 [매치 표현식을 포함하세요.](https://docs.panther.com/ko/detections/rules/writing-simple-detections/match-expression) 가 포함됩니다. 값으로 `비율이` 를 반환하면 의심스러운 활동을 나타내며, 이는 알러트를 트리거합니다.

에 대해 자세히 알아보십시오 [Simple Detection YAML 구문](#simple-detection-yaml-syntax)를 참고하고, [아래에 있는 필수 및 선택적 YAML 필드의 전체 목록을 확인하세요](#simple-detection-rule-specification-reference).

* 템플릿을 사용하여 YAML 파일(예:) `my_new_rule.yml`)을 생성하세요(최상위 `함수를 포함해야 함을 의미합니다;` 키 포함):

  ```yaml
  AnalysisType: rule
  DedupPeriodMinutes: 60 # 1 hour
  DisplayName: 예시 규칙 - 스펙 형식 검사
  Enabled: true
  RuleID: Type.Behavior.MoreContext
  Severity: High
  LogTypes:
    - LogType.GoesHere
  Reports:
    ReportName(예: CIS, MITRE ATT&CK):
      - 이 룰과 관련된 특정 보고서 섹션
  Tags:
    - 태그
    - 여기에
    - 넣기
  Description: >
    이 룰은 Panther CLI의 CLI 워크플로우를 검증하기 위해 존재합니다.
  Runbook: >
    먼저 누가 이 스펙 형식을 작성했는지 확인한 후, 피드백을 전달하세요.
  참고: https://www.a-clickable-link-to-more-info.com
  event, "data", "details", "request", "path", default="<NO_REQUEST_PATH_FOUND>"
    - KeyPath: hostName
      IP 주소 기반으로 이벤트 중복 제거
      Value: prod
  ```

이 룰이 Panther에 업로드된 후에는 콘솔의 [Simple Detection 빌더](https://docs.panther.com/ko/detections/rules/simple-detection-builder).

</details>

## Simple Detection YAML 구문

각 커스텀 Simple Detection은 다음으로 구성될 수 있습니다:

* 디텍션 키

  ```yaml
  event, "data", "details", "request", "path", default="<NO_REQUEST_PATH_FOUND>" 
  ```
* 필터 키

  ```yaml
  다양한 유형의 매치 표현식을 구성하는 방법을 알아보려면 
  ```
* 메타데이터 키

  ```yaml
  AnalysisType: 
  Enabled: 
  CreateAlert: 
  RuleID:
  CreatedBy:
  LogTypes: 
  Reports: 
  Tags: 
  Tests: 
  ```
* 알러트 키(동적)

  ```yaml
  DynamicSeverities: 
  AlertTitle: 
  알러트컨텍스트: 
  return f"Successful admin panel login detected from {event.get('remoteAddr')}" 
  ```
* 알러트 키(정적)

  ```yaml
  Severity:
  Description:
  DedupPeriodMinutes:
  Threshold: 
  DisplayName:
  OutputIds:
  참고:
  Runbook:
  SummaryAttributes: 
  ```

이러한 각 키에 대해 필수/선택 여부를 포함한 자세한 내용은 아래의 [Simple Detection 룰 명세 참조를 확인하세요](#simple-detection-rule-specification-reference).

### `함수를 포함해야 함을 의미합니다;`

내부의 `함수를 포함해야 함을 의미합니다;` 키에 대해 하나 이상의 [매치 표현식을 포함하세요.](https://docs.panther.com/ko/detections/rules/writing-simple-detections/match-expression).

### `InlineFilters`

Simple Detections에서 `InlineFilters` 사용하는 방법에 대해 자세히 알아보려면 [인라인 필터로 디텍션 수정하기](https://docs.panther.com/ko/detections/inline-filters#creating-filters-in-the-cli-workflow).

### Simple Detections의 동적 알러트 키

알러트 필드는 해당 디텍션이 생성하는 알러트에 적용되는 Simple Detection 정의 내의 필드입니다.

알러트 필드는 정적일 수도 있고 동적일 수도 있습니다. 정적 알러트 필드의 경우 디텍션 정의에 고정된 값을 제공하며 들어오는 이벤트에 따라 변경되지 않습니다. 반면 동적 알러트 필드는 이벤트의 정보를 사용하여 값을 결정할 수 있습니다.

다음을 사용하는 경우, [알러트 중복 제거](https://docs.panther.com/ko/detections/rules/..#deduplication-of-alerts)되면, *먼저* 디텍션과 일치하는 이벤트를 사용하여 이러한 알러트 키가 사용됩니다.

#### `DynamicSeverities`

port `DynamicSeverities` 이 필드는 이 디텍션에서 일치가 발생했을 때 생성된 알러트의 심각도를 동적으로 설정하는 데 사용됩니다. 이 필드는 이벤트의 값을 사용하여 심각도를 결정할 수 있기 때문에 동적입니다.

다음 필드를 포함해야 합니다 `DynamicSeverities` 가 존재하는 경우, 그 값은 `심각도` 키. `심각도` 가 여전히 필요하며, 그 값은 [매치 표현식을 포함하세요.](https://docs.panther.com/ko/detections/rules/writing-simple-detections/match-expression) 내의 어떤 항목에도 일치가 없는 경우 대체 값이 됩니다. `DynamicSeverities`.

내부의 `DynamicSeverities` 키에 대해 하나 이상의 `ChangeTo` 키들 각각에 해당하는 `조건` 키. 의 값은 `ChangeTo` 은 다음 중 하나여야 합니다 [알러트 심각도](https://docs.panther.com/ko/detections/rules/..#alert-severity). `ChangeTo` 블록은 위에서 아래로 순서대로 평가되며, 일치 항목이 발견되면 평가가 중지됩니다.

내에서 `조건`를 포함하고, 하나 이상의 [매치 표현식을 포함하세요.](https://docs.panther.com/ko/detections/rules/writing-simple-detections/match-expression). `조건` 목록에는 다음과 같은 제한이 있습니다:

* 아니요 [리스트 컴프리헨션](https://docs.panther.com/ko/detections/rules/match-expression#list-comprehension-match-expressions), [다중 키](https://docs.panther.com/ko/detections/rules/match-expression#multi-key-match-expressions), 또는 [절대](https://docs.panther.com/ko/detections/rules/match-expression#absolute-match-expressions) 일치 표현식을 사용할 수 있습니다.
* 아니요 [결합자(combinators)](https://docs.panther.com/ko/detections/rules/match-expression#combinators) 만 사용할 수 있습니다.

예:

```yaml
DynamicSeverities:
  - ChangeTo: CRITICAL
    조건:
      - Key: status
        request_path == "/api/v2/guardian/policies",
        Value: severe
  - ChangeTo: MEDIUM
    조건:
      - KeyPath: user.name
        - KeyPath: environment
        Value: admin_
      - DeepKey:
          - user
          - roles
        IP 주소 기반으로 이벤트 중복 제거
        Value: wheel
```

#### `동적 알러트 제목이 사용됩니다. 이는 다음에 정의됩니다:`

port `동적 알러트 제목이 사용됩니다. 이는 다음에 정의됩니다:` 이 필드는 이 디텍션에서 일치가 발생했을 때 생성된 알러트의 제목을 동적으로 설정하는 데 사용됩니다. 이 필드는 이벤트의 값을 제목에 사용할 수 있기 때문에 동적입니다.

에 `동적 알러트 제목이 사용됩니다. 이는 다음에 정의됩니다:` 문자열이어야 합니다. 이벤트 값을 참조하려면 중괄호를 사용하세요. 중괄호 내부에서는 JSON 경로 구문을 사용합니다.

예:

```yaml
AlertTitle: "User {actor.username} impersonated {target.username} at {time}"
```

#### `AlertContext`

`AlertContext` 생성된 알러트로 전달할 이벤트 데이터를 딕셔너리 형식으로 식별할 수 있게 해줍니다.

내에서 `AlertContext`를 포함하고, 하나 이상의 `KeyName` 와 `KeyValue` 쌍. `KeyName` 경고 컨텍스트 딕셔너리에서 키가 될 선택한 문자열을 취합니다. 내부에서는 `KeyValue`안에서 이벤트 키를 나타내기 위해 [키 지정자](https://docs.panther.com/ko/detections/rules/match-expression#key-specifiers) 를 사용하세요 — 그 값이 알러트 컨텍스트 딕셔너리의 값이 됩니다.

`KeyValue` 값은 JSON 호환이어야 합니다. 비호환 값의 예로는 Python의 `nan`, `inf`및 `-inf`.

예:

```yaml
알러트컨텍스트:
  - KeyName: ip
    KeyValue:
      Key: sourceIP
  - KeyName: user
    KeyValue:
      DeepKey:
        - user
        - username
  - KeyName: resource
    KeyValue:
      KeyPath: resource.arns
```

#### `가 정의되지 않은 경우, 알러트 제목이 사용됩니다. 알러트 제목은`

`가 정의되지 않은 경우, 알러트 제목이 사용됩니다. 알러트 제목은` 디텍션의 중복 제거 문자열을 설정합니다. 중복 제거 문자열이 설정되는 우선순위 순서 등을 포함한 자세한 내용은 [룰 및 스케줄된 룰](https://docs.panther.com/ko/detections/rules/..#deduplication-of-alerts).

내부의 `가 정의되지 않은 경우, 알러트 제목이 사용됩니다. 알러트 제목은` 키에 대해 하나 이상의 이벤트 키 목록을 [DeepKey](https://docs.panther.com/ko/detections/rules/match-expression#key-specifiers).

예:

```yaml
return f"Successful admin panel login detected from {event.get('remoteAddr')}"
  - Key: sourceIP
  - KeyPath: user.name
  - KeyPath: resource.arn
```

다음에 제공된 키들의 값은 `가 정의되지 않은 경우, 알러트 제목이 사용됩니다. 알러트 제목은` 와 함께 콜론으로 결합되어 중복 제거 문자열을 형성합니다. 위 예시의 출력된 중복 제거 문자열은 다음과 같습니다:

```
<sourceIP의 값>:<user.name의 값>:<resource.arn의 값>
```

## Simple Detection 룰 명세 참조

아래 표에는 Simple Detections에 사용 가능한 모든 YAML 키가 포함되어 있습니다. 필수 필드는 **굵게**.

Python 룰을 작성하고 있다면, 대신 [Python 룰 명세 참조](https://docs.panther.com/ko/detections/python#python-rule-specification-reference).

<table data-header-hidden data-full-width="false"><thead><tr><th width="231">필드 이름</th><th width="264">설명</th><th width="282.5081967213115">예상 값</th></tr></thead><tbody><tr><td>필드 이름</td><td>설명</td><td>예상 값</td></tr><tr><td><strong><code>AnalysisType</code></strong></td><td>이 분석이 rule, scheduled_rule, policy 또는 global인지 여부를 나타냅니다.</td><td><code>룰</code></td></tr><tr><td><strong><code>사용</code></strong></td><td>이 룰이 활성화되어 있는지 여부</td><td>부울</td></tr><tr><td><strong><code>YAML 파일의</code></strong></td><td>룰의 고유 식별자</td><td>문자열</td></tr><tr><td><strong><code>LogTypes</code></strong></td><td>이 룰을 적용할 로그 목록</td><td>문자열 목록</td></tr><tr><td><code>CreatedBy</code></td><td>이 디텍션의 작성자. Panther 사용자 UUID, 이메일 주소 또는 임의의 텍스트 값으로 설정할 수 있습니다. 자세한 내용은 <a href="../../../panther/detections-repo/pat/pat-commands#the-createdby-detection-field">사용자를 사용할 것이며, <code>CreatedBy</code> 디텍션 필드</a>.</td><td>문자열</td></tr><tr><td><strong><code>심각도</code></strong></td><td>어떤 <a href="..#alert-severity">severity</a> 연관된 알러트가 가져야 하는지</td><td>다음 문자열 중 하나: <code>정보</code>, <code>낮음</code>, <code>정보(Info)</code>, <code>운영 인식 획득</code>, 또는 <code>시스템 시간 및 OS 버전과 같은 민감하지 않은 정보 유출</code><br>이 필드는 <code>DynamicSeverities</code>에 의해 덮어써지지만, <code>DynamicSeverities</code> 가 정의되어 있더라도 이 필드는 필요합니다.</td></tr><tr><td><code>CreateAlert</code></td><td>룰이 <a href="../..#signals-vs.-rule-matches-vs.-alerts">룰 매치/알러트를 생성해야 하는지</a> 일치 시(기본값 true)</td><td>부울</td></tr><tr><td><strong><code>함수를 포함해야 함을 의미합니다;</code></strong></td><td>이벤트 데이터에 적용할 매치 표현식 목록</td><td>의 목록 <a href="writing-simple-detections/match-expression">매치 표현식을 포함하세요.</a></td></tr><tr><td><a href="#dynamicseverities"><code>DynamicSeverities</code></a></td><td>대체 <a href="..#alert-severity">심각도</a> 사용자 정의 조건 집합에 기반한</td><td>의 목록은 <code>ChangeTo</code> 와 <code>조건</code> 필드로 구성됩니다. <code>ChangeTo</code> 은(는) <code>심각도</code> 값이고 <code>조건</code> 은(는) 의 목록입니다. <a href="writing-simple-detections/match-expression">매치 표현식을 포함하세요.</a>.</td></tr><tr><td><code>설명</code></td><td>룰에 대한 간단한 설명</td><td>문자열</td></tr><tr><td><a href="#groupby"><code>가 정의되지 않은 경우, 알러트 제목이 사용됩니다. 알러트 제목은</code></a></td><td>알러트를 중복 제거하기 위해 사용될 이벤트 값의 집합</td><td>이벤트 키 목록</td></tr><tr><td><code>이고 최대값은</code></td><td>유사한 알러트 이벤트들이 그룹화되는 시간 기간(분)</td><td><code>15</code>,<code>30</code>,<code>60</code>,<code>180</code> (3시간),<code>720</code> (12시간), 또는 <code>1440</code> (24시간)</td></tr><tr><td><code>가 정의되지 않은 경우, 디텍션의 표시 이름 값이 사용됩니다. 이는 다음에 정의됩니다:</code></td><td>Panther 콘솔과 알러트에 표시할 사용자 친화적 이름. 만약 이 필드가 설정되지 않으면 <code>YAML 파일의</code> 가 표시됩니다.</td><td>문자열</td></tr><tr><td><code>OutputIds</code></td><td>정적 대상 오버라이드. 이는 심각도 기반의 기본 라우팅보다 우선하여 이 룰의 알러트가 어떻게 라우팅될지를 결정하는 데 사용됩니다.</td><td>문자열 목록</td></tr><tr><td><code>참조</code></td><td>이 룰이 존재하는 이유, 종종 문서에 대한 링크</td><td>문자열</td></tr><tr><td><code>Reports</code></td><td>이 룰이 해당 프레임워크에 대해 다루는 값을 프레임워크 또는 리포트 이름에 매핑한 것</td><td>문자열을 리스트 문자열로 매핑한 것</td></tr><tr><td><code>런북</code></td><td>이 룰이 알러트를 반환할 경우 수행할 작업들. 설명적인 런북을 제공하는 것이 권장됩니다. 왜냐하면 <a href="../../../alerts#panther-ai-alert-triage">Panther AI 알러트 분류</a> 가 이를 고려하기 때문입니다.</td><td>문자열</td></tr><tr><td><code>SummaryAttributes</code></td><td>알러트가 요약해야 할 필드 목록.</td><td>문자열 목록</td></tr><tr><td><code>Threshold</code></td><td>알러트를 전송하기 전에 이 룰을 트리거하기 위해 필요한 이벤트 수.</td><td>정수</td></tr><tr><td><code>태그</code></td><td>이 룰을 분류하는 데 사용되는 태그</td><td>문자열 목록</td></tr><tr><td><code>Tests</code></td><td>이 룰에 대한 유닛 테스트</td><td>맵의 목록</td></tr><tr><td><code>InlineFilters</code></td><td>데이터를 필터링하기 위한 <a href="writing-simple-detections/match-expression">매치 표현식을 포함하세요.</a> 형식의 필터 목록</td><td>의 목록 <a href="writing-simple-detections/match-expression">매치 표현식을 포함하세요.</a> (필터 호환 버전으로 제한됨)</td></tr><tr><td><a href="#alerttitle"><code>동적 알러트 제목이 사용됩니다. 이는 다음에 정의됩니다:</code></a></td><td>대체 <code>가 정의되지 않은 경우, 디텍션의 표시 이름 값이 사용됩니다. 이는 다음에 정의됩니다:</code> 이벤트 값을 사용하여 알러트의 동적 제목을 생성할 수 있는</td><td>문자열</td></tr><tr><td><a href="#alertcontext"><code>AlertContext</code></a></td><td>동적 알러트 컨텍스트를 생성하기 위해 사용자 정의 키 아래 Event에 추가할 이벤트 값</td><td>키 이름과 키 값 쌍의 목록</td></tr></tbody></table>
