SlideShare a Scribd company logo
Regular Expression Injection
By : Elton J. Crasto
21/05/2020
Who am I?
Name: Elton Crasto
Designation: Security Analyst
Twitter: @xd1810
Objectives:- 1. What is Regular Expression?
2. What is Regular Expression
Injection?
3. ReDos?
4. How do we Find it?
5. Exploit Demo
6. Mitigation
What is Regular
Expression?
Regular Expressions (regex) are
widely used to match strings of text.
For example, the grep utility supports
regular expressions for finding patterns
in the specified text.
What is Regular
Expression?
What is Regular
Expression?
/[w._+-]+@[w.-]+.[a-zA-Z]{2,4}/
Eg: elton@net-square.com
https://www.w3schools.com/jsref/jsref_obj_regexp.asp
Regular Expression
vs UI validation?
Main difference between them is :
An attacker can easily perform an HTTP
request without using a browser (using
proxy like Burp)and then send a payload
that can compromise our application.
Regex is difficult to set up correctly.
What is Regular
Expression
Injection?
An attacker may supply a malicious
input that modifies the original
regular expression in such a way that
the regex fails to comply with the
program's specification.
This attack is called a Regex
injection or Regular Expression
Injection, might affect control flow,
cause information leaks, or result in
denial-of-service (DOS) or ReDOS
vulnerabilities.
ReDOS?
ReDoS stands for Regular
Expression Denial of Service.
The ReDoS is an algorithmic
complexity attack that produces a
denial of service by providing a
regular expression that takes a very
long time to evaluate.
For example :
Regex: ^((ab)*)+$ (this regex
searches for ab and its repetition)
input:abababababab
ReDOS?
Now we can complicate things very
easily by throwing in abababa as the
input. This extra a in the end will
cause all kinds of trouble since it
does not match the pattern and it will
make the regex engine run all kinds
of permutation looking for a possible
match.
How do we ïŹnd it?
Mostly like all injections we find it
with help of methods such as
A.Error Based
B.Blind Based [Fairly new]
Error-based is an in-band Injection
technique that relies on error
messages thrown by the server to
obtain information about the structure
of the regex.
Blind-Based is injection technique
that relies on time take to respond by
the server based on input.
Exploit Demo Detection:-
Below we have an application which has 2 types
of logs , private and public . Private logs can only
be seen by admin and public can be seen by all
Registered users.
Exploit Demo
Now on inputting any character the application
uses regex to find letters in public logs.But What if
i want to see private logs too.
So we try inputting all characters to see which one
isn't escaped.
Eg: !@#$%^&*()_+abcdefg....etc
On putting * we get to see an error which shows
us the regex code used.
Exploit Demo
Exploit:
Now that we know what the regex is all we have to do
is bypass it by tampering with the input to complete
the regex.
For example for the above regex which uses
.*<input>.* .We can easily bypass it with
. * ) | ( . *
Which gives us the following output:-
Mitigation ● Input validation/sanitization should
be done and then sent to regex.
String sanitized = subject.replaceAll("[ + * /  ]");
Pattern regex = Pattern.compile(sanitized);
● If a regular expression takes too
long, kill it at once, and inform the
user that the regular expression
was taking too long.
References ● https://www.w3schools.com/jsref/js
ref_obj_regexp.asp
● https://www.geeksforgeeks.org/un
derstanding-redos-attack/
● https://www.ntu.edu.sg/home/ehch
ua/programming/howto/Regexe.ht
ml
● https://dzone.com/articles/regular-
expressions-denial
Thank You
Questions?

More Related Content

PDF
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
PDF
LDAP Injection
PDF
도컀 ëŹŽìž‘ì • 따띌하Ʞ: 도컀가 ìČ˜ìŒìž ì‚ŹëžŒë„ 60분읎멎 ì›č 서ëČ„ë„Œ ì˜ŹëŠŽ 수 있슔니닀!
PDF
Web Hacking (basic)
PPTX
OWASP AppSecCali 2015 - Marshalling Pickles
PPTX
Sequelize
PPTX
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
PDF
ìš°ì•„í•œí…ŒíŹì„žëŻžë‚˜-우아한멀티ëȘšë“ˆ
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
LDAP Injection
도컀 ëŹŽìž‘ì • 따띌하Ʞ: 도컀가 ìČ˜ìŒìž ì‚ŹëžŒë„ 60분읎멎 ì›č 서ëČ„ë„Œ ì˜ŹëŠŽ 수 있슔니닀!
Web Hacking (basic)
OWASP AppSecCali 2015 - Marshalling Pickles
Sequelize
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
ìš°ì•„í•œí…ŒíŹì„žëŻžë‚˜-우아한멀티ëȘšë“ˆ

What's hot (20)

PPTX
Dll 파음 혞출의 2가지 ë°©ëȕ
PDF
Penetration testing web application web application (in) security
PPTX
Pentesting ReST API
PDF
The Secret Life of a Bug Bounty Hunter – Frans RosĂ©n @ Security Fest 2016
PPTX
JavaScript
PPTX
Here Be Dragons: The Unexplored Land of Active Directory ACLs
PPTX
êł”ìžìžìŠì„œ 크래í‚č - Inc0gnito 2015
PDF
Introduction To CodeIgniter
PPTX
Introduction to Spring Framework
PDF
From Java 11 to 17 and beyond.pdf
PPTX
Introduction to REST - API
PDF
Spring boot jpa
PDF
NodeJS for Beginner
PPTX
예왞ìČ˜ëŠŹê°€ìŽë“œ
PDF
HTTP Request Smuggling via higher HTTP versions
PPTX
Webpack Introduction
PDF
DNS hijacking using cloud providers – No verification needed
PPTX
서ëȄ 아킀텍ìȘ 읎핎넌 위한 í”„ëĄœì„žìŠ€ì™€ 쓰레드
PDF
Jwt == insecurity?
 
PPTX
Laravel Tutorial PPT
Dll 파음 혞출의 2가지 ë°©ëȕ
Penetration testing web application web application (in) security
Pentesting ReST API
The Secret Life of a Bug Bounty Hunter – Frans RosĂ©n @ Security Fest 2016
JavaScript
Here Be Dragons: The Unexplored Land of Active Directory ACLs
êł”ìžìžìŠì„œ 크래í‚č - Inc0gnito 2015
Introduction To CodeIgniter
Introduction to Spring Framework
From Java 11 to 17 and beyond.pdf
Introduction to REST - API
Spring boot jpa
NodeJS for Beginner
예왞ìČ˜ëŠŹê°€ìŽë“œ
HTTP Request Smuggling via higher HTTP versions
Webpack Introduction
DNS hijacking using cloud providers – No verification needed
서ëȄ 아킀텍ìȘ 읎핎넌 위한 í”„ëĄœì„žìŠ€ì™€ 쓰레드
Jwt == insecurity?
 
Laravel Tutorial PPT
Ad

Similar to Regular Expression Injection (20)

PPTX
Regular Expression Denial of Service RegexDoS
PPTX
APMG juni 2014 - Regular Expression
 
ODP
OISF: Regular Expressions (Regex) Overview
ODP
DerbyCon 7.0 Legacy: Regular Expressions (Regex) Overview
ODP
CiNPA Security SIG - Regex Presentation
PDF
Don't Fear the Regex LSP15
PDF
Don't Fear the Regex WordCamp DC 2017
PDF
Don't Fear the Regex - Northeast PHP 2015
PPTX
Regex Primer
PDF
A3 sec -_regular_expressions
 
PPTX
Regular Expression
PPTX
regularexpression-180328061400.pptx hehe
PDF
Coffee 'n code: Regexes
ODP
Regex Presentation
ODP
Regex Presentation
PPTX
Regular Expressions
PPTX
Regular expressions
DOCX
Python - Regular Expressions
PDF
Python Regular Expressions
PDF
Regular expressions
 
Regular Expression Denial of Service RegexDoS
APMG juni 2014 - Regular Expression
 
OISF: Regular Expressions (Regex) Overview
DerbyCon 7.0 Legacy: Regular Expressions (Regex) Overview
CiNPA Security SIG - Regex Presentation
Don't Fear the Regex LSP15
Don't Fear the Regex WordCamp DC 2017
Don't Fear the Regex - Northeast PHP 2015
Regex Primer
A3 sec -_regular_expressions
 
Regular Expression
regularexpression-180328061400.pptx hehe
Coffee 'n code: Regexes
Regex Presentation
Regex Presentation
Regular Expressions
Regular expressions
Python - Regular Expressions
Python Regular Expressions
Regular expressions
 
Ad

More from NSConclave (20)

PDF
RED-TEAM_Conclave
PPTX
Create a Custom Plugin in Burp Suite using the Extension
PPTX
IOT SECURITY ASSESSMENT Pentester's Approach
PPTX
Debugging Android Native Library
PPTX
Burp Suite Extension Development
PDF
Log Analysis
PDF
HTML5 Messaging (Post Message)
PDF
Node.js Deserialization
PDF
RIA Cross Domain Policy
PDF
Python Deserialization Attacks
PDF
Sandboxing
PDF
NoSql Injection
PDF
Thick Client Testing Advanced
PDF
Thick Client Testing Basics
PDF
Markdown
PDF
Docker 101
PDF
Security Architecture Consulting - Hiren Shah
PDF
OSINT: Open Source Intelligence - Rohan Braganza
PDF
Lets get started with car hacking - Ankit Joshi
PDF
Advanced Wireless Reconnaissance And Testing - Rohit Jadav
RED-TEAM_Conclave
Create a Custom Plugin in Burp Suite using the Extension
IOT SECURITY ASSESSMENT Pentester's Approach
Debugging Android Native Library
Burp Suite Extension Development
Log Analysis
HTML5 Messaging (Post Message)
Node.js Deserialization
RIA Cross Domain Policy
Python Deserialization Attacks
Sandboxing
NoSql Injection
Thick Client Testing Advanced
Thick Client Testing Basics
Markdown
Docker 101
Security Architecture Consulting - Hiren Shah
OSINT: Open Source Intelligence - Rohan Braganza
Lets get started with car hacking - Ankit Joshi
Advanced Wireless Reconnaissance And Testing - Rohit Jadav

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
System and Network Administraation Chapter 3
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
AI in Product Development-omnex systems
PDF
medical staffing services at VALiNTRY
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PTS Company Brochure 2025 (1).pdf.......
System and Network Administraation Chapter 3
Wondershare Filmora 15 Crack With Activation Key [2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Design an Analysis of Algorithms I-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
Odoo Companies in India – Driving Business Transformation.pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How Creative Agencies Leverage Project Management Software.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
AI in Product Development-omnex systems
medical staffing services at VALiNTRY
Which alternative to Crystal Reports is best for small or large businesses.pdf
top salesforce developer skills in 2025.pdf
Nekopoi APK 2025 free lastest update
Odoo POS Development Services by CandidRoot Solutions
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...

Regular Expression Injection

  • 1. Regular Expression Injection By : Elton J. Crasto 21/05/2020
  • 2. Who am I? Name: Elton Crasto Designation: Security Analyst Twitter: @xd1810
  • 3. Objectives:- 1. What is Regular Expression? 2. What is Regular Expression Injection? 3. ReDos? 4. How do we Find it? 5. Exploit Demo 6. Mitigation
  • 4. What is Regular Expression? Regular Expressions (regex) are widely used to match strings of text. For example, the grep utility supports regular expressions for finding patterns in the specified text.
  • 6. What is Regular Expression? /[w._+-]+@[w.-]+.[a-zA-Z]{2,4}/ Eg: elton@net-square.com https://www.w3schools.com/jsref/jsref_obj_regexp.asp
  • 7. Regular Expression vs UI validation? Main difference between them is : An attacker can easily perform an HTTP request without using a browser (using proxy like Burp)and then send a payload that can compromise our application. Regex is difficult to set up correctly.
  • 8. What is Regular Expression Injection? An attacker may supply a malicious input that modifies the original regular expression in such a way that the regex fails to comply with the program's specification. This attack is called a Regex injection or Regular Expression Injection, might affect control flow, cause information leaks, or result in denial-of-service (DOS) or ReDOS vulnerabilities.
  • 9. ReDOS? ReDoS stands for Regular Expression Denial of Service. The ReDoS is an algorithmic complexity attack that produces a denial of service by providing a regular expression that takes a very long time to evaluate. For example : Regex: ^((ab)*)+$ (this regex searches for ab and its repetition) input:abababababab
  • 10. ReDOS? Now we can complicate things very easily by throwing in abababa as the input. This extra a in the end will cause all kinds of trouble since it does not match the pattern and it will make the regex engine run all kinds of permutation looking for a possible match.
  • 11. How do we ïŹnd it? Mostly like all injections we find it with help of methods such as A.Error Based B.Blind Based [Fairly new] Error-based is an in-band Injection technique that relies on error messages thrown by the server to obtain information about the structure of the regex. Blind-Based is injection technique that relies on time take to respond by the server based on input.
  • 12. Exploit Demo Detection:- Below we have an application which has 2 types of logs , private and public . Private logs can only be seen by admin and public can be seen by all Registered users.
  • 13. Exploit Demo Now on inputting any character the application uses regex to find letters in public logs.But What if i want to see private logs too. So we try inputting all characters to see which one isn't escaped. Eg: !@#$%^&*()_+abcdefg....etc On putting * we get to see an error which shows us the regex code used.
  • 14. Exploit Demo Exploit: Now that we know what the regex is all we have to do is bypass it by tampering with the input to complete the regex. For example for the above regex which uses .*<input>.* .We can easily bypass it with . * ) | ( . * Which gives us the following output:-
  • 15. Mitigation ● Input validation/sanitization should be done and then sent to regex. String sanitized = subject.replaceAll("[ + * / ]"); Pattern regex = Pattern.compile(sanitized); ● If a regular expression takes too long, kill it at once, and inform the user that the regular expression was taking too long.
  • 16. References ● https://www.w3schools.com/jsref/js ref_obj_regexp.asp ● https://www.geeksforgeeks.org/un derstanding-redos-attack/ ● https://www.ntu.edu.sg/home/ehch ua/programming/howto/Regexe.ht ml ● https://dzone.com/articles/regular- expressions-denial