Skip to content

Commit b7288f9

Browse files
Merge pull request #30 from AikidoSec/lowercase-input-and-queries-before-si-detection
Enhance SQL injection detection and improve regex handling
2 parents 8a736f0 + 87a0608 commit b7288f9

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Aikido.Zen.Core/Api/Models/ReportingAPIResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ public class ReportingAPIResponse : APIResponse
5353
/// <summary>
5454
/// Gets the regex pattern for blocked user agents.
5555
/// </summary>
56-
public Regex BlockedUserAgentsRegex => new Regex(BlockedUserAgents);
56+
public Regex BlockedUserAgentsRegex => BlockedUserAgents != null ? new Regex(BlockedUserAgents) : null;
5757
}
5858
}

Aikido.Zen.Core/Vulnerabilities/SQLInjectionDetector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ public class SQLInjectionDetector
1010
{
1111
/// <summary>
1212
/// Detects potential SQL injection vulnerabilities in a query string
13+
/// the query and userInput are converted to lowercase before being processed
1314
/// </summary>
1415
/// <param name="query">The SQL query to analyze</param>
1516
/// <param name="userInput">The user input to check for injection attempts</param>
1617
/// <param name="dialect">The SQL dialect identifier</param>
1718
/// <returns>True if SQL injection is detected, false otherwise</returns>
1819
public static bool IsSQLInjection(string query, string userInput, SQLDialect dialect)
1920
{
21+
query = query?.ToLower();
22+
userInput = userInput?.ToLower();
2023
return ZenInternals.IsSQLInjection(query, userInput, dialect.ToRustDialectInt());
2124
}
2225
}

Aikido.Zen.Test/testdata/data.SQLInjectionDetector.json

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"command": "SELECT * FROM users WHERE id = '1'; DROP TABLE users; -- '",
1111
"dialect": 0,
1212
"userInput": "1'; DROP TABLE users; -- ",
13-
"description": "ATTACK: Command chaining with comment",
13+
"description": "ATTACK: Command chaining with comment",
1414
"isInjection": true
1515
},
1616
{
@@ -52,7 +52,7 @@
5252
"command": "INSERT INTO dbo.pets (pet_name, owner) VALUES ('Malicious Pet', 'Aikido Security'), ('Gru from the Minions', 'Evil Corp'); -- '",
5353
"dialect": 7,
5454
"userInput": "Malicious Pet', 'Aikido Security'), ('Gru from the Minions', 'Evil Corp'); -- ",
55-
"description": "ATTACK: Microsoft SQL injection with multiple values",
55+
"description": "ATTACK: Microsoft SQL injection with multiple values",
5656
"isInjection": true
5757
},
5858
{
@@ -89,5 +89,47 @@
8989
"userInput": "' OR 1=1 -- ",
9090
"description": "SAFE: PostgreSQL named dollar sign quotes",
9191
"isInjection": false
92+
},
93+
{
94+
"command": "SELECT * FROM users WHERE id = 'USER'",
95+
"dialect": 0,
96+
"userInput": "USER",
97+
"description": "SAFE: Uppercase user input",
98+
"isInjection": false
99+
},
100+
{
101+
"command": "SELECT * FROM users WHERE id = 'user'",
102+
"dialect": 0,
103+
"userInput": "USER",
104+
"description": "SAFE: Lowercase query with uppercase user input",
105+
"isInjection": false
106+
},
107+
{
108+
"command": "SELECT * FROM USERS WHERE ID = 'user'",
109+
"dialect": 0,
110+
"userInput": "user",
111+
"description": "SAFE: Uppercase query with lowercase user input",
112+
"isInjection": false
113+
},
114+
{
115+
"command": "SELECT * FROM USERS WHERE ID = 'USER'",
116+
"dialect": 0,
117+
"userInput": "user",
118+
"description": "SAFE: Uppercase query and user input",
119+
"isInjection": false
120+
},
121+
{
122+
"command": "SELECT * FROM users WHERE id = 'user' OR 1=1 --",
123+
"dialect": 0,
124+
"userInput": "USER' OR 1=1 --",
125+
"description": "ATTACK: Uppercase user input with SQL injection",
126+
"isInjection": true
127+
},
128+
{
129+
"command": "SELECT * FROM USERS WHERE ID = 'user' OR 1=1 --",
130+
"dialect": 0,
131+
"userInput": "user' OR 1=1 --",
132+
"description": "ATTACK: Uppercase query with lowercase user input and SQL injection",
133+
"isInjection": true
92134
}
93135
]

0 commit comments

Comments
 (0)