Skillpedia
الأمان6.5k · #13968

redos

ما الذي تفعله

تشرح هذه المهارة ReDoS، وهو حجب للخدمة يستغرق فيه تعبير نمطي وقتًا طويلًا جدًا على سلسلة مصممة بعناية. وهي مخصصة للمطورين والمختبرين الذين يفحصون سرعة كودهم وأمانه.

متى تستخدمها

  • ✓عندما يطلب مطور من وكيله إيجاد تعبيرات نمطية قد تبطؤ بشدة عند مدخل مُعَد.
  • ✓عندما يفحص وكيلك أي محركات التعبيرات النمطية في المشروع قد تتأثر، لأن بعض المحركات غير متأثرة.
  • ✓عندما يجب أن يُظهر التقرير نتيجة توقيت تثبت البطء.

رابط المهارة

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/redos/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/redos/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“هل تستطيع فحص كودنا المصرّح به لإيجاد تعبيرات نمطية قد تجمّد الخادم عند مدخل طويل مُعَد؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يبحث وكيلك عن استدعاءات التعبيرات النمطية، ويجد التي تحتوي على تكرارات متداخلة، ويتتبع مدخلات المستخدم إليها، ويقيس زمن الاستجابة على نسخة اختبار.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

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:

  1. string tainted, pattern static → ReDoS possible if pattern is vulnerable
  2. pattern tainted → also check for Regex Injection (attacker adds their own quantifiers → instant ReDoS)
  3. 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

الأسئلة الشائعة

ما ReDoS؟

هو بطء ناتج عن تعبير نمطي يستغرق وقتًا أطول بكثير على مدخلات معينة، مما قد يشغل الخادم.

هل كل محركات التعبيرات النمطية متأثرة؟

لا. تقول المهارة إن محركات مثل RE2 وregexp في Go لا تتراجع، لذلك لا تتأثر بهذه الطريقة.

كيف يُؤكَّد الخلل؟

تطلب المهارة اختبار توقيت يُظهر ارتفاعًا واضحًا في زمن الاستجابة مقارنة بمدخل عادي.

التفاصيل

الوصف الأصلي من المؤلف

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'.

repo: BitterSecurity/Decepticon

الشعبية

نجوم GitHub
6.5k
الترتيب
#13968
الترخيص
Apache-2.0
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة