Skip to content

Commit 24d305c

Browse files
authored
Merge pull request #6565 from kingthorin/sqli-mysql-split
ascanrules: SQLi MySQL rename scan rule (all time based)
2 parents c42bfda + 3bc02f6 commit 24d305c

File tree

5 files changed

+16
-29
lines changed

5 files changed

+16
-29
lines changed

addOns/ascanrules/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
- The following scan rules and their alerts have been renamed to clarify that they're time based (Issue 7341).
1111
- SQL Injection - Oracle
1212
- SQL Injection - MsSQL
13+
- SQL Injection - MySQL
1314
- SQL Injection - Hypersonic
1415

1516
### Added
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Collections;
2525
import java.util.HashMap;
2626
import java.util.Iterator;
27-
import java.util.LinkedHashMap;
2827
import java.util.List;
2928
import java.util.Map;
3029
import java.util.concurrent.atomic.AtomicReference;
@@ -44,19 +43,19 @@
4443
import org.zaproxy.zap.model.TechSet;
4544

4645
/**
47-
* The SqlInjectionMySqlScanRule identifies MySQL specific SQL Injection vulnerabilities using MySQL
48-
* specific syntax. If it doesn't use MySQL specific syntax, it belongs in the generic SQLInjection
49-
* class! Note the ordering of checks, for efficiency is : 1) Error based (N/A) 2) Boolean Based
50-
* (N/A - uses standard syntax) 3) UNION based (N/A - uses standard syntax) 4) Stacked (N/A - uses
51-
* standard syntax) 5) Blind/Time Based (Yes - uses specific syntax)
46+
* This scan rule identifies MySQL specific SQL Injection vulnerabilities using MySQL specific
47+
* syntax. If it doesn't use MySQL specific syntax, it belongs in the generic SQLInjection class!
48+
* Note the ordering of checks, for efficiency is : 1) Error based (N/A) 2) Boolean Based (N/A -
49+
* uses standard syntax) 3) UNION based (N/A - uses standard syntax) 4) Stacked (N/A - uses standard
50+
* syntax) 5) Blind/Time Based (Yes - uses specific syntax)
5251
*
5352
* <p>See the following for some great MySQL specific tricks which could be integrated here
5453
* http://www.websec.ca/kb/sql_injection#MySQL_Stacked_Queries
5554
* http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
5655
*
5756
* @author 70pointer
5857
*/
59-
public class SqlInjectionMySqlScanRule extends AbstractAppParamPlugin
58+
public class SqlInjectionMySqlTimingScanRule extends AbstractAppParamPlugin
6059
implements CommonActiveScanRuleInfo {
6160

6261
/** MySQL one-line comment */
@@ -65,21 +64,6 @@ public class SqlInjectionMySqlScanRule extends AbstractAppParamPlugin
6564
private static final String ORIG_VALUE_TOKEN = "<<<<ORIGINALVALUE>>>>";
6665
private static final String SLEEP_TOKEN = "<<<<SLEEP>>>>";
6766

68-
/**
69-
* create a map of SQL related error message fragments, and map them back to the RDBMS that they
70-
* are associated with keep the ordering the same as the order in which the values are inserted,
71-
* to allow the more (subjectively judged) common cases to be tested first Note: these should
72-
* represent actual (driver level) error messages for things like syntax error, otherwise we are
73-
* simply guessing that the string should/might occur.
74-
*/
75-
private static final Map<String, String> SQL_ERROR_TO_DBMS = new LinkedHashMap<>();
76-
77-
static {
78-
SQL_ERROR_TO_DBMS.put("com.mysql.jdbc.exceptions", "MySQL");
79-
SQL_ERROR_TO_DBMS.put("org.gjt.mm.mysql", "MySQL");
80-
// Note: only MYSQL mappings here.
81-
}
82-
8367
/** MySQL specific time based injection strings. */
8468

8569
// Note: <<<<ORIGINALVALUE>>>> is replaced with the original parameter value at runtime in these
@@ -231,7 +215,8 @@ public class SqlInjectionMySqlScanRule extends AbstractAppParamPlugin
231215
}
232216

233217
/** for logging. */
234-
private static final Logger LOGGER = LogManager.getLogger(SqlInjectionMySqlScanRule.class);
218+
private static final Logger LOGGER =
219+
LogManager.getLogger(SqlInjectionMySqlTimingScanRule.class);
235220

236221
private int timeSleepSeconds = DEFAULT_SLEEP_TIME;
237222

addOns/ascanrules/src/main/javahelp/org/zaproxy/zap/extension/ascanrules/resources/help/contents/ascanrules.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ <H2 id="id-40019">SQL Injection - MySQL (Time Based)</H2>
386386
<br>
387387
Post 2.5.0 you can change the length of time used for the attack by changing the <code>rules.common.sleep</code> parameter via the Options 'Rule configuration' panel.
388388
<p>
389-
Latest code: <a href="https://github.com/zaproxy/zap-extensions/blob/main/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/SqlInjectionMySqlScanRule.java">SqlInjectionMySqlScanRule.java</a>
389+
Latest code: <a href="https://github.com/zaproxy/zap-extensions/blob/main/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/SqlInjectionMySqlTimingScanRule.java">SqlInjectionMySqlTimingScanRule.java</a>
390390
<br>
391391
Alert ID: <a href="https://www.zaproxy.org/docs/alerts/40019/">40019</a>.
392392

addOns/ascanrules/src/main/resources/org/zaproxy/zap/extension/ascanrules/resources/Messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ ascanrules.sqlinjection.desc = SQL injection may be possible.
183183
ascanrules.sqlinjection.hypersonic.name = SQL Injection - Hypersonic SQL (Time Based)
184184
ascanrules.sqlinjection.mssql.alert.timebased.extrainfo = The query time is controllable using parameter value [{0}], which caused the request to take [{1}] milliseconds, when the original unmodified query with value [{2}] took [{3}] milliseconds.
185185
ascanrules.sqlinjection.mssql.name = SQL Injection - MsSQL (Time Based)
186-
ascanrules.sqlinjection.mysql.name = SQL Injection - MySQL
186+
ascanrules.sqlinjection.mysql.name = SQL Injection - MySQL (Time Based)
187187
ascanrules.sqlinjection.name = SQL Injection
188188
ascanrules.sqlinjection.oracle.name = SQL Injection - Oracle (Time Based)
189189
ascanrules.sqlinjection.postgres.name = SQL Injection - PostgreSQL
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@
3838
import org.zaproxy.zap.model.TechSet;
3939
import org.zaproxy.zap.testutils.NanoServerHandler;
4040

41-
/** Unit test for {@link SqlInjectionMySqlScanRule}. */
42-
class SqlInjectionMySqlScanRuleUnitTest extends ActiveScannerTest<SqlInjectionMySqlScanRule> {
41+
/** Unit test for {@link SqlInjectionMySqlTimingScanRule}. */
42+
class SqlInjectionMySqlTimingScanRuleUnitTest
43+
extends ActiveScannerTest<SqlInjectionMySqlTimingScanRule> {
4344

4445
@Override
45-
protected SqlInjectionMySqlScanRule createScanner() {
46-
return new SqlInjectionMySqlScanRule();
46+
protected SqlInjectionMySqlTimingScanRule createScanner() {
47+
return new SqlInjectionMySqlTimingScanRule();
4748
}
4849

4950
@Test

0 commit comments

Comments
 (0)