Skip to content

fix(security): resolve SQL injection protection bypass (942380 PL2)#3720

Open
azurit wants to merge 20 commits into
coreruleset:mainfrom
azurit:Bypass942380
Open

fix(security): resolve SQL injection protection bypass (942380 PL2)#3720
azurit wants to merge 20 commits into
coreruleset:mainfrom
azurit:Bypass942380

Conversation

@azurit
Copy link
Copy Markdown
Member

@azurit azurit commented May 27, 2024

I found TONS of ways how to bypass rule 942380 and some of them were extremely easy (for example using \s instead of \s+ in regex).

We are now able to catch these new ways of injection:

HAVING 2-1
HAVING 1 mod 2
HAVING 1 div 1
HAVING true = 1
HAVING false = 0
HAVING 1++++1
HAVING ''=''
HAVING '1'=1
HAVING ('1'=2)
HAVING 1%1
HAVING 1&1
HAVING 1*1
HAVING 1/1
HAVING 1|1
HAVING 1^2
HAVING 1!=2
HAVING 1<>1

Also, we are now catching these:

CREATE TABLE`test`
EXECUTE`test`

We are still NOT catching these:

HAVING 1
HAVING true

Copy link
Copy Markdown
Member

@fzipi fzipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your bypass example you mention for example using \s instead of \s+ in regex.

What is the difference on what you did? Does having work with no spacing?

Comment thread regex-assembly/942380.ra Outdated
@azurit
Copy link
Copy Markdown
Member Author

azurit commented Sep 4, 2024

In your bypass example you mention for example using \s instead of \s+ in regex.

What is the difference on what you did? Does having work with no spacing?

\s means exactly 1 space so it can be bypassed using 2 or more spaces. Any SQL server ignores excessive spaces in commands. For example order\sby can be bypassed using order by.

@theseion
Copy link
Copy Markdown
Contributor

theseion commented Sep 5, 2024

You could try removing all spaces with a transformation first.

Comment thread regex-assembly/942380.ra Outdated
Comment thread regex-assembly/942380.ra
\bhaving\b ?\d{1,10} ?[=<>]+
\bhaving\b ?[\'\"][^=]{1,10}[\'\" ?[=<>]+
\bcreate\s+?table.{0,20}?\(
\bhaving\s*\(?\s*(?:['"]?\s*\d+\s*['"]?|['"]\s*[^\d]*\s*['"]|true|false)\s*(?:[=<>+\-*/%^&!|]+|div|mod)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\bhaving\s*\(?\s*(?:['"]?\s*\d+\s*['"]?|['"]\s*[^\d]*\s*['"]|true|false)\s*(?:[=<>+\-*/%^&!|]+|div|mod)
\bhaving\s+\(?\s*(?:['"]?\s*\d+\s*['"]?|['"]\s*[^\d]*\s*['"]|true|false)\s*(?:[=<>+\-*/%^&!|]+|div|mod)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think * is correct here. The parser might accept ...having'..., for example.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The msg is SQL Injection Attack, atleast MySQL expects a space after HAVING, haven't checked others. Maybe @azurit has more info about this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters really in terms of the regex. As long as we assume that it can happen we should be fine either way.

@Xhoenix
Copy link
Copy Markdown
Member

Xhoenix commented Apr 10, 2026

@azurit Can you look into the open comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants