🚩 Challenge Overview
- Platform/Event: HTB Cyber Apocalypse 2025
- Difficulty: Medium
- Points: 230
- Solves: 290
- Category: Misc
- Tags: Regular Expressions, Input Validation, Constraints Bypass
📝 Description
Write a single regular expression under 40 characters that matches valid mathematical equations but rejects maliciously injection vectors.
💡 Solution / Approach
-
The validation script uses PHP’s
preg_matchwith a strict length count. -
The allowed characters are limited to numbers, arithmetic signs, and parentheses:
^[0-9+\-*\/()]+$. -
To bypass the length check while preventing command injection via backticks or function calls, we use recursive subpatterns to match matching nesting parentheses:
^([0-9+\-*\/]|(\((?1)*\)))+$.