Quick Wins
OSINT:
nuclei -tags osint -var user=<USERNAME> -esc
Templates
Structure
Cấu trúc cơ bản của một template bao gồm:
- Template ID
- Template info
- Dữ liệu cần gửi đến remote host
- Các chỉ dẫn phân tích phản hồi
Ví dụ:
id: htpasswd
info:
name: Detect exposed .htpasswd files
author: geeknik
severity: info
tags: config,exposure
requests:
- method: GET
path:
- "{{BaseURL}}/.htpasswd"
matchers-condition: and
matchers:
- type: word
words:
- ":{SHA}"
- ":$apr1$"
- ":$2y$"
condition: or
- type: status
status:
- 200
Request
Request trên dùng raw mode (truyền vào raw request). Thay vì vậy, ta có thể specify các thành phần của một request thông qua các cặp key value của YML:
- method: GET
path:
- "{{BaseURL}}"
headers:
x-php-debug: 1
redirects: true
Variables
Một số global variable: {{Hostname}}
, {{Scheme}}
, {{BaseURL}}
.
User-defined variable:
requests:
- raw:
- |
GET / HTTP/1.1
Host: {{Hostname}}
X-{{fuzz}}-debug: 1
redirects: true
attack: batteringram
payloads:
fuzz: /var/tmp/fuzz.txt
Payloads
Ta cũng có thể dùng payloads ở dạng list:
payloads:
fuzz:
- abc
- def
- test
- xyz
- php
- derp
Attack Modes
Có nhiều attack mode: Batteringram (1 list - 1 injection point), Pitchfork (n list - n injection point) và Clusterbomb (n list - m injection point - n x m combinations).
Matcher
Giả sử ta muốn tìm các response có sensitive data và baseline request có kích thước là 109 bytes:
Ta sẽ viết matcher để match với các response có size lớn hơn 109 bytes:
stop-at-first-match: false
matchers:
- type: dsl
dsl:
- "len(body) > 109"
Matcher có type
là word
sẽ được dùng để exact match với chuỗi có trong response;
matchers:
- type: word
words:
- "Array"
- "[HTTP_AUTHORIZATION]"
Template Clustering
Kỹ thuật mà Nuclei sử dụng để tối ưu hóa việc gửi request:
The Nuclei engine uses “template clustering” to optimize the number of requests sent to a target and reduce network traffic. A basic example of how this works is if a scan contains 5 individual templates that need to make a GET request to the path /login.php, then instead of making 5 separate GET requests to that URL, it will make one request and the 5 individual templates can process the results of that request.
Filtering Templates
Không nên sử dụng tất cả các templates vì nó có thể làm chậm quá trình quét.
Ta có thể dùng option -as
(automatic selection):
This option attempts to fingerprint the technology stack and components used on the target, then select templates that have been tagged with those tech stack keywords.
Option -t
có thể nhận vào một file có chứa các đường dẫn tương đối đến các folder có chứa template trong thư mục nuclei-templates
:
user@kali:~/nuclei-templates$ cat template-categories.txt
file/logs
exposures/files
cves/2021
user@kali:~/nuclei-templates$ nuclei -u https://my.target.site -t template-categories.txt
Lọc theo các tags và severity:
nuclei -u https://jira.targetdomain.site -tags jira,generic
nuclei -u https://jira.targetdomain.site -s critical,high,medium,low,info
Optimizations
Khi scan nhiều host thì ta có thể set timeout ngắn lại, giảm số lần retry hoặc quy định số lần lỗi tối đa trước khi skip một host nào đó để đẩy nhanh quá trình quét:
nuclei -l list-of-targets.txt -timeout 1 -retries 3 -mhe 3
Resuming Scans
Sau khi ngắt Nuclei, nó sẽ hiển thị đường dẫn đến resume file:
Ta có thể resume việc scan như sau:
nuclei -l targets-file.txt -resume /path/to/resume-file.cfg
Profiles
Ta còn có thể dùng các profiles để giảm số lượng template chẳng hạn như:
recommended
: balanced and efficient scanning. Bao gồm các moduledns
,ssl
,tcp
,http
vàjavascript
.cves
: quét CVE. Bao gồm;http/cves/
http/cnvd/
network/cves/
javascript/cves/
default-login
: tìm các trang đăng nhập mặc định. Bao gồm:http/default-logins/
network/default-login/
javascript/default-logins/
subdomain-takeovers
: tìm subdomain có thể bị takeover.http/takeovers/
dns/azure-takeover-detection.yaml
dns/elasticbeanstalk-takeover.yaml
misconfigurations
: tìm các misconfigurations.http/misconfiguration/
network/misconfig/
javascript/misconfiguration/
wordpress
: quét các lỗ hổng trong WordPress.
Ví dụ:
ax scan domains-alive-without-scheme.txt -m nuclei-base -o nuclei.txt --extra-args '-as -config ~/nuclei-templates/profiles/recommended.yml -iserver vps.insomnia.ninja -silent'
Workflows
Giống với option -as
nhưng cho phép ta tự custom để quyết định nên chạy template nào khi gặp các điều kiện nhất định.
Một workflow bình thường chỉ là một chuỗi các template paths:
# mandatory template info goes up here (id, name etc)
# workflow definition:
workflows:
- template: files/git-config.yaml
- template: files/svn-config.yaml
- template: files/env-file.yaml
- template: cves/2022/
- tags: xss,ssrf,cve,lfi
Hoặc chạy các sub-templates khi template có findings:
workflows:
- template: technologies/jira-detect.yaml
subtemplates:
- tags: jira
- template: exploits/jira/
Sử dụng matcher:
workflows:
- template: technologies/tech-detect.yaml
matchers:
- name: wordpress
subtemplates:
- template: cves/CVE-2019-6715.yaml
- template: cves/CVE-2019-9978.yaml
- template: files/wordpress-db-backup.yaml
- template: files/wordpress-debug-log.yaml