Regular Expression: Evil Regex

Denial of serviceExploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

Evil Regex contains:

  • Grouping with repetition

  • Inside the repeated group:

    • Repetition

    • Alternation with overlapping

Examples:

  • (a+)+

  • ([a-zA-Z]+)*

  • (a|aa)+

  • (a|a?)+

  • (.*a){x} for x > 10

These regular expressions can be exploited with aaaaaaaaaaaaaaaaaaaaaaaa! (20 'a's followed by a '!').

ps1
aaaaaaaaaaaaaaaaaaaa! 

For this input, the regex engine will try all possible ways to group the a characters before realizing that the match ultimately fails because of the !. This results in an explosion of backtracking attempts.

Comments

No comments yet.