Skip to content

Commit f614040

Browse files
b-c-dsbcaller
authored andcommitted
1.0.0rc1
1 parent 42db986 commit f614040

File tree

2 files changed

+36
-44
lines changed

2 files changed

+36
-44
lines changed

README.md

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
# Regexploit
22

3-
Regular Expression Denial of Service (ReDoS).
3+
Find regexes which are vulnerable to Regular Expression Denial of Service (ReDoS).
44

5-
Most default regular expression parsers (non-deterministic finite automata) have unbounded worst-case complexity. Regex matching may be quick when presented with a matching input string. However, certain non-matching input strings can make the regular expression matcher go into crazy loops and take ages to process. This can cause denial of service, as the CPU will be stuck trying to match the regex.
5+
Many default regular expression parsers have unbounded worst-case complexity. Regex matching may be quick when presented with a matching input string. However, certain non-matching input strings can make the regular expression matcher go into crazy backtracking loops and take ages to process. This can cause denial of service, as the CPU will be stuck trying to match the regex.
66

77
This tool is designed to:
88
* find regular expressions which are vulnerable to ReDoS
99
* give an example malicious string which will cause catastrophic backtracking
1010

11-
Something something regexes are bad.
12-
1311
## Worst-case complexity
1412

1513
This reflects the complexity of the regular expression matcher's backtracking procedure with respect to the length of the entered string.
1614

1715
Cubic complexity here means that if the vulnerable part of the string is doubled in length, the execution time should be about 8 times longer (2^3).
1816
For exponential ReDoS with starred stars e.g. `(a*)*$` a fudge factor is used and the complexity will be greater than 10.
1917

20-
For explotability, a cubic complexity or higher is typically required unless truly giant strings are allowed as input.
18+
For explotability, cubic complexity or higher is typically required unless truly giant strings are allowed as input.
2119

2220
## Example
2321

@@ -41,7 +39,7 @@ To scan the installed python modules run `regexploit-python-env`.
4139

