[ About Nuclei Template ]
Nuclei Template은 Nuclei 엔진이 사용하는 점검 파일로 HTTP, Headless, Network, DNS, File, Javascript, Code, Flow, Multi-protocol 등과 같은 다양한 프로토콜을 지원한다. Template은 Yaml 확장자를 가진다.
[ YAML (YAML Ain't Markup Language) ]
Nuclei는 YAML 기반 템플릿 파일을 기반으로 PoC/Exploit 코드를 작성하는 시간을 줄이고, 여러 취약점을 빠르고 손쉽게 점검 가능하고, 가독성이 좋다.
[ Nuclei Template Structure ]
Nuclei Template은 사용자 지정 YAML 기반 DSL을 사용하며, 사용된 프로토콜에 따라 구조가 달라진다. 일반적인 구성 요소는 다음과 같다.
- Template ID
- Template 관련 Information & Metadata
- 지원하는 Protocols
(ex. HTTP, Headless, DNS, File, Javascript, Code, Flow etc..) - HTTP Protocol에서 수행된 요청과 같이 선택한 Protocol 관련 세부 정보
- 결과의 존재를 확인하기 위한 일련의 Matchers
- 결과에서 데이터를 검색하는 데 필요한 extractors
[ Details ]
1) ID
Template의 ID를 지정하는 부분. 공백이 없어야 함
id: git-config
2) Information & MetaData
Information 블록에서는 name, author, severity, description, reference, tags 등 템플릿에 대한 정보를 작성한다.
info:
name: Git Config File Detection Template
author: Ice3man
severity: medium
description: Searches for the pattern /.git/config on passed URLs.
reference: https://www.acunetix.com/vulnerabilities/web/git-repository-found/
tags: git,config
Metadata 블록은 해당 취약점에 영향을 받는 서비스를 찾기 위한 shodan 구문 등의 여러 검색 엔진을 연결하는 툴인 uncover을 지원하는 블록이다.
info:
metadata:
shodan-query: 'vuln:CVE-2021-26855'
3) Protocol
- HTTP : 기본적인 요청을 수행하는 URL 형태(Method 형태)의 요청, Raw HTTP 요청 그리고 비 RFC 요청도 지원한다.
# URL 형태(method 형태)
http:
- method: GET
path:
- "{{BaseURL}}/login.php"
# Raw HTTP
http:
- raw:
- |
POST /path2/ HTTP/1.1
Host: {{Hostname}}
Content-Type: application/x-www-form-urlencoded
a=test&b=pd
# 비 RFC 요청
http:
- raw:
- |+
POST / HTTP/1.1
Host: {{Hostname}}
Content-Type: application/x-www-form-urlencoded
Content-Length: 150
Transfer-Encoding: chunked
0
GET /post?postId=5 HTTP/1.1
User-Agent: a"/><script>alert(1)</script>
Content-Type: application/x-www-form-urlencoded
Content-Length: 5
x=1
unsafe: true
4) Matchers
Matchers를 통해 다양한 Protocol Response 유형을 유연하게 탐지할 수 있다. 기본적으로 지원하는 Matcher는 다음과 같다.
원하는 Response Status Code만 얻고 싶다면 아래와 같이 "Type"을 사용하면 된다.
# 해석 : HTTP 요청 이후 Response Status Code가 "200", "302"인 경우만 체크 (정탐)
matchers:
- type: status
status:
- 200
- 302
dsl matcher을 사용하면 더 정교한 탐지도 가능하다.
matchers:
- type: dsl
dsl:
- "len(body)<1024 && status_code==200" # Body Length가 1024 미만이고 status_code가 200인 경우만 체크
- "contains(toupper(body), md5(cookie))" # cookie값을 md5시킨 값이 body에 포함되어있는 경우만 체크
- DSL Matcher Example
- 조건 구문
matcher는 여러 단어를 지정 가능하며 AND, OR과 같은 다양한 조건으로 구성하여 오탐율을 낮출 수 있다.- AND : matcher 목록에서 모든 단어가 일치하면 정탐으로 간주
- OR : matcher 목록에서 단일 단어가 응답에 존재하면 정탐으로 간주
matchers:
- type: word
words:
- "[core]"
- "[config]"
condition: and
part: body