redos
Skill này làm gì
Skill này giải thích ReDoS, một kiểu từ chối dịch vụ khi biểu thức chính quy mất rất lâu với một chuỗi được tạo đặc biệt. Skill dành cho lập trình viên và người kiểm thử kiểm tra tốc độ và độ an toàn của mã họ sở hữu.
Khi nào nên dùng
- ✓Khi lập trình viên yêu cầu agent tìm biểu thức chính quy có thể chậm nghiêm trọng với đầu vào được tạo đặc biệt.
- ✓Khi agent kiểm tra những engine regex nào trong dự án có thể bị ảnh hưởng, vì một số engine không bị ảnh hưởng.
- ✓Khi một báo cáo phải có kết quả đo thời gian chứng minh mức chậm lại.
Liên kết skill
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/redos/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể kiểm tra mã được ủy quyền của chúng tôi xem có biểu thức chính quy nào có thể làm treo máy chủ khi nhận chuỗi dài được tạo đặc biệt không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tìm các lệnh gọi regex, xác định những cái có lặp lồng nhau, theo dõi đầu vào người dùng đến chúng, và đo thời gian phản hồi trên bản sao kiểm thử.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
ReDoS Hunting Playbook
Regular Expression Denial of Service exploits O(2^n) or O(n^2) matching time in backtracking engines. One crafted string can peg a CPU thread for seconds or minutes against an otherwise tiny pattern.
1. Identify Backtracking Engines in Scope
Not all regex engines backtrack:
| Engine | Language/Runtime | Backtracks? | Vulnerable? |
|---|---|---|---|
| PCRE / PCRE2 | C, PHP, Apache, nginx | Yes | YES |
re module |
Python (pre-3.11 re, regex) |
Yes | YES |
java.util.regex |
Java | Yes | YES |
RegExp |
JavaScript / V8 | Yes | YES |
System.Text.RegularExpressions |
.NET | Yes (w/ timeout option) | YES |
regexp package |
Go | DFA-based (RE2) | NO |
Oniguruma |
Ruby | Yes | YES |
| RE2 | C++, re2 Python binding | DFA-based | NO |
If the target uses RE2 or Go's regexp, skip this playbook — no
backtracking, no ReDoS.
2. Source Patterns — Where Tainted Input Reaches Regex
# Python
grep -rn 're\.match\|re\.search\|re\.fullmatch\|re\.compile\|regex\.match' /workspace/src \
| grep -v '#' | grep -v 'test_' | grep -v '_test\.py'
# Node.js / TypeScript
grep -rn 'new RegExp\|\.match(\|\.search(\|\.test(' /workspace/src \
--include='*.js' --include='*.ts' | grep -v 'node_modules'
# Java
grep -rn 'Pattern\.compile\|\.matches(\|\.find(\|String\.matches' /workspace/src \
--include='*.java'
# PHP
grep -rn 'preg_match\|preg_replace\|preg_split' /workspace/src --include='*.php'
# Ruby
grep -rn 'match\|=~\|Regexp\.new\|\.scan(' /workspace/src --include='*.rb' \
| grep -v '#'
# Semgrep for tainted-input-to-regex-sink
semgrep --config p/regex /workspace/src --sarif -o /workspace/sem-redos.sarif 2>/dev/null
For each hit, determine whether the regex pattern is:
- Static (hardcoded string literal) → scan the pattern itself
- Dynamic (constructed from user input) → separate vuln class (regex injection); flag it and continue
3. Catastrophic Pattern Recognition
A regex is potentially catastrophic if it can match the same character through multiple paths. The two canonical forms:
Form 1: Nested quantifiers
(a+)+, (a*)*, ([a-z]+)+, (a|a)+
The inner group can match one character in multiple ways → exponential
backtracking on a string like aaaa...b.
Form 2: Overlapping alternation
(a|aa)+, (a|ab)+c, (x+|y+)+z
Two branches can match the same prefix → exponential when neither eventually matches the suffix.
Quick pattern scanner
# Find potentially catastrophic regexes (grep heuristic)
grep -rn "$(printf \
'(\([^)]*[+*][^)]*\)[+*])\|(\([^)]*|\[^)]*\)[+*])\|(\([^)]*[+*]\)\{[2-9]\})')" \
/workspace/src 2>/dev/null | grep -v 'node_modules\|\.min\.js'
# Better: use vuln-regex-detector (if available)
python3 -c "
import subprocess, json, os, sys
# Try to find all regex literals in Python files
import ast, glob
for path in glob.glob('/workspace/src/**/*.py', recursive=True):
try:
tree = ast.parse(open(path).read())
for node in ast.walk(tree):
if isinstance(node, ast.Call):
fn = getattr(node.func, 'attr', '') or getattr(node.func, 'id', '')
if fn in ('compile','match','search','fullmatch'):
for arg in node.args:
if isinstance(arg, ast.Constant) and isinstance(arg.value, str):
print(path, node.lineno, repr(arg.value))
except Exception:
pass
" 2>/dev/null | head -50
Patterns warranting deeper analysis (flag these):
- Any group with a quantifier inside a quantifier:
(X+)+,(X*)+,(X+)* - Alternation where branches share a prefix:
(ab|a)+,(abc|ab)+ - Long character classes under a star inside a group under a star:
([a-z ]+)+
4. Taint Heuristics — Is This Reachable?
For each flagged regex, trace whether attacker-controlled data reaches the
pattern, the string argument, or both:
stringtainted,patternstatic → ReDoS possible if pattern is vulnerablepatterntainted → also check for Regex Injection (attacker adds their own quantifiers → instant ReDoS)- Both tainted → highest risk
For web endpoints, check:
- URL path / query param → regex for routing or validation
- HTTP body field → input validation regex
- Header (User-Agent, Content-Type) → server-side validation
5. Timing PoC Construction
A valid PoC must demonstrate measurable time difference between a benign and a malicious input
Câu hỏi thường gặp
ReDoS là gì?
Đó là tình trạng chậm do một biểu thức chính quy mất nhiều thời gian hơn hẳn với một số đầu vào nhất định, có thể làm nghẽn máy chủ.
Mọi engine regex đều bị ảnh hưởng không?
Không. Skill nói các engine như RE2 và regexp của Go không quay lui (backtrack), nên không bị ảnh hưởng theo cách này.
Làm sao xác nhận?
Skill yêu cầu một kiểm thử thời gian cho thấy thời gian phản hồi tăng rõ rệt so với đầu vào bình thường.
Chi tiết
Mô tả gốc của tác giả
Hunt ReDoS (CWE-1333, Catastrophic Backtracking) — identify regexes with nested quantifiers or overlapping alternation that cause super-linear matching time, trace tainted input paths to regex sinks, demonstrate timing PoC, and validate with response-time delta. Covers PCRE/RE2/V8/Python re engine differences. Triggers on: 'ReDoS', 'regex denial', 'catastrophic backtracking', 'redos', 'regex complexity', 'nested quantifiers', 'regex amplification', 'CWE-1333'.
Độ phổ biến
- Sao GitHub
- 6.5k
- Vị trí xếp hạng
- #13968
- Giấy phép
- Apache-2.0
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
detector-overview
6.5kGiúp agent của bạn đọc code mà một công cụ quét đã đánh dấu, rồi quyết định điểm nào là lỗ hổng bảo mật thật và điểm nào là báo động giả.
exploiter-overview
6.5kGiúp agent của bạn ghép nhiều lỗ hổng bảo mật đã xác nhận thành một chuỗi kiểm thử và kiểm tra chuỗi đó có thể gây hậu quả đến đâu.
llm-redteam-overview
6.5kGiúp agent của bạn tìm đúng hướng dẫn red-team AI cho một bài kiểm thử, bao quát 15 nhóm chiến thuật từ prompt injection đến lạm dụng mô hình.
aatmf-t01-prompt-injection
6.5kGiải thích prompt injection, khi các chỉ dẫn ẩn cố ghi đè một hệ thống AI, để chuyên gia bảo mật có thể kiểm tra lỗi này.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.