Skip to content

Commit d2a710a

Browse files
committed
ascanrules: SQLi PostgreSQL rename scan rule (all time based)
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
1 parent 8afbdb0 commit d2a710a

File tree

5 files changed

+16
-30
lines changed

5 files changed

+16
-30
lines changed

addOns/ascanrules/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
### Changed
88
- Maintenance changes.
99
- Depends on an updated version of the Common Library add-on.
10+
- The SQL Injection - PostgreSQL scan rule and alerts have been renamed to clarify that they're time based (Issue 7341).
1011

1112
### Added
1213
- Rules (as applicable) have been tagged in relation to HIPAA and PCI DSS.
Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
import org.zaproxy.zap.model.TechSet;
4343

4444
/**
45-
* The SqlInjectionPostgreScanRule identifies Postgresql specific SQL Injection vulnerabilities
46-
* using Postgresql specific syntax. If it doesn't use Postgresql specific syntax, it belongs in the
47-
* generic SQLInjection class! Note the ordering of checks, for efficiency is : 1) Error based (N/A)
48-
* 2) Boolean Based (N/A - uses standard syntax) 3) UNION based (N/A - uses standard syntax) 4)
49-
* Stacked (N/A - uses standard syntax) 5) Blind/Time Based (Yes)
45+
* This scan rule identifies Postgresql specific SQL Injection vulnerabilities using Postgresql
46+
* specific syntax. If it doesn't use Postgresql specific syntax, it belongs in the generic
47+
* SQLInjection class! Note the ordering of checks, for efficiency is : 1) Error based (N/A) 2)
48+
* Boolean Based (N/A - uses standard syntax) 3) UNION based (N/A - uses standard syntax) 4) Stacked
49+
* (N/A - uses standard syntax) 5) Blind/Time Based (Yes)
5050
*
5151
* <p>See the following for some great specific tricks which could be integrated here
5252
* http://www.websec.ca/kb/sql_injection
@@ -60,7 +60,7 @@
6060
*
6161
* @author 70pointer
6262
*/
63-
public class SqlInjectionPostgreScanRule extends AbstractAppParamPlugin
63+
public class SqlInjectionPostgreSqlTimingScanRule extends AbstractAppParamPlugin
6464
implements CommonActiveScanRuleInfo {
6565

6666
private boolean doTimeBased = false;
@@ -80,23 +80,6 @@ public class SqlInjectionPostgreScanRule extends AbstractAppParamPlugin
8080
private static final double TIME_CORRELATION_ERROR_RANGE = 0.15;
8181
private static final double TIME_SLOPE_ERROR_RANGE = 0.30;
8282

83-
/**
84-
* create a map of SQL related error message fragments, and map them back to the RDBMS that they
85-
* are associated with keep the ordering the same as the order in which the values are inserted,
86-
* to allow the more (subjectively judged) common cases to be tested first Note: these should
87-
* represent actual (driver level) error messages for things like syntax error, otherwise we are
88-
* simply guessing that the string should/might occur.
89-
*/
90-
private static final Map<String, String> SQL_ERROR_TO_DBMS = new LinkedHashMap<>();
91-
92-
static {
93-
SQL_ERROR_TO_DBMS.put("org.postgresql.util.PSQLException", "PostgreSQL");
94-
SQL_ERROR_TO_DBMS.put("org.postgresql", "PostgreSQL");
95-
// Note: only Postgresql mappings here.
96-
// TODO: is this all?? we need more error messages for Postgresql for different languages.
97-
// PHP, ASP, JSP(JDBC), etc.
98-
}
99-
10083
/**
10184
* The sleep function in Postgresql cast it back to an int, so we can use it in nested select
10285
* statements and stuff.
@@ -209,7 +192,8 @@ public class SqlInjectionPostgreScanRule extends AbstractAppParamPlugin
209192
}
210193

211194
/** for logging. */
212-
private static final Logger LOGGER = LogManager.getLogger(SqlInjectionPostgreScanRule.class);
195+
private static final Logger LOGGER =
196+
LogManager.getLogger(SqlInjectionPostgreSqlTimingScanRule.class);
213197

214198
@Override
215199
public int getId() {

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
@@ -422,7 +422,7 @@ <H2 id="id-40022">SQL Injection - PostgreSQL (Time Based)</H2>
422422
<br>
423423
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.
424424
<p>
425-
Latest code: <a href="https://github.com/zaproxy/zap-extensions/blob/main/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/SqlInjectionPostgreScanRule.java">SqlInjectionPostgreScanRule.java</a>
425+
Latest code: <a href="https://github.com/zaproxy/zap-extensions/blob/main/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/SqlInjectionPostgreSqlTimingScanRule.java">SqlInjectionPostgreSqlTimingScanRule.java</a>
426426
<br>
427427
Alert ID: <a href="https://www.zaproxy.org/docs/alerts/40022/">40022</a>.
428428

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
@@ -186,7 +186,7 @@ ascanrules.sqlinjection.mssql.name = SQL Injection - MsSQL
186186
ascanrules.sqlinjection.mysql.name = SQL Injection - MySQL
187187
ascanrules.sqlinjection.name = SQL Injection
188188
ascanrules.sqlinjection.oracle.name = SQL Injection - Oracle
189-
ascanrules.sqlinjection.postgres.name = SQL Injection - PostgreSQL
189+
ascanrules.sqlinjection.postgres.name = SQL Injection - PostgreSQL (Time Based)
190190
ascanrules.sqlinjection.refs = https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
191191
ascanrules.sqlinjection.soln = Do not trust client side input, even if there is client side validation in place.\nIn general, type check all data on the server side.\nIf the application uses JDBC, use PreparedStatement or CallableStatement, with parameters passed by '?'\nIf the application uses ASP, use ADO Command Objects with strong type checking and parameterized queries.\nIf database Stored Procedures can be used, use them.\nDo *not* concatenate strings into queries in the stored procedure, or use 'exec', 'exec immediate', or equivalent functionality!\nDo not create dynamic SQL queries using simple string concatenation.\nEscape all data received from the client.\nApply an 'allow list' of allowed characters, or a 'deny list' of disallowed characters in user input.\nApply the principle of least privilege by using the least privileged database user possible.\nIn particular, avoid using the 'sa' or 'db-owner' database users. This does not eliminate SQL injection, but minimizes its impact.\nGrant the minimum database access that is necessary for the application.
192192
ascanrules.sqlinjection.sqlite.alert.errorbased.extrainfo = The following known SQLite error message was provoked: [{0}].
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
import org.zaproxy.zap.model.TechSet;
4242
import org.zaproxy.zap.testutils.NanoServerHandler;
4343

44-
/** Unit test for {@link SqlInjectionPostgreScanRule}. */
45-
class SqlInjectionPostgreScanRuleUnitTest extends ActiveScannerTest<SqlInjectionPostgreScanRule> {
44+
/** Unit test for {@link SqlInjectionPostgreSqlTimingScanRule}. */
45+
class SqlInjectionPostgreSqlTimingScanRuleUnitTest
46+
extends ActiveScannerTest<SqlInjectionPostgreSqlTimingScanRule> {
4647

4748
@Override
48-
protected SqlInjectionPostgreScanRule createScanner() {
49-
return new SqlInjectionPostgreScanRule();
49+
protected SqlInjectionPostgreSqlTimingScanRule createScanner() {
50+
return new SqlInjectionPostgreSqlTimingScanRule();
5051
}
5152

5253
@Test

0 commit comments

Comments
 (0)