4240
```
4341
Importing ua_parser.user_agent_parser
44-
Vulnerable regex in /Users/b3n/Research/redosauto/.env/lib/python3.9/site-packages/ua_parser/user_agent_parser.py #183
42+
Vulnerable regex in /somewhere/.env/lib/python3.9/site-packages/ua_parser/user_agent_parser.py #183
4543
Pattern: \bSmartWatch *\( *([^;]+) *; *([^;]+) *;
4644
Context: self.user_agent_re = re.compile(self.pattern)
4745
---
@@ -53,7 +51,7 @@ Worst-case complexity: 3 ⭐⭐⭐
5351
Repeated character: [20]
5452
Example: 'SmartWatch(0;' + ' ' * 3456
5553
56-
Vulnerable regex in /Users/b3n/Research/redosauto/.env/lib/python3.9/site-packages/ua_parser/user_agent_parser.py #183
54+
Vulnerable regex in /somewhere/.env/lib/python3.9/site-packages/ua_parser/user_agent_parser.py #183
5755
Pattern: ; *([^;/]+) Build[/ ]Huawei(MT1-U06|[A-Z]+\d+[^\);]+)[^\);]*\)
5856
Context: self.user_agent_re = re.compile(self.pattern)
5957
---
@@ -67,15 +65,19 @@ For each vulnerable regular expression it prints one or more malicious string to
6765

6866
# Installation
6967

70-
For now, clone and run
68+
Python 3.8+ is required. To extract regexes from JavaScript / TypeScript code, NodeJS 12+ is also required.
69+
70+
Optionally make a virtual environment
7171

7272
```bash
73-
# Optionally make a virtualenv
7473
python3 -m venv .env
7574
source .env/bin/activate
76-
# Now actually install
77-
pip install -e .
78-
(cd regexploit/bin/javascript; npm install --production)
75+
```
76+
77+
Now actually install with pip
78+
79+
```
80+
pip install regexploit
7981
```
8082

8183
# Usage
@@ -93,62 +95,51 @@ or via a file
9395
```bash
9496
cat myregexes.txt | regexploit
9597
```
96-
97-
Nothing is printed when no ReDoS is found.
98-
99-
## Python imports
100-
101-
Search for regexes in all the python modules currently installed in your path / env. This means you can `pip install` whatever modules you are interested in and they will be analysed. Cpython code is included.
102-
103-
```bash
104-
regexploit-python-env
105-
```
106-
107-
N.B. this doesn't parse the python code to an AST and will only find regexes compiled automatically on module import. Modules are actually imported, so code in the modules will be executed.
108-
109-
11098
## Python code
11199

112-
Parses Python code (without executing it) via the AST to find regexes (with some false positives). The regexes are then analysed for ReDoS.
100+
Parses Python code (without executing it) via the AST to find regexes. The regexes are then analysed for ReDoS.
113101

114102
```bash
115-
regexploit-py my-project/stuff.py
103+
regexploit-py my-project/
116104
regexploit-py "my-project/**/*.py" --glob
117105
```
118-
119106
## Javascript / Typescript
120107

121-
This will use the bundled NodeJS package in `regexploit/bin/javascript` which parses your javascript as an AST with [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) and prints out all regexes.
108+
This will use the bundled NodeJS package in `regexploit/bin/javascript` which parses your javascript as an AST with [eslint](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) and prints out all regexes.
122109

123110
Those regexes are fed into the python ReDoS finder.
124111

125112
```bash
126-
regexploit-js my-module/my-file.js another/file.js
113+
regexploit-js my-module/my-file.js another/file.js some/folder/
127114
regexploit-js "my-project/node_modules/**/*.js" --glob
128115
```
129116

130-
N.B. there are differences between javascript and python regex parsing so there may be some errors. I'm [not sure I want](https://hackernoon.com/the-madness-of-parsing-real-world-javascript-regexps-d9ee336df983) to write a JS regex AST! Also, use NodeJS version >=12.
117+
N.B. there are differences between javascript and python regex parsing so there may be some errors. I'm [not sure I want](https://hackernoon.com/the-madness-of-parsing-real-world-javascript-regexps-d9ee336df983) to write a JS regex AST!
131118

132-
## Ruby
133-
134-
TODO: not so straight forward to extract the regexes because of the way they are often built up from multiple strings.
135-
136-
## PHP
119+
## Python imports
137120

138-
TODO: not so straight forward to extract the regexes because of the way they are often built up from multiple strings. Can maybe grep for simple uses of `preg_match` and pipe into `regexploit`.
121+
Search for regexes in all the python modules currently installed in your path / env. This means you can `pip install` whatever modules you are interested in and they will be analysed. Cpython code is included.
139122

140-
## Golang / anything using re2
123+
```bash
124+
regexploit-python-env
125+
```
141126

142-
Unless you specifically use a non-deterministic finite automata, Go code is not vulnerable to this type of ReDoS. It uses `re2` which does not have catastrophic backtracking.
127+
N.B. this doesn't parse the python code to an AST and will only find regexes compiled automatically on module import. Modules are actually imported, **so code in the modules will be executed**. This is helpful for finding regexes which are built up from smaller strings on load e.g. [CVE-2021-25292 in Pillow](https://github.com/python-pillow/Pillow/commit/3bce145966374dd39ce58a6fc0083f8d1890719c)
143128

144129
## JSON / YAML
145130

131+
Yaml requires pyyaml, which can be installed with `pip install regexploit[yaml]`.
132+
146133
```bash
147134
regexploit-json *.json
148135
regexploit-yaml *.yaml
149136
```
137+
## C# (.NET)
150138

151-
# Bugs reported
139+
```bash
140+
regexploit-csharp something.cs
141+
```
142+
# :trophy: Bugs reported :trophy:
152143

153144
* [bpo-38804: cpython's http.cookiejar](https://github.com/python/cpython/pull/17157) (Set-Cookie header parsing)
154145
* [CVE-2020-5243: uap-core](https://github.com/ua-parser/uap-core/security/advisories/GHSA-cmcx-xhr8-3w9p) affecting uap-python, [uap-ruby](https://github.com/ua-parser/uap-ruby/security/advisories/GHSA-pcqq-5962-hvcw), etc. (User-Agent header parsing)
@@ -161,7 +152,8 @@ regexploit-yaml *.yaml
161152
* [CVE-2021-27291: pygments](https://github.com/pygments/pygments/commit/2e7e8c4a7b318f4032493773732754e418279a14) lexers for ADL, CADL, Ceylon, Evoque, Factor, Logos, Matlab, Octave, ODIN, Scilab & Varnish VCL (Syntax highlighting)
162153
* [CVE-2021-27292: ua-parser-js](https://github.com/faisalman/ua-parser-js/commit/809439e20e273ce0d25c1d04e111dcf6011eb566) (User-Agent header parsing)
163154
* [CVE-2021-27293: RestSharp](https://github.com/restsharp/RestSharp/issues/1556) (JSON deserialisation in a .NET C# package)
164-
* Plus unpublished bugs in pypi packages, npm packages and a nuget (C#) package
155+
* CVE-2021-28092: to be released
156+
* Plus unpublished bugs in a handful of pypi, npm, ruby and nuget packages
165157

166158
## Credits
167159

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
setuptools.setup(
77
name="regexploit",
8-
version="0.0.1",
8+
version="1.0.0rc1",
99
author="Ben Caller :: Doyensec",
10-
author_email="REMOVE.THIS.PREFIX[email protected]",
10+
author_email="REMOVETHISPREFIX[email protected]",
1111
description="Find regular expressions vulnerable to ReDoS",
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